webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: profile.admin.inc,v 1.8 2008/01/21 15:20:43 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * @file |
webmaster@1
|
6 * Administrative page callbacks for the profile module. |
webmaster@1
|
7 */ |
webmaster@1
|
8 |
webmaster@1
|
9 /** |
webmaster@1
|
10 * Form builder to display a listing of all editable profile fields. |
webmaster@1
|
11 * |
webmaster@1
|
12 * @ingroup forms |
webmaster@1
|
13 * @see profile_admin_overview_submit() |
webmaster@1
|
14 */ |
webmaster@1
|
15 function profile_admin_overview() { |
webmaster@1
|
16 $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_fields} ORDER BY category, weight'); |
webmaster@1
|
17 |
webmaster@1
|
18 $form = array(); |
webmaster@1
|
19 $categories = array(); |
webmaster@1
|
20 while ($field = db_fetch_object($result)) { |
webmaster@1
|
21 // Collect all category information |
webmaster@1
|
22 $categories[] = $field->category; |
webmaster@1
|
23 |
webmaster@1
|
24 // Save all field information |
webmaster@1
|
25 $form[$field->fid]['name'] = array('#value' => check_plain($field->name)); |
webmaster@1
|
26 $form[$field->fid]['title'] = array('#value' => check_plain($field->title)); |
webmaster@1
|
27 $form[$field->fid]['type'] = array('#value' => $field->type); |
webmaster@1
|
28 $form[$field->fid]['category'] = array('#type' => 'select', '#default_value' => $field->category, '#options' => array()); |
webmaster@1
|
29 $form[$field->fid]['weight'] = array('#type' => 'weight', '#default_value' => $field->weight); |
webmaster@1
|
30 $form[$field->fid]['edit'] = array('#value' => l(t('edit'), "admin/user/profile/edit/$field->fid")); |
webmaster@1
|
31 $form[$field->fid]['delete'] = array('#value' => l(t('delete'), "admin/user/profile/delete/$field->fid")); |
webmaster@1
|
32 } |
webmaster@1
|
33 |
webmaster@1
|
34 // Add the cateogory combo boxes |
webmaster@1
|
35 $categories = array_unique($categories); |
webmaster@1
|
36 foreach ($form as $fid => $field) { |
webmaster@1
|
37 foreach ($categories as $cat => $category) { |
webmaster@1
|
38 $form[$fid]['category']['#options'][$category] = $category; |
webmaster@1
|
39 } |
webmaster@1
|
40 } |
webmaster@1
|
41 |
webmaster@1
|
42 // Display the submit button only when there's more than one field |
webmaster@1
|
43 if (count($form) > 1) { |
webmaster@1
|
44 $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); |
webmaster@1
|
45 } |
webmaster@1
|
46 else { |
webmaster@1
|
47 // Disable combo boxes when there isn't a submit button |
webmaster@1
|
48 foreach ($form as $fid => $field) { |
webmaster@1
|
49 unset($form[$fid]['weight']); |
webmaster@1
|
50 $form[$fid]['category']['#type'] = 'value'; |
webmaster@1
|
51 } |
webmaster@1
|
52 } |
webmaster@1
|
53 $form['#tree'] = TRUE; |
webmaster@1
|
54 |
webmaster@1
|
55 $addnewfields = '<h2>'. t('Add new field') .'</h2>'; |
webmaster@1
|
56 $addnewfields .= '<ul>'; |
webmaster@1
|
57 foreach (_profile_field_types() as $key => $value) { |
webmaster@1
|
58 $addnewfields .= '<li>'. l($value, "admin/user/profile/add/$key") .'</li>'; |
webmaster@1
|
59 } |
webmaster@1
|
60 $addnewfields .= '</ul>'; |
webmaster@1
|
61 $form['addnewfields'] = array('#value' => $addnewfields); |
webmaster@1
|
62 |
webmaster@1
|
63 return $form; |
webmaster@1
|
64 } |
webmaster@1
|
65 |
webmaster@1
|
66 /** |
webmaster@1
|
67 * Submit handler to update changed profile field weights and categories. |
webmaster@1
|
68 * |
webmaster@1
|
69 * @see profile_admin_overview() |
webmaster@1
|
70 */ |
webmaster@1
|
71 function profile_admin_overview_submit($form, &$form_state) { |
webmaster@1
|
72 foreach (element_children($form_state['values']) as $fid) { |
webmaster@1
|
73 if (is_numeric($fid)) { |
webmaster@1
|
74 $weight = $form_state['values'][$fid]['weight']; |
webmaster@1
|
75 $category = $form_state['values'][$fid]['category']; |
webmaster@1
|
76 if ($weight != $form[$fid]['weight']['#default_value'] || $category != $form[$fid]['category']['#default_value']) { |
webmaster@1
|
77 db_query("UPDATE {profile_fields} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid); |
webmaster@1
|
78 } |
webmaster@1
|
79 } |
webmaster@1
|
80 } |
webmaster@1
|
81 |
webmaster@1
|
82 drupal_set_message(t('Profile fields have been updated.')); |
webmaster@1
|
83 cache_clear_all(); |
webmaster@1
|
84 menu_rebuild(); |
webmaster@1
|
85 } |
webmaster@1
|
86 |
webmaster@1
|
87 /** |
webmaster@1
|
88 * Theme the profile field overview into a drag and drop enabled table. |
webmaster@1
|
89 * |
webmaster@1
|
90 * @ingroup themeable |
webmaster@1
|
91 * @see profile_admin_overview() |
webmaster@1
|
92 */ |
webmaster@1
|
93 function theme_profile_admin_overview($form) { |
webmaster@1
|
94 drupal_add_css(drupal_get_path('module', 'profile') .'/profile.css'); |
webmaster@1
|
95 // Add javascript if there's more than one field. |
webmaster@1
|
96 if (isset($form['submit'])) { |
webmaster@1
|
97 drupal_add_js(drupal_get_path('module', 'profile') .'/profile.js'); |
webmaster@1
|
98 } |
webmaster@1
|
99 |
webmaster@1
|
100 $rows = array(); |
webmaster@1
|
101 $categories = array(); |
webmaster@1
|
102 $category_number = 0; |
webmaster@1
|
103 foreach (element_children($form) as $key) { |
webmaster@1
|
104 // Don't take form control structures. |
webmaster@1
|
105 if (array_key_exists('category', $form[$key])) { |
webmaster@1
|
106 $field = &$form[$key]; |
webmaster@1
|
107 $category = $field['category']['#default_value']; |
webmaster@1
|
108 |
webmaster@1
|
109 if (!isset($categories[$category])) { |
webmaster@1
|
110 // Category classes are given numeric IDs because there's no guarantee |
webmaster@1
|
111 // class names won't contain invalid characters. |
webmaster@1
|
112 $categories[$category] = $category_number; |
webmaster@1
|
113 $category_field['#attributes']['class'] = 'profile-category profile-category-'. $category_number; |
webmaster@1
|
114 $rows[] = array(array('data' => $category, 'colspan' => 7, 'class' => 'category')); |
webmaster@1
|
115 $rows[] = array('data' => array(array('data' => '<em>'. t('No fields in this category. If this category remains empty when saved, it will be removed.') .'</em>', 'colspan' => 7)), 'class' => 'category-'. $category_number .'-message category-message category-populated'); |
webmaster@1
|
116 |
webmaster@1
|
117 // Make it dragable only if there is more than one field |
webmaster@1
|
118 if (isset($form['submit'])) { |
webmaster@1
|
119 drupal_add_tabledrag('profile-fields', 'order', 'sibling', 'profile-weight', 'profile-weight-'. $category_number); |
webmaster@1
|
120 drupal_add_tabledrag('profile-fields', 'match', 'sibling', 'profile-category', 'profile-category-'. $category_number); |
webmaster@1
|
121 } |
webmaster@1
|
122 $category_number++; |
webmaster@1
|
123 } |
webmaster@1
|
124 |
webmaster@1
|
125 // Add special drag and drop classes that group fields together. |
webmaster@1
|
126 $field['weight']['#attributes']['class'] = 'profile-weight profile-weight-'. $categories[$category]; |
webmaster@1
|
127 $field['category']['#attributes']['class'] = 'profile-category profile-category-'. $categories[$category]; |
webmaster@1
|
128 |
webmaster@1
|
129 // Add the row |
webmaster@1
|
130 $row = array(); |
webmaster@1
|
131 $row[] = drupal_render($field['title']); |
webmaster@1
|
132 $row[] = drupal_render($field['name']); |
webmaster@1
|
133 $row[] = drupal_render($field['type']); |
webmaster@1
|
134 if (isset($form['submit'])) { |
webmaster@1
|
135 $row[] = drupal_render($field['category']); |
webmaster@1
|
136 $row[] = drupal_render($field['weight']); |
webmaster@1
|
137 } |
webmaster@1
|
138 $row[] = drupal_render($field['edit']); |
webmaster@1
|
139 $row[] = drupal_render($field['delete']); |
webmaster@1
|
140 $rows[] = array('data' => $row, 'class' => 'draggable'); |
webmaster@1
|
141 } |
webmaster@1
|
142 } |
webmaster@1
|
143 if (empty($rows)) { |
webmaster@1
|
144 $rows[] = array(array('data' => t('No fields available.'), 'colspan' => 7)); |
webmaster@1
|
145 } |
webmaster@1
|
146 |
webmaster@1
|
147 $header = array(t('Title'), t('Name'), t('Type')); |
webmaster@1
|
148 if (isset($form['submit'])) { |
webmaster@1
|
149 $header[] = t('Category'); |
webmaster@1
|
150 $header[] = t('Weight'); |
webmaster@1
|
151 } |
webmaster@1
|
152 $header[] = array('data' => t('Operations'), 'colspan' => 2); |
webmaster@1
|
153 |
webmaster@1
|
154 $output = theme('table', $header, $rows, array('id' => 'profile-fields')); |
webmaster@1
|
155 $output .= drupal_render($form); |
webmaster@1
|
156 |
webmaster@1
|
157 return $output; |
webmaster@1
|
158 } |
webmaster@1
|
159 |
webmaster@1
|
160 /** |
webmaster@1
|
161 * Menu callback: Generate a form to add/edit a user profile field. |
webmaster@1
|
162 * |
webmaster@1
|
163 * @ingroup forms |
webmaster@1
|
164 * @see profile_field_form_validate() |
webmaster@1
|
165 * @see profile_field_form_submit() |
webmaster@1
|
166 */ |
webmaster@1
|
167 function profile_field_form(&$form_state, $arg = NULL) { |
webmaster@1
|
168 if (arg(3) == 'edit') { |
webmaster@1
|
169 if (is_numeric($arg)) { |
webmaster@1
|
170 $fid = $arg; |
webmaster@1
|
171 |
webmaster@1
|
172 $edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); |
webmaster@1
|
173 |
webmaster@1
|
174 if (!$edit) { |
webmaster@1
|
175 drupal_not_found(); |
webmaster@1
|
176 return; |
webmaster@1
|
177 } |
webmaster@1
|
178 drupal_set_title(t('edit %title', array('%title' => $edit['title']))); |
webmaster@1
|
179 $form['fid'] = array('#type' => 'value', |
webmaster@1
|
180 '#value' => $fid, |
webmaster@1
|
181 ); |
webmaster@1
|
182 $type = $edit['type']; |
webmaster@1
|
183 } |
webmaster@1
|
184 else { |
webmaster@1
|
185 drupal_not_found(); |
webmaster@1
|
186 return; |
webmaster@1
|
187 } |
webmaster@1
|
188 } |
webmaster@1
|
189 else { |
webmaster@1
|
190 $types = _profile_field_types(); |
webmaster@1
|
191 if (!isset($types[$arg])) { |
webmaster@1
|
192 drupal_not_found(); |
webmaster@1
|
193 return; |
webmaster@1
|
194 } |
webmaster@1
|
195 $type = $arg; |
webmaster@1
|
196 drupal_set_title(t('add new %type', array('%type' => $types[$type]))); |
webmaster@1
|
197 $edit = array('name' => 'profile_'); |
webmaster@1
|
198 $form['type'] = array('#type' => 'value', '#value' => $type); |
webmaster@1
|
199 } |
webmaster@1
|
200 $edit += array( |
webmaster@1
|
201 'category' => '', |
webmaster@1
|
202 'title' => '', |
webmaster@1
|
203 'explanation' => '', |
webmaster@1
|
204 'weight' => 0, |
webmaster@1
|
205 'page' => '', |
webmaster@1
|
206 'autocomplete' => '', |
webmaster@1
|
207 'required' => '', |
webmaster@1
|
208 'register' => '', |
webmaster@1
|
209 ); |
webmaster@1
|
210 $form['fields'] = array('#type' => 'fieldset', |
webmaster@1
|
211 '#title' => t('Field settings'), |
webmaster@1
|
212 ); |
webmaster@1
|
213 $form['fields']['category'] = array('#type' => 'textfield', |
webmaster@1
|
214 '#title' => t('Category'), |
webmaster@1
|
215 '#default_value' => $edit['category'], |
webmaster@1
|
216 '#autocomplete_path' => 'admin/user/profile/autocomplete', |
webmaster@1
|
217 '#description' => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'), |
webmaster@1
|
218 '#required' => TRUE, |
webmaster@1
|
219 ); |
webmaster@1
|
220 $form['fields']['title'] = array('#type' => 'textfield', |
webmaster@1
|
221 '#title' => t('Title'), |
webmaster@1
|
222 '#default_value' => $edit['title'], |
webmaster@1
|
223 '#description' => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'), |
webmaster@1
|
224 '#required' => TRUE, |
webmaster@1
|
225 ); |
webmaster@1
|
226 $form['fields']['name'] = array('#type' => 'textfield', |
webmaster@1
|
227 '#title' => t('Form name'), |
webmaster@1
|
228 '#default_value' => $edit['name'], |
webmaster@1
|
229 '#description' => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs. |
webmaster@1
|
230 Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'), |
webmaster@1
|
231 '#required' => TRUE, |
webmaster@1
|
232 ); |
webmaster@1
|
233 $form['fields']['explanation'] = array('#type' => 'textarea', |
webmaster@1
|
234 '#title' => t('Explanation'), |
webmaster@1
|
235 '#default_value' => $edit['explanation'], |
webmaster@1
|
236 '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'), |
webmaster@1
|
237 ); |
webmaster@1
|
238 if ($type == 'selection') { |
webmaster@1
|
239 $form['fields']['options'] = array('#type' => 'textarea', |
webmaster@1
|
240 '#title' => t('Selection options'), |
webmaster@1
|
241 '#default_value' => isset($edit['options']) ? $edit['options'] : '', |
webmaster@1
|
242 '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'), |
webmaster@1
|
243 ); |
webmaster@1
|
244 } |
webmaster@1
|
245 $form['fields']['visibility'] = array('#type' => 'radios', |
webmaster@1
|
246 '#title' => t('Visibility'), |
webmaster@1
|
247 '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC, |
webmaster@1
|
248 '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')), |
webmaster@1
|
249 ); |
webmaster@1
|
250 if ($type == 'selection' || $type == 'list' || $type == 'textfield') { |
webmaster@1
|
251 $form['fields']['page'] = array('#type' => 'textfield', |
webmaster@1
|
252 '#title' => t('Page title'), |
webmaster@1
|
253 '#default_value' => $edit['page'], |
webmaster@1
|
254 '#description' => t('To enable browsing this field by value, enter a title for the resulting page. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". This is only applicable for a public field.'), |
webmaster@1
|
255 ); |
webmaster@1
|
256 } |
webmaster@1
|
257 else if ($type == 'checkbox') { |
webmaster@1
|
258 $form['fields']['page'] = array('#type' => 'textfield', |
webmaster@1
|
259 '#title' => t('Page title'), |
webmaster@1
|
260 '#default_value' => $edit['page'], |
webmaster@1
|
261 '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'), |
webmaster@1
|
262 ); |
webmaster@1
|
263 } |
webmaster@1
|
264 $form['fields']['weight'] = array('#type' => 'weight', |
webmaster@1
|
265 '#title' => t('Weight'), |
webmaster@1
|
266 '#default_value' => $edit['weight'], |
webmaster@1
|
267 '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'), |
webmaster@1
|
268 ); |
webmaster@1
|
269 $form['fields']['autocomplete'] = array('#type' => 'checkbox', |
webmaster@1
|
270 '#title' => t('Form will auto-complete while user is typing.'), |
webmaster@1
|
271 '#default_value' => $edit['autocomplete'], |
webmaster@1
|
272 ); |
webmaster@1
|
273 $form['fields']['required'] = array('#type' => 'checkbox', |
webmaster@1
|
274 '#title' => t('The user must enter a value.'), |
webmaster@1
|
275 '#default_value' => $edit['required'], |
webmaster@1
|
276 ); |
webmaster@1
|
277 $form['fields']['register'] = array('#type' => 'checkbox', |
webmaster@1
|
278 '#title' => t('Visible in user registration form.'), |
webmaster@1
|
279 '#default_value' => $edit['register'], |
webmaster@1
|
280 ); |
webmaster@1
|
281 $form['submit'] = array('#type' => 'submit', |
webmaster@1
|
282 '#value' => t('Save field'), |
webmaster@1
|
283 ); |
webmaster@1
|
284 return $form; |
webmaster@1
|
285 } |
webmaster@1
|
286 |
webmaster@1
|
287 /** |
webmaster@1
|
288 * Validate profile_field_form submissions. |
webmaster@1
|
289 */ |
webmaster@1
|
290 function profile_field_form_validate($form, &$form_state) { |
webmaster@1
|
291 // Validate the 'field name': |
webmaster@1
|
292 if (preg_match('/[^a-zA-Z0-9_-]/', $form_state['values']['name'])) { |
webmaster@1
|
293 form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.')); |
webmaster@1
|
294 } |
webmaster@1
|
295 |
webmaster@1
|
296 if (in_array($form_state['values']['name'], user_fields())) { |
webmaster@1
|
297 form_set_error('name', t('The specified form name is reserved for use by Drupal.')); |
webmaster@1
|
298 } |
webmaster@1
|
299 // Validate the category: |
webmaster@1
|
300 if (!$form_state['values']['category']) { |
webmaster@1
|
301 form_set_error('category', t('You must enter a category.')); |
webmaster@1
|
302 } |
webmaster@1
|
303 if (strtolower($form_state['values']['category']) == 'account') { |
webmaster@1
|
304 form_set_error('category', t('The specified category name is reserved for use by Drupal.')); |
webmaster@1
|
305 } |
webmaster@1
|
306 $args1 = array($form_state['values']['title'], $form_state['values']['category']); |
webmaster@1
|
307 $args2 = array($form_state['values']['name']); |
webmaster@1
|
308 $query_suffix = ''; |
webmaster@1
|
309 |
webmaster@1
|
310 if (isset($form_state['values']['fid'])) { |
webmaster@1
|
311 $args1[] = $args2[] = $form_state['values']['fid']; |
webmaster@1
|
312 $query_suffix = ' AND fid != %d'; |
webmaster@1
|
313 } |
webmaster@1
|
314 |
webmaster@1
|
315 if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'". $query_suffix, $args1))) { |
webmaster@1
|
316 form_set_error('title', t('The specified title is already in use.')); |
webmaster@1
|
317 } |
webmaster@1
|
318 if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'". $query_suffix, $args2))) { |
webmaster@1
|
319 form_set_error('name', t('The specified name is already in use.')); |
webmaster@1
|
320 } |
webmaster@1
|
321 if ($form_state['values']['visibility'] == PROFILE_HIDDEN) { |
webmaster@1
|
322 if ($form_state['values']['required']) { |
webmaster@1
|
323 form_set_error('required', t('A hidden field cannot be required.')); |
webmaster@1
|
324 } |
webmaster@1
|
325 if ($form_state['values']['register']) { |
webmaster@1
|
326 form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.')); |
webmaster@1
|
327 } |
webmaster@1
|
328 } |
webmaster@1
|
329 } |
webmaster@1
|
330 |
webmaster@1
|
331 /** |
webmaster@1
|
332 * Process profile_field_form submissions. |
webmaster@1
|
333 */ |
webmaster@1
|
334 function profile_field_form_submit($form, &$form_state) { |
webmaster@1
|
335 if (!isset($form_state['values']['options'])) { |
webmaster@1
|
336 $form_state['values']['options'] = ''; |
webmaster@1
|
337 } |
webmaster@1
|
338 if (!isset($form_state['values']['page'])) { |
webmaster@1
|
339 $form_state['values']['page'] = ''; |
webmaster@1
|
340 } |
webmaster@1
|
341 if (!isset($form_state['values']['fid'])) { |
webmaster@1
|
342 db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']); |
webmaster@1
|
343 |
webmaster@1
|
344 drupal_set_message(t('The field has been created.')); |
webmaster@1
|
345 watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_state['values']['title'], '%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); |
webmaster@1
|
346 } |
webmaster@1
|
347 else { |
webmaster@1
|
348 db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']); |
webmaster@1
|
349 |
webmaster@1
|
350 drupal_set_message(t('The field has been updated.')); |
webmaster@1
|
351 } |
webmaster@1
|
352 cache_clear_all(); |
webmaster@1
|
353 menu_rebuild(); |
webmaster@1
|
354 |
webmaster@1
|
355 $form_state['redirect'] = 'admin/user/profile'; |
webmaster@1
|
356 return; |
webmaster@1
|
357 } |
webmaster@1
|
358 |
webmaster@1
|
359 /** |
webmaster@1
|
360 * Menu callback; deletes a field from all user profiles. |
webmaster@1
|
361 */ |
webmaster@1
|
362 function profile_field_delete(&$form_state, $fid) { |
webmaster@1
|
363 $field = db_fetch_object(db_query("SELECT title FROM {profile_fields} WHERE fid = %d", $fid)); |
webmaster@1
|
364 if (!$field) { |
webmaster@1
|
365 drupal_not_found(); |
webmaster@1
|
366 return; |
webmaster@1
|
367 } |
webmaster@1
|
368 $form['fid'] = array('#type' => 'value', '#value' => $fid); |
webmaster@1
|
369 $form['title'] = array('#type' => 'value', '#value' => $field->title); |
webmaster@1
|
370 |
webmaster@1
|
371 return confirm_form($form, |
webmaster@1
|
372 t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/user/profile', |
webmaster@1
|
373 t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid))), |
webmaster@1
|
374 t('Delete'), t('Cancel')); |
webmaster@1
|
375 } |
webmaster@1
|
376 |
webmaster@1
|
377 /** |
webmaster@1
|
378 * Process a field delete form submission. |
webmaster@1
|
379 */ |
webmaster@1
|
380 function profile_field_delete_submit($form, &$form_state) { |
webmaster@1
|
381 db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']); |
webmaster@1
|
382 db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']); |
webmaster@1
|
383 |
webmaster@1
|
384 cache_clear_all(); |
webmaster@1
|
385 |
webmaster@1
|
386 drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_state['values']['title']))); |
webmaster@1
|
387 watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); |
webmaster@1
|
388 |
webmaster@1
|
389 $form_state['redirect'] = 'admin/user/profile'; |
webmaster@1
|
390 return; |
webmaster@1
|
391 } |
webmaster@1
|
392 |
webmaster@1
|
393 /** |
webmaster@1
|
394 * Retrieve a pipe delimited string of autocomplete suggestions for profile categories |
webmaster@1
|
395 */ |
webmaster@1
|
396 function profile_admin_settings_autocomplete($string) { |
webmaster@1
|
397 $matches = array(); |
webmaster@1
|
398 $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10); |
webmaster@1
|
399 while ($data = db_fetch_object($result)) { |
webmaster@1
|
400 $matches[$data->category] = check_plain($data->category); |
webmaster@1
|
401 } |
webmaster@1
|
402 print drupal_to_js($matches); |
webmaster@1
|
403 exit(); |
webmaster@1
|
404 } |