/[drupal]/drupal/modules/user/user.pages.inc
ViewVC logotype

Diff of /drupal/modules/user/user.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.25 by dries, Tue Dec 30 16:43:20 2008 UTC revision 1.26 by webchick, Thu Jan 8 08:42:13 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: user.pages.inc,v 1.24 2008/11/24 00:40:45 webchick Exp $  // $Id: user.pages.inc,v 1.25 2008/12/30 16:43:20 dries Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 228  function user_edit($account, $category = Line 228  function user_edit($account, $category =
228   * @ingroup forms   * @ingroup forms
229   * @see user_profile_form_validate()   * @see user_profile_form_validate()
230   * @see user_profile_form_submit()   * @see user_profile_form_submit()
231   * @see user_edit_delete_submit()   * @see user_cancel_confirm_form_submit()
232   */   */
233  function user_profile_form($form_state, $account, $category = 'account') {  function user_profile_form($form_state, $account, $category = 'account') {
234      global $user;
235    
236    $edit = (empty($form_state['values'])) ? (array)$account : $form_state['values'];    $edit = (empty($form_state['values'])) ? (array)$account : $form_state['values'];
237    
# Line 238  function user_profile_form($form_state, Line 239  function user_profile_form($form_state,
239    $form['_category'] = array('#type' => 'value', '#value' => $category);    $form['_category'] = array('#type' => 'value', '#value' => $category);
240    $form['_account'] = array('#type' => 'value', '#value' => $account);    $form['_account'] = array('#type' => 'value', '#value' => $account);
241    $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 30);    $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 30);
242    if (user_access('administer users')) {    if (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')) {
243      $form['delete'] = array(      $form['cancel'] = array(
244        '#type' => 'submit',        '#type' => 'submit',
245        '#value' => t('Delete'),        '#value' => t('Cancel account'),
246        '#weight' => 31,        '#weight' => 31,
247        '#submit' => array('user_edit_delete_submit'),        '#submit' => array('user_edit_cancel_submit'),
248      );      );
249    }    }
250    $form['#attributes']['enctype'] = 'multipart/form-data';    $form['#attributes']['enctype'] = 'multipart/form-data';
# Line 270  function user_profile_form_validate($for Line 271  function user_profile_form_validate($for
271  function user_profile_form_submit($form, &$form_state) {  function user_profile_form_submit($form, &$form_state) {
272    $account = $form_state['values']['_account'];    $account = $form_state['values']['_account'];
273    $category = $form_state['values']['_category'];    $category = $form_state['values']['_category'];
274    unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['delete'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);    unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['cancel'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);
275    user_module_invoke('submit', $form_state['values'], $account, $category);    user_module_invoke('submit', $form_state['values'], $account, $category);
276    user_save($account, $form_state['values'], $category);    user_save($account, $form_state['values'], $category);
277    
# Line 282  function user_profile_form_submit($form, Line 283  function user_profile_form_submit($form,
283  }  }
284    
285  /**  /**
286   * Submit function for the 'Delete' button on the user edit form.   * Submit function for the 'Cancel account' button on the user edit form.
287   */   */
288  function user_edit_delete_submit($form, &$form_state) {  function user_edit_cancel_submit($form, &$form_state) {
289    $destination = '';    $destination = '';
290    if (isset($_REQUEST['destination'])) {    if (isset($_REQUEST['destination'])) {
291      $destination = drupal_get_destination();      $destination = drupal_get_destination();
292      unset($_REQUEST['destination']);      unset($_REQUEST['destination']);
293    }    }
294    // Note: We redirect from user/uid/edit to user/uid/delete to make the tabs disappear.    // Note: We redirect from user/uid/edit to user/uid/cancel to make the tabs disappear.
295    $form_state['redirect'] = array("user/" . $form_state['values']['_account']->uid . "/delete", $destination);    $form_state['redirect'] = array("user/" . $form_state['values']['_account']->uid . "/cancel", $destination);
296  }  }
297    
298  /**  /**
299   * Form builder; confirm form for user deletion.   * Form builder; confirm form for cancelling user account.
300   *   *
301   * @ingroup forms   * @ingroup forms
302   * @see user_confirm_delete_submit()   * @see user_edit_cancel_submit()
303   */   */
304  function user_confirm_delete(&$form_state, $account) {  function user_cancel_confirm_form(&$form_state, $account) {
305      global $user;
306    
307    $form['_account'] = array('#type' => 'value', '#value' => $account);    $form['_account'] = array('#type' => 'value', '#value' => $account);
308    
309      // Display account cancellation method selection, if allowed.
310      $default_method = variable_get('user_cancel_method', 'user_cancel_block');
311      $admin_access = user_access('administer users');
312      $can_select_method = $admin_access || user_access('select account cancellation method');
313      $form['user_cancel_method'] = array(
314        '#type' => 'item',
315        '#title' => ($account->uid == $user->uid ? t('When cancelling your account') : t('When cancelling the account')),
316        '#access' => $can_select_method,
317      );
318      $form['user_cancel_method'] += user_cancel_methods();
319    
320      // Allow user administrators to skip the account cancellation confirmation
321      // mail (by default), as long as they do not attempt to cancel their own
322      // account.
323      $override_access = $admin_access && ($account->uid != $user->uid);
324      $form['user_cancel_confirm'] = array(
325        '#type' => 'checkbox',
326        '#title' => t('Require e-mail confirmation to cancel account.'),
327        '#default_value' => ($override_access ? FALSE : TRUE),
328        '#access' => $override_access,
329        '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
330      );
331      // Also allow to send account canceled notification mail, if enabled.
332      $default_notify = variable_get('user_mail_status_canceled_notify', FALSE);
333      $form['user_cancel_notify'] = array(
334        '#type' => 'checkbox',
335        '#title' => t('Notify user when account is canceled.'),
336        '#default_value' => ($override_access ? FALSE : $default_notify),
337        '#access' => $override_access && $default_notify,
338        '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
339      );
340    
341      // Prepare confirmation form page title and description.
342      if ($account->uid == $user->uid) {
343        $question = t('Are you sure you want to cancel your account?');
344      }
345      else {
346        $question = t('Are you sure you want to cancel the account %name?', array('%name' => $account->name));
347      }
348      $description = '';
349      if ($can_select_method) {
350        $description = t('Select the method to cancel the account above.');
351        foreach (element_children($form['user_cancel_method']) as $element) {
352          unset($form['user_cancel_method'][$element]['#description']);
353        }
354      }
355      else {
356        // The radio button #description is used as description for the confirmation
357        // form.
358        foreach (element_children($form['user_cancel_method']) as $element) {
359          if ($form['user_cancel_method'][$element]['#default_value'] == $form['user_cancel_method'][$element]['#return_value']) {
360            $description = $form['user_cancel_method'][$element]['#description'];
361          }
362          unset($form['user_cancel_method'][$element]['#description']);
363        }
364      }
365    
366    return confirm_form($form,    return confirm_form($form,
367      t('Are you sure you want to delete the account %name?', array('%name' => $account->name)),      $question,
368      'user/' . $account->uid,      'user/' . $account->uid,
369      t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'),      $description . ' ' . t('This action cannot be undone.'),
370      t('Delete'), t('Cancel'));      t('Cancel account'), t('Cancel'));
371  }  }
372    
373  /**  /**
374   * Submit function for the confirm form for user deletion.   * Submit handler for the account cancellation confirm form.
375     *
376     * @see user_cancel_confirm_form()
377     * @see user_multiple_cancel_confirm_submit()
378   */   */
379  function user_confirm_delete_submit($form, &$form_state) {  function user_cancel_confirm_form_submit($form, &$form_state) {
380    user_delete($form_state['values'], $form_state['values']['_account']->uid);    global $user;
381    drupal_set_message(t('%name has been deleted.', array('%name' => $form_state['values']['_account']->name)));    $account = $form_state['values']['_account'];
382    
383      // Cancel account immediately, if the current user has administrative
384      // privileges, no confirmation mail shall be sent, and the user does not
385      // attempt to cancel the own account.
386      if (user_access('administer users') && empty($form_state['values']['user_cancel_confirm']) && $account->uid != $user->uid) {
387        user_cancel($form_state['values'], $account->uid, $form_state['values']['user_cancel_method']);
388    
389    if (!isset($_REQUEST['destination'])) {      if (!isset($_REQUEST['destination'])) {
390      $form_state['redirect'] = 'admin/user/user';        $form_state['redirect'] = 'admin/user/user';
391        }
392      }
393      else {
394        // Store cancelling method and whether to notify the user in $account for
395        // user_cancel_confirm().
396        $edit = array(
397          'user_cancel_method' => $form_state['values']['user_cancel_method'],
398          'user_cancel_notify' => $form_state['values']['user_cancel_notify'],
399        );
400        $account = user_save($account, $edit);
401        _user_mail_notify('cancel_confirm', $account);
402        drupal_set_message(t('A confirmation request to cancel your account has been sent to your e-mail address.'));
403    
404        if (!isset($_REQUEST['destination'])) {
405          $form_state['redirect'] = "user/$account->uid";
406        }
407      }
408    }
409    
410    /**
411     * Helper function to return available account cancellation methods.
412     *
413     * Please refer to the documentation of hook_user_cancel_methods_alter().
414     *
415     * @return
416     *   An array containing all account cancellation methods as form elements.
417     *
418     * @see hook_user_cancel_methods_alter()
419     * @see user_admin_settings()
420     * @see user_cancel_confirm_form()
421     * @see user_multiple_cancel_confirm()
422     */
423    function user_cancel_methods() {
424      $methods = array(
425        'user_cancel_block' => array(
426          'title' => t('Disable the account and keep all content.'),
427          'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'),
428        ),
429        'user_cancel_block_unpublish' => array(
430          'title' => t('Disable the account and unpublish all content.'),
431          'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'),
432        ),
433        'user_cancel_reassign' => array(
434          'title' => t('Delete the account and make all content belong to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))),
435          'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))),
436        ),
437        'user_cancel_delete' => array(
438          'title' => t('Delete the account and all content.'),
439          'description' => t('Your account will be removed and all account information deleted. All of your content will also be deleted.'),
440          'access' => user_access('administer users'),
441        ),
442      );
443      // Allow modules to customize account cancellation methods.
444      drupal_alter('user_cancel_methods', $methods);
445    
446      // Turn all methods into real form elements.
447      $default_method = variable_get('user_cancel_method', 'user_cancel_block');
448      $form = array();
449      foreach ($methods as $name => $method) {
450        $form[$name] = array(
451          '#type' => 'radio',
452          '#title' => $method['title'],
453          '#description' => (isset($method['description']) ? $method['description'] : NULL),
454          '#return_value' => $name,
455          '#default_value' => $default_method,
456          '#parents' => array('user_cancel_method'),
457          '#required' => TRUE,
458        );
459      }
460      return $form;
461    }
462    
463    /**
464     * Menu callback; Cancel a user account via e-mail confirmation link.
465     *
466     * @see user_cancel_confirm_form()
467     * @see user_cancel_url()
468     */
469    function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') {
470      // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
471      $timeout = 86400;
472      $current = REQUEST_TIME;
473    
474      // Basic validation of arguments.
475      if (isset($account->user_cancel_method) && !empty($timestamp) && !empty($hashed_pass)) {
476        // Validate expiration and hashed password/login.
477        if ($timestamp <= $current && $current - $timestamp < $timeout && $account->uid && $timestamp >= $account->login && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) {
478          $edit = array(
479            'user_cancel_notify' => isset($account->user_cancel_notify) ? $account->user_cancel_notify : variable_get('user_mail_status_canceled_notify', FALSE),
480          );
481          user_cancel($edit, $account->uid, $account->user_cancel_method);
482          // Since user_cancel() is not invoked via Form API, batch processing needs
483          // to be invoked manually and should redirect to the front page after
484          // completion.
485          batch_process('');
486        }
487        else {
488          drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'));
489          drupal_goto("user/$account->uid/cancel");
490        }
491    }    }
492      drupal_access_denied();
493  }  }
494    
495  function user_edit_validate($form, &$form_state) {  function user_edit_validate($form, &$form_state) {
# Line 336  function user_edit_validate($form, &$for Line 505  function user_edit_validate($form, &$for
505  function user_edit_submit($form, &$form_state) {  function user_edit_submit($form, &$form_state) {
506    $account = $form_state['values']['_account'];    $account = $form_state['values']['_account'];
507    $category = $form_state['values']['_category'];    $category = $form_state['values']['_category'];
508    unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['delete'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);    unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['cancel'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);
509    user_module_invoke('submit', $form_state['values'], $account, $category);    user_module_invoke('submit', $form_state['values'], $account, $category);
510    user_save($account, $form_state['values'], $category);    user_save($account, $form_state['values'], $category);
511    

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.3