commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / cas / cas.pages.inc
1 <?php
2
3 /**
4 * @file
5 * User page callbacks for the cas module.
6 */
7
8 /**
9 * Menu callback; Manage CAS identities for the specified user.
10 */
11 function cas_user_identities($account) {
12 drupal_set_title(check_plain(format_username($account)));
13
14 $header = array(t('CAS username'), t('Operations'));
15 $rows = array();
16 foreach ($account->cas_names as $aid => $cas_name) {
17 $rows[] = array(check_plain($cas_name), l(t('Delete'), 'user/' . $account->uid . '/cas/delete/' . $aid));
18 }
19
20 $build['cas_table'] = array(
21 '#theme' => 'table',
22 '#header' => $header,
23 '#rows' => $rows,
24 );
25 $build['cas_user_add'] = drupal_get_form('cas_user_add', $account);
26
27 return $build;
28 }
29
30 /**
31 * Form builder; Add a CAS identity.
32 *
33 * @ingroup forms
34 * @see cas_user_add_validate()
35 */
36 function cas_user_add($form, &$form_state, $account) {
37 $form['cas_name'] = array(
38 '#type' => 'textfield',
39 '#title' => t('CAS username'),
40 '#element_validate' => array('_cas_name_element_validate'),
41 );
42 $form['actions'] = array('#type' => 'actions');
43 $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add a CAS username'));
44 return $form;
45 }
46
47 function cas_user_add_submit($form, &$form_state) {
48 $query = db_insert('cas_user')
49 ->fields(array(
50 'uid' => $form_state['build_info']['args'][0]->uid,
51 'cas_name' => $form_state['values']['cas_name'],
52 ))
53 ->execute();
54 drupal_set_message(t('CAS username %cas_name added.', array('%cas_name' => $form_state['values']['cas_name'])));
55 }
56
57 /**
58 * Menu callback; Delete the specified CAS username from the system.
59 */
60 function cas_user_delete_form($form, $form_state, $account, $aid = 0) {
61 return confirm_form(array(), t('Are you sure you want to delete the CAS username %cas_name for %user?', array('%cas_name' => $account->cas_names[$aid], '%user' => $account->name)), 'user/' . $account->uid . '/cas');
62 }
63
64 function cas_user_delete_form_submit($form, &$form_state) {
65 $query = db_delete('cas_user')
66 ->condition('uid', $form_state['build_info']['args'][0]->uid)
67 ->condition('aid', $form_state['build_info']['args'][1])
68 ->execute();
69 if ($query) {
70 drupal_set_message(t('CAS username deleted.'));
71 }
72 $form_state['redirect'] = 'user/' . $form_state['build_info']['args'][0]->uid . '/cas';
73 }