b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/views/_user_identity.form.php - 693 lines - 26454 bytes - Summary - Text - Print

Description: This file implements the UI view for the user properties. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UI view for the user properties.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * The Evo Factory grants Francois PLANQUE the right to license
  22   * The Evo Factory's contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   *
  25   * Daniel HAHLER grants Francois PLANQUE the right to license
  26   * Daniel HAHLER's contributions to this file and the b2evolution project
  27   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  28   * }}
  29   *
  30   * @package admin
  31   *
  32   * @version $Id: _user_identity.form.php 6136 2014-03-08 07:59:48Z manuel $
  33   */
  34  
  35  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  36  
  37  load_class( 'regional/model/_country.class.php', 'Country' );
  38  load_funcs( 'regional/model/_regional.funcs.php' );
  39  
  40  /**
  41   * @var instance of GeneralSettings class
  42   */
  43  global $Settings;
  44  /**
  45   * @var instance of Plugins class
  46   */
  47  global $Plugins;
  48  /**
  49   * @var instance of UserSettings class
  50   */
  51  global $UserSettings;
  52  /**
  53   * @var instance of User class
  54   */
  55  global $edited_User;
  56  /**
  57   * @var instance of User class
  58   */
  59  global $current_User;
  60  /**
  61   * @var current action
  62   */
  63  global $action;
  64  /**
  65   * @var user permission, if user is only allowed to edit his profile
  66   */
  67  global $user_profile_only;
  68  /**
  69   * @var the action destination of the form (NULL for pagenow)
  70   */
  71  global $form_action;
  72  /**
  73   * @var url of RSC folder
  74   */
  75  global $rsc_url;
  76  global $is_admin_page;
  77  
  78  // Default params:
  79  $default_params = array(
  80          'skin_form_params' => array(),
  81      );
  82  
  83  if( isset( $params ) )
  84  {    // Merge with default params
  85      $params = array_merge( $default_params, $params );
  86  }
  87  else
  88  {    // Use a default params
  89      $params = $default_params;
  90  }
  91  
  92  // ------------------- PREV/NEXT USER LINKS -------------------
  93  user_prevnext_links( array(
  94          'block_start'  => '<table class="prevnext_user"><tr>',
  95          'prev_start'   => '<td width="33%">',
  96          'prev_end'     => '</td>',
  97          'prev_no_user' => '<td width="33%">&nbsp;</td>',
  98          'back_start'   => '<td width="33%" class="back_users_list">',
  99          'back_end'     => '</td>',
 100          'next_start'   => '<td width="33%" class="right">',
 101          'next_end'     => '</td>',
 102          'next_no_user' => '<td width="33%">&nbsp;</td>',
 103          'block_end'    => '</tr></table>',
 104          'user_tab'     => 'profile'
 105      ) );
 106  // ------------- END OF PREV/NEXT USER LINKS -------------------
 107  
 108  $has_full_access = $current_User->check_perm( 'users', 'edit' );
 109  $edited_user_perms = array( 'edited-user', 'edited-user-required' );
 110  $new_user_creating = ( $edited_User->ID == 0 );
 111  
 112  $Form = new Form( $form_action, 'user_checkchanges' );
 113  
 114  $Form->switch_template_parts( $params['skin_form_params'] );
 115  
 116  if( !$user_profile_only )
 117  {
 118      echo_user_actions( $Form, $edited_User, $action );
 119  }
 120  
 121  $is_admin = is_admin_page();
 122  if( $is_admin )
 123  {
 124      if( $new_user_creating )
 125      {
 126          $form_title = T_('Edit user profile');
 127      }
 128      else
 129      {
 130          $form_title = get_usertab_header( $edited_User, 'profile', T_( 'Edit profile' ) );
 131          $Form->title_fmt = '<span style="float:right">$global_icons$</span><div>$title$</div>'."\n";
 132      }
 133      $form_class = 'fform';
 134  }
 135  else
 136  {
 137      $form_title = '';
 138      $form_class = 'bComment';
 139  }
 140  
 141      $Form->begin_form( $form_class, $form_title );
 142  
 143      // We should print out this submit "update" before all other buttons (because form is submitted by first button)
 144      // It gives to update a form when we press Enter key on the form element
 145      echo '<div style="position:absolute;top:-1000px;left:-1000px">';
 146      $Form->button( array( 'type' => 'submit', 'name' => 'actionArray[update]' ) );
 147      echo '</div>';
 148  
 149      $Form->add_crumb( 'user' );
 150      $Form->hidden_ctrl();
 151      $Form->hidden( 'user_tab', 'profile' );
 152      $Form->hidden( 'identity_form', '1' );
 153  
 154      $Form->hidden( 'user_ID', $edited_User->ID );
 155      if( isset( $Blog ) )
 156      {
 157          $Form->hidden( 'blog', $Blog->ID );
 158      }
 159  
 160  if( $new_user_creating )
 161  {
 162      $current_User->check_perm( 'users', 'edit', true );
 163      $edited_User->get_Group();
 164  
 165      $Form->begin_fieldset( T_( 'New user' ), array( 'class' => 'fieldset clear' ) );
 166  
 167      $chosengroup = ( $edited_User->Group === NULL ) ? $Settings->get( 'newusers_grp_ID' ) : $edited_User->grp_ID;
 168      $GroupCache = & get_GroupCache();
 169      $Form->select_object( 'edited_user_grp_ID', $chosengroup, $GroupCache, T_( 'User group' ) );
 170  
 171      $field_note = '[0 - 10]';
 172      $Form->text_input( 'edited_user_level', $edited_User->get('level'), 2, T_('User level'), $field_note, array( 'required' => true ) );
 173  
 174      $email_fieldnote = '<a href="mailto:'.$edited_User->get('email').'">'.get_icon( 'email', 'imgtag', array('title'=>T_('Send an email')) ).'</a>';
 175      $Form->text_input( 'edited_user_email', $edited_User->email, 30, T_('Email'), $email_fieldnote, array( 'maxlength' => 100, 'required' => true ) );
 176      $Form->select_input_array( 'edited_user_status', $edited_User->get( 'status' ), get_user_statuses(), T_( 'Account status' ) );
 177  
 178      $Form->end_fieldset();
 179  }
 180  
 181      /***************  Identity  **************/
 182  
 183  $Form->begin_fieldset( T_('Identity') );
 184  
 185  if( ($url = $edited_User->get('url')) != '' )
 186  {
 187      if( !preg_match('#://#', $url) )
 188      {
 189          $url = 'http://'.$url;
 190      }
 191      $url_fieldnote = '<a href="'.$url.'" target="_blank">'.get_icon( 'play', 'imgtag', array('title'=>T_('Visit the site')) ).'</a>';
 192  }
 193  else
 194      $url_fieldnote = '';
 195  
 196  if( $action != 'view' )
 197  {    // We can edit the values:
 198  
 199      if( $action != 'new' )
 200      {
 201          $user_pictures = '<div class="avatartag">'.$edited_User->get_avatar_imgtag( 'crop-top-80x80', 'avatar', 'top', true, '', 'user' ).'</div>';
 202  
 203          // Get other pictures:
 204          $user_avatars = $edited_User->get_avatar_Files();
 205          foreach( $user_avatars as $uFile )
 206          {
 207              $user_pictures .= $uFile->get_tag( '<div class="avatartag">', '', '', '</div>', 'crop-top-80x80', 'original', $edited_User->login, 'lightbox[user]' );
 208          }
 209  
 210          if( $edited_User->has_avatar() )
 211          {    // Change an existing avatar
 212              $user_pictures = $user_pictures.' <a href="'.get_user_settings_url( 'avatar', $edited_User->ID ).'" class="floatleft">'.T_('Change &raquo;').'</a>';
 213          }
 214          else
 215          {    // Upload a new avatar
 216              $user_pictures = $user_pictures.' <a href="'.get_user_settings_url( 'avatar', $edited_User->ID ).'" class="floatleft"> '.T_('Upload now &raquo;').'</a>';
 217          }
 218          $Form->info( T_('Profile picture'), $user_pictures );
 219      }
 220  
 221      $Form->text_input( 'edited_user_login', $edited_User->login, 20, T_('Login'), '', array( 'maxlength' => 60, 'required' => true ) );
 222  
 223      $firstname_editing = $Settings->get( 'firstname_editing' );
 224      if( ( in_array( $firstname_editing, $edited_user_perms ) && $edited_User->ID == $current_User->ID ) || ( $firstname_editing != 'hidden' && $has_full_access ) )
 225      {
 226          $Form->text_input( 'edited_user_firstname', $edited_User->firstname, 20, T_('First name'), '', array( 'maxlength' => 50, 'required' => ( $firstname_editing == 'edited-user-required' ) ) );
 227      }
 228  
 229      $lastname_editing = $Settings->get( 'lastname_editing' );
 230      if( ( in_array( $lastname_editing, $edited_user_perms ) && $edited_User->ID == $current_User->ID ) || ( $lastname_editing != 'hidden' && $has_full_access ) )
 231      {
 232          $Form->text_input( 'edited_user_lastname', $edited_User->lastname, 20, T_('Last name'), '', array( 'maxlength' => 50, 'required' => ( $lastname_editing == 'edited-user-required' ) ) );
 233      }
 234  
 235      $nickname_editing = $Settings->get( 'nickname_editing' );
 236      if( ( in_array( $nickname_editing, $edited_user_perms ) && $edited_User->ID == $current_User->ID ) || ( $nickname_editing != 'hidden' && $has_full_access ) )
 237      {
 238          $Form->text_input( 'edited_user_nickname', $edited_User->nickname, 20, T_('Nickname'), '', array( 'maxlength' => 50, 'required' => ( $nickname_editing == 'edited-user-required' ) ) );
 239      }
 240  
 241      $Form->radio( 'edited_user_gender', $edited_User->get('gender'), array(
 242              array( 'M', T_('A man') ),
 243              array( 'F', T_('A woman') ),
 244          ), T_('I am'), false, '', $Settings->get( 'registration_require_gender' ) == 'required' );
 245  
 246      $button_refresh_regional = '<button id="%s" type="submit" name="actionArray[refresh_regional]" class="action_icon refresh_button">'.get_icon( 'refresh' ).'</button>';
 247      $button_refresh_regional .= '<img src="'.$rsc_url.'img/ajax-loader.gif" alt="'.T_('Loading...').'" title="'.T_('Loading...').'" style="display:none;margin:2px 0 0 5px" align="top" />';
 248  
 249      if( user_country_visible() )
 250      {    // Display a select input for Country
 251          $CountryCache = & get_CountryCache();
 252          $Form->select_country( 'edited_user_ctry_ID',
 253                  $edited_User->ctry_ID,
 254                  $CountryCache,
 255                  T_('Country'),
 256                  array(    // field params
 257                          'required' => $Settings->get( 'location_country' ) == 'required', // true if Country is required
 258                          'allow_none' => // Allow none value:
 259                                          $has_full_access || // Current user has permission to edit users
 260                                          empty( $edited_User->ctry_ID ) || // Country is not defined yet
 261                                          ( !empty( $edited_User->ctry_ID ) && $Settings->get( 'location_country' ) != 'required' ) // Country is defined but this field is not required
 262                      )
 263              );
 264      }
 265  
 266      if( user_region_visible() )
 267      {    // Display a select input for Region
 268          $regions_option_list = get_regions_option_list( $edited_User->ctry_ID, $edited_User->rgn_ID, array( 'none_option_text' => T_( 'Unknown' ) ) );
 269          $Form->select_input_options( 'edited_user_rgn_ID',
 270                  $regions_option_list,
 271                  T_( 'Region' ),
 272                  sprintf( $button_refresh_regional, 'button_refresh_region' ), // Button to refresh regions list
 273                  array(    // field params
 274                          'required' => $Settings->get( 'location_region' ) == 'required' // true if Region is required
 275                      )
 276              );
 277      }
 278  
 279      if( user_subregion_visible() )
 280      {    // Display a select input for Subregion
 281          $subregions_option_list = get_subregions_option_list( $edited_User->rgn_ID, $edited_User->subrg_ID, array( 'none_option_text' => T_( 'Unknown' ) ) );
 282          $Form->select_input_options( 'edited_user_subrg_ID',
 283                  $subregions_option_list,
 284                  T_( 'Sub-region' ),
 285                  sprintf( $button_refresh_regional, 'button_refresh_subregion' ), // Button to refresh subregions list
 286                  array(    // field params
 287                          'required' => $Settings->get( 'location_subregion' ) == 'required' // true if Subregion is required
 288                      )
 289              );
 290      }
 291  
 292      if( user_city_visible() )
 293      {    // Display a select input for City
 294          $cities_option_list = get_cities_option_list( $edited_User->ctry_ID, $edited_User->rgn_ID, $edited_User->subrg_ID, $edited_User->city_ID, array( 'none_option_text' => T_( 'Unknown' ) ) );
 295          $Form->select_input_options( 'edited_user_city_ID',
 296                  $cities_option_list,
 297                  T_( 'City' ),
 298                  sprintf( $button_refresh_regional, 'button_refresh_city' ), // Button to refresh cities list
 299                  array(    // field params
 300                          'required' => $Settings->get( 'location_city' ) == 'required' // true if City is required
 301                      )
 302              );
 303      }
 304  
 305      $Form->interval( 'edited_user_age_min', $edited_User->age_min, 'edited_user_age_max', $edited_User->age_max, 3, T_('My age group') );
 306  
 307      if( $new_user_creating )
 308      {
 309          $Form->text_input( 'edited_user_source', $edited_User->source, 30, T_('Source'), '', array( 'maxlength' => 30 ) );
 310      }
 311  
 312      if( $edited_User->get_field_url() != '' )
 313      {    // At least one url field is existing for current user
 314          $Form->info( T_('URL'), $edited_User->get_field_link(), T_('(This is the main URL advertised for this profile. It is automatically selected from the URLs you enter in the fields below.)') );
 315      }
 316  }
 317  else
 318  { // display only
 319  
 320      if( $Settings->get('allow_avatars') )
 321      {
 322          $Form->info( T_('Profile picture'), $edited_User->get_avatar_imgtag( 'crop-top-64x64', 'avatar', '', true ) );
 323      }
 324  
 325      $Form->info( T_('Login'), $edited_User->get('login') );
 326      $Form->info( T_('First name'), $edited_User->get('firstname') );
 327      $Form->info( T_('Last name'), $edited_User->get('lastname') );
 328      $Form->info( T_('Nickname'), $edited_User->get('nickname') );
 329      $Form->info( T_('Identity shown'), $edited_User->get('preferredname') );
 330  
 331      $user_gender = $edited_User->get( 'gender' );
 332      if( ! empty( $user_gender ) )
 333      {
 334          $Form->info( T_('Gender'), $edited_User->get_gender() );
 335      }
 336  
 337      if( ! empty( $edited_User->ctry_ID ) )
 338      {    // Display country
 339          load_class( 'regional/model/_country.class.php', 'Country' );
 340          $Form->info( T_('Country'), $edited_User->get_country_name() );
 341      }
 342  
 343      if( ! empty( $edited_User->rgn_ID ) )
 344      {    // Display region
 345          load_class( 'regional/model/_region.class.php', 'Region' );
 346          $Form->info( T_( 'Region' ), $edited_User->get_region_name() );
 347      }
 348  
 349      if( ! empty( $edited_User->rgn_ID ) )
 350      {    // Display sub-region
 351          load_class( 'regional/model/_subregion.class.php', 'Subregion' );
 352          $Form->info( T_( 'Sub-region' ), $edited_User->get_subregion_name() );
 353      }
 354  
 355      if( ! empty( $edited_User->city_ID ) )
 356      {    // Display city
 357          load_class( 'regional/model/_city.class.php', 'City' );
 358          $Form->info( T_( 'City' ), $edited_User->get_city_name() );
 359      }
 360  
 361      //$Form->info( T_('My ZIP/Postcode'), $edited_User->get('postcode') );
 362      $Form->info( T_('My age group'), $edited_User->get('age_min') );
 363      $Form->info( T_('to'), $edited_User->get('age_max') );
 364  
 365      $Form->info( T_('URL'), $edited_User->get('url'), $url_fieldnote );
 366  }
 367  
 368  $Form->end_fieldset();
 369  
 370      /***************  Password  **************/
 371  
 372  if( empty( $edited_User->ID ) && $action != 'view' )
 373  { // We can edit the values:
 374  
 375      $Form->begin_fieldset( T_('Password') );
 376          $Form->password_input( 'edited_user_pass1', '', 20, T_('New password'), array( 'maxlength' => 50, 'required' => true, 'autocomplete'=>'off' ) );
 377          $Form->password_input( 'edited_user_pass2', '', 20, T_('Confirm new password'), array( 'note'=>sprintf( T_('Minimum length: %d characters.'), $Settings->get('user_minpwdlen') ), 'maxlength' => 50, 'required' => true, 'autocomplete'=>'off' ) );
 378      $Form->end_fieldset();
 379  }
 380  
 381      /***************  Multiple sessions  **************/
 382  
 383  if( empty( $edited_User->ID ) && $action != 'view' )
 384  {    // New user will be created with default multiple_session setting
 385  
 386      $multiple_sessions = $Settings->get( 'multiple_sessions' );
 387      if( $multiple_sessions == 'userset_default_yes' || ( $has_full_access && $multiple_sessions == 'adminset_default_yes' ) )
 388      {
 389          $Form->hidden( 'edited_user_set_login_multiple_sessions', 1 );
 390      }
 391      else
 392      {
 393          $Form->hidden( 'edited_user_set_login_multiple_sessions', 0 );
 394      }
 395  }
 396  
 397  /***************  Additional info  **************/
 398  
 399  // This totally needs to move into User object
 400  global $DB;
 401  
 402  // Get original user id for duplicate
 403  if( $edited_User->ID == 0 )
 404  {
 405      $user_id = param( 'user_ID', 'integer', 0 );
 406      if( $user_id == 0 )
 407      {
 408          $user_id = param( 'orig_user_ID', 'integer', 0 );
 409      }
 410  }
 411  else
 412  {
 413      $user_id = $edited_User->ID;
 414  }
 415  
 416  // -------------------  Get existing userfields: -------------------------------
 417  $userfields = $DB->get_results( '
 418  SELECT ufdf_ID, uf_ID, ufdf_type, ufdf_name, uf_varchar, ufdf_required, ufdf_options, ufgp_order, ufdf_order, ufdf_suggest, ufdf_duplicated, ufgp_ID, ufgp_name
 419  FROM
 420      (
 421          SELECT ufdf_ID, uf_ID, ufdf_type, ufdf_name, uf_varchar, ufdf_required, ufdf_options, ufgp_order, ufdf_order, ufdf_suggest, ufdf_duplicated, ufgp_ID, ufgp_name
 422              FROM T_users__fields
 423                  LEFT JOIN T_users__fielddefs ON uf_ufdf_ID = ufdf_ID
 424                  LEFT JOIN T_users__fieldgroups ON ufdf_ufgp_ID = ufgp_ID
 425          WHERE uf_user_ID = '.$user_id.'
 426  
 427          UNION
 428  
 429          SELECT ufdf_ID, "0" AS uf_ID, ufdf_type, ufdf_name, "" AS uf_varchar, ufdf_required, ufdf_options, ufgp_order, ufdf_order, ufdf_suggest, ufdf_duplicated, ufgp_ID, ufgp_name
 430              FROM T_users__fielddefs
 431                  LEFT JOIN T_users__fieldgroups ON ufdf_ufgp_ID = ufgp_ID
 432          WHERE ufdf_required IN ( "recommended", "require" )
 433              AND ufdf_ID NOT IN ( SELECT uf_ufdf_ID FROM T_users__fields WHERE uf_user_ID = '.$user_id.' )
 434      ) tfields
 435  ORDER BY ufgp_order, ufdf_order, uf_ID' );
 436  
 437  userfields_display( $userfields, $Form );
 438  
 439  if( $action != 'view' )
 440  {    // Edit mode
 441  // ------------------- Add new field: -------------------------------
 442  $Form->begin_fieldset( T_('Add new fields') );
 443  
 444      // -------------------  Display new added userfields: -------------------------------
 445      global $add_field_types, $Messages;
 446  
 447      if( $Messages->has_errors() )
 448      {    // Display new added fields(from submitted form) only if errors are exist
 449          if( is_array( $add_field_types ) && count( $add_field_types ) > 0 )
 450          {    // This case happens when user add a new required field and he doesn't fill it, then we should show all fields again
 451              foreach( $add_field_types as $add_field_type )
 452              {    // We use "foreach" because sometimes the user adds several fields with the same type
 453                  $userfields = $DB->get_results( '
 454                  SELECT ufdf_ID, "0" AS uf_ID, ufdf_type, ufdf_name, "" AS uf_varchar, ufdf_required, ufdf_options, ufdf_suggest, ufdf_duplicated, ufgp_ID, ufgp_name
 455                      FROM T_users__fielddefs
 456                          LEFT JOIN T_users__fieldgroups ON ufdf_ufgp_ID = ufgp_ID
 457                  WHERE ufdf_ID = '.intval( $add_field_type ) );
 458  
 459                  userfields_display( $userfields, $Form, 'add', false );
 460              }
 461          }
 462      }
 463  
 464      $button_add_field = '<button type="submit" id="button_add_field" name="actionArray[add_field]" class="action_icon">'.get_icon( 'add' ).'</button>';
 465  
 466      $Form->select( 'new_field_type', param( 'new_field_type', 'integer', 0 ), 'callback_options_user_new_fields', T_('Add a field of type'), $button_add_field );
 467  
 468  $Form->end_fieldset();
 469  }
 470  
 471  $Form->hidden( 'orig_user_ID', $user_id );
 472  
 473  $Plugins->trigger_event( 'DisplayProfileFormFieldset', array(
 474              'Form' => & $ProfileForm,
 475              'User' => & $User,
 476              'edit_layout' => 'private',
 477              'is_admin_page' => $is_admin_page,
 478          ) );
 479  
 480      /***************  Buttons  **************/
 481  
 482  if( $action != 'view' )
 483  { // Edit buttons
 484      $action_buttons = array(
 485          array( '', 'actionArray[update]', T_( $is_admin ? 'Save !' : 'Save changes' ), 'SaveButton' ) );
 486      if( $is_admin )
 487      {
 488          $action_buttons[] = array( 'reset', '', T_('Reset'), 'ResetButton' );
 489          // dh> TODO: Non-Javascript-confirm before trashing all settings with a misplaced click.
 490          $action_buttons[] = array( 'type' => 'submit', 'name' => 'actionArray[default_settings]', 'value' => T_('Restore defaults'), 'class' => 'ResetButton',
 491              'onclick' => "return confirm('".TS_('This will reset all your user settings.').'\n'.TS_('This cannot be undone.').'\n'.TS_('Are you sure?')."');" );
 492      }
 493      $Form->buttons( $action_buttons );
 494  }
 495  
 496  
 497  $Form->end_form();
 498  
 499  ?>
 500  <script type="text/javascript">
 501  	function replace_form_params( result )
 502      {
 503          return result.replace( '#fieldstart#', '<?php echo format_to_js( str_ireplace( '$id$', '', $Form->fieldstart ) ); ?>' )
 504              .replace( '#fieldend#', '<?php echo format_to_js( $Form->fieldend ); ?>' )
 505              .replace( '#labelstart#', '<?php echo format_to_js( $Form->labelstart ); ?>' )
 506              .replace( '#labelend#', '<?php echo format_to_js( $Form->labelend ); ?>' )
 507              .replace( '#inputstart#', '<?php echo format_to_js( $Form->inputstart ); ?>' )
 508              .replace( '#inputend#', '<?php echo format_to_js( $Form->inputend ); ?>' );
 509      }
 510  
 511      jQuery( '#button_add_field' ).click( function ()
 512      {    // Action for the button when we want to add a new field in the Additional info
 513          var field_id = jQuery( this ).parent().prev().find( 'option:selected' ).val();
 514  
 515          if( field_id == '' )
 516          {    // Mark select element of field types as error
 517              field_type_error( '<?php echo T_('Please select a field type.'); ?>' );
 518              // We should to stop the ajax request without field_id
 519              return false;
 520          }
 521          else
 522          {    // Remove an error class from the field
 523              field_type_error_clear();
 524          }
 525  
 526          var this_obj = jQuery( this );
 527          jQuery.ajax({
 528          type: 'POST',
 529          url: '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php',
 530          data: 'action=get_user_new_field&user_id=<?php echo $edited_User->ID; ?>&field_id=' + field_id,
 531          success: function(result)
 532              {
 533                  result = ajax_debug_clear( result );
 534                  if( result == '[0]' )
 535                  {    // This field(not duplicated) already exists for current user
 536                      field_type_error( '<?php echo TS_('You already added this field, please select another.'); ?>' );
 537                  }
 538                  else
 539                  {
 540                      result = replace_form_params( result );
 541                      var field_duplicated = parseInt( result.replace( /^\[(\d+)\](.*)/, '$1' ) );
 542                      if( field_duplicated == 0 )
 543                      {    // This field is NOT duplicated
 544                          var field_id = parseInt( result.replace( /(.*)fieldset id="ffield_uf_add_(\d+)_(.*)/, '$2' ) );
 545                          // Remove option from select element
 546                          jQuery( '#new_field_type option[value='+field_id+']').remove();
 547                          if( jQuery( '[id^=uf_new_' + field_id + '], [id^=uf_add_' + field_id + ']' ).length > 0 )
 548                          {    // This field already exists(on the html form, not in DB) AND user cannot add a duplicate
 549                              field_type_error( '<?php echo TS_('You already added this field, please select another.'); ?>' );
 550                              return false;
 551                          }
 552                      }
 553                      // Print out new field on the form
 554                      jQuery( '#ffield_new_field_type' ).before( result.replace( /^\[\d+\](.*)/, '$1' ) );
 555                      // Show a button 'Add(+)' with new field
 556                      jQuery( 'span[rel^=add_ufdf_]' ).show();
 557  
 558                      bind_autocomplete( jQuery( '#ffield_new_field_type' ).prev().prev().find( 'input[id^=uf_add_][autocomplete=on]' ) );
 559                  }
 560              }
 561          });
 562  
 563          return false;
 564      } );
 565  
 566      jQuery( document ).on( 'focus', '[rel^=ufdf_]', function ()
 567      {    // Auto select the value for the field of type
 568          var field_id = parseInt( jQuery( this ).attr( 'rel' ).replace( /^ufdf_(\d+)$/, '$1' ) );
 569          if( field_id > 0 )
 570          {    // Select an option with current field type
 571              jQuery( '#new_field_type' ).val( field_id );
 572              field_type_error_clear();
 573          }
 574      } );
 575  
 576      jQuery( '#new_field_type' ).change( function ()
 577      {    // Remove all errors messages from field "Add a field of type:"
 578          field_type_error_clear();
 579      } );
 580  
 581  	function field_type_error( message )
 582      {    // Add an error message for the "field of type" select
 583          jQuery( 'select#new_field_type' ).addClass( 'field_error' );
 584          var span_error = jQuery( 'select#new_field_type' ).next().find( 'span.field_error' );
 585          if( span_error.length > 0 )
 586          {    // Replace a content of the existing span element
 587              span_error.html( message );
 588          }
 589          else
 590          {    // Create a new span element for error message
 591              jQuery( 'select#new_field_type' ).next().append( '<span class="field_error">' + message + '</span>' );
 592          }
 593      }
 594  
 595  	function field_type_error_clear()
 596      {    // Remove an error style from the "field of type" select
 597          jQuery( 'select#new_field_type' ).removeClass( 'field_error' )
 598                                                                              .next().find( 'span.field_error' ).remove();
 599      }
 600  
 601      <?php /*jQuery( 'span[rel^=add_ufdf_]' ).each( function()
 602      {    // Show only last button 'Add(+)' for each field type
 603          // These buttons is hidden by default to ignore browsers without javascript
 604          jQuery( 'span[rel=' + jQuery( this ).attr( 'rel' ) + ']:last' ).show();
 605      } );*/ ?>
 606      // Show a buttons 'Add(+)' for each field
 607      // These buttons is hidden by default to ignore a browsers without javascript
 608      jQuery( 'span[rel^=add_ufdf_]' ).show();
 609  
 610      jQuery( document ).on( 'click', 'span[rel^=add_ufdf_]', function()
 611      {    // Click event for button 'Add(+)'
 612          var this_obj = jQuery( this );
 613          var field_id = this_obj.attr( 'rel' ).replace( /^add_ufdf_(\d+)$/, '$1' );
 614  
 615          jQuery.ajax({
 616          type: 'POST',
 617          url: '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php',
 618          data: 'action=get_user_new_field&user_id=<?php echo $edited_User->ID; ?>&field_id=' + field_id,
 619          success: function( result )
 620              {
 621                  result = ajax_debug_clear( result );
 622                  if( result == '[0]' )
 623                  {    // This field(not duplicated) already exists for current user
 624                      field_type_error( '<?php echo TS_('You already added this field, please select another.'); ?>' );
 625                  }
 626                  else
 627                  {
 628                      result = replace_form_params( result );
 629                      var field_duplicated = parseInt( result.replace( /^\[(\d+)\](.*)/, '$1' ) );
 630                      if( field_duplicated == 0 )
 631                      {    // This field is NOT duplicated
 632                          field_type_error( '<?php echo TS_('You already added this field, please select another.'); ?>' );
 633                          return false;
 634                      }
 635                      var cur_fieldset_obj = this_obj.parent().parent().parent();
 636                      <?php /* // Remove current button 'Add(+)' and then we will show button with new added field
 637                      this_obj.remove();*/ ?>
 638                      // Print out new field on the form
 639                      cur_fieldset_obj.after( result.replace( /^\[\d+\](.*)/, '$1' ) )
 640                      // Show a button 'Add(+)' with new field
 641                                                      .next().find( 'span.icon' ).show();
 642  
 643                      var new_field = cur_fieldset_obj.next().find( 'input[id^=uf_add_]' );
 644                      if( new_field.attr( 'autocomplete' ) == 'on' )
 645                      {    // Bind autocomplete event
 646                          bind_autocomplete( new_field );
 647                      }
 648                      // Set auto focus on new created field
 649                      new_field.focus();
 650                  }
 651              }
 652          } );
 653      } );
 654  
 655      jQuery( document ).on( 'mouseover', 'span[rel^=add_ufdf_]', function()
 656      {    // Grab event from input to show bubbletip
 657          jQuery( this ).parent().prev().focus();
 658          jQuery( this ).css( 'z-index', jQuery( this ).parent().prev().css( 'z-index' ) );
 659      } );
 660      jQuery( document ).on( 'mouseout', 'span[rel^=add_ufdf_]', function()
 661      {    // Grab event from input to hide bubbletip
 662          var input = jQuery( this ).parent().prev();
 663          if( input.is( ':focus' ) )
 664          {    // Don't hide bubbletip if current input is focused
 665              return false;
 666          }
 667          input.blur();
 668      } );
 669  </script>
 670  
 671  <script type="text/javascript">
 672  function bind_autocomplete( field_objs )
 673  {    // Bind autocomplete plugin event
 674      if( field_objs.length > 0 )
 675      {    // If selected elements are exists
 676          field_objs.autocomplete( {
 677              source: function(request, response) {
 678                  jQuery.getJSON( '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php?action=get_user_field_autocomplete', {
 679                      term: request.term, attr_id: this.element[0].getAttribute( 'id' )
 680                  }, response);
 681              },
 682          } );
 683      }
 684  }
 685  // Plugin jQuery(...).live() doesn't work with autocomplete
 686  // We should assign an autocomplete event for each new added field
 687  bind_autocomplete( jQuery( 'input[id^=uf_][autocomplete=on]' ) );
 688  </script>
 689  <?php
 690  // Location
 691  echo_regional_js( 'edited_user', user_region_visible() );
 692  
 693  ?>

title

Description

title

Description

title

Description

title

title

Body