/[drupal]/contributions/modules/pageroute/pageroute.page_user_edit.inc
ViewVC logotype

Contents of /contributions/modules/pageroute/pageroute.page_user_edit.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Sat Sep 13 13:45:09 2008 UTC (14 months, 1 week ago) by tauran
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of pageroute d6 dev version.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Page user edit type
7 */
8
9 include_once(drupal_get_path('module', 'pageroute') .'/pageroute.page.inc');
10
11 class pageroute_page_user_edit extends pageroute_page {
12
13 public function get_form(&$form_state, &$args) {
14 $form = array();
15
16 if ($args && isset($args['uid'])) {
17 $account = user_load(array('uid' => $args['uid']));
18 }
19 else {
20 $account = user_load(array('uid' => pageroute_page_get_uid($this, 'administer users')));
21 }
22
23 if (!$account->uid) {
24 drupal_not_found();
25 pageroute_exit_now();
26 }
27
28 if ($args['todo']['action'] == t('Delete')) {
29 $args['hide_pageroute_buttons'] = TRUE;
30 $args['submit_action'] = PAGEROUTE_CURRENT;
31 return pageroute_node_delete_confirm($account, $form, $page, $args);
32 }
33
34 $args['hide_pageroute_buttons'] = FALSE;
35 $args['submit_action'] = PAGEROUTE_FORWARD;
36
37 $form = drupal_retrieve_form('user_profile_form', &$form_state, $account, $this->options['category']);
38 drupal_prepare_form('user_edit', &$form, &$form_state);
39
40 $page->configure_form(&$form);
41
42 return $form;
43 }
44
45 public static function ui($page, &$form) {
46 $categories = array();
47 foreach (_user_categories(false) as $category) {
48 $categories[$category['name']] = $category['title'];
49 }
50 $form['options']['category'] = array(
51 '#type' => 'select',
52 '#title' => t('Category'),
53 '#description' => t('The form of the chosen category will be used for this page.'),
54 '#required' => TRUE,
55 '#default_value' => isset($page->options['category']) ? $page->options['category'] : '',
56 '#weight' => 2,
57 '#options' => $categories,
58 );
59 }
60
61 public static function help() {
62 return t('A page of this type will present users\' account editing page '.
63 'inside a pageroute. By giving a user id as second pageroute argument '.
64 'it\'s also possible for administrators to edit another users\' account.'.
65 'By choosing another category it could also be used to integrate a drupal user profile into a pageroute.') .
66 '<br />'.
67 t('!warn This page type is still experimental. If you consider using it, make '.
68 'sure you \'ve read !link before!',
69 array('!warn' => '<strong>'. t('Warning!') .'</strong>', '!link' => l(t('this issue'), 'http://drupal.org/node/128045')));
70 }
71
72 public static function info() {
73 return array('name' => t('User editing form'));
74 }
75
76 public static function form_submitted(&$form_state) {
77
78 $todo = NULL;
79
80 if ($form_state['clicked_button']['#value'] == t('Delete')) {
81 if (is_numeric($form_state['clicked_button']['#name'])) {
82 $target = $form_state['clicked_button']['#name'];
83 }
84 else {
85 $target = $form_state['storage']['args']['todo']['target'];
86 }
87 $todo = array('action' => $form_state['clicked_button']['#value'], 'target' => $target);
88 }
89
90 return $todo;
91 }
92
93 protected function set_up() {
94 include_once(drupal_get_path('module', 'user') .'/user.pages.inc');
95 }
96 }
97
98 /*
99 * Provide an extra delete page to keep control about the destination parameter.
100 */
101 function pageroute_user_delete_confirm($user, $form, &$page, $args = NULL) {
102 if (user_access('delete', $user)) {
103
104 $form = array();
105 $form['uid'] = array('#type' => 'value', '#value' => $user->uid);
106
107 $form = confirm_form($form,
108 t('Are you sure you want to delete %name?', array('%name' => $user->name)),
109 pageroute_get_page_path($page, $args),
110 t('This action cannot be undone.'), t('Delete'), t('Cancel')
111 );
112
113 $form['actions']['submit']['#submit'][] = 'pageroute_user_delete_confirm_submit';
114
115 return $form;
116 }
117 drupal_access_denied();
118 pageroute_exit_now();
119 }
120
121 function pageroute_user_delete_confirm_submit($form, &$form_state) {
122 $form_state['target'] = PAGEROUTE_CURRENT;
123
124 if ($form_state['values']['confirm']) {
125 user_delete($form_state['values']['uid']);
126 }
127
128 $form_state['rebuild'] = TRUE;
129 unset($form_state['values']['target']);
130 unset($form_state['button_clicked']);
131 unset($form_state['args']['todo']);
132 unset($form_state['todo']);
133 }

  ViewVC Help
Powered by ViewVC 1.1.2