Mercurial > defr > drupal > core
comparison modules/user/user.admin.inc @ 9:acef7ccb09b5 6.4
Drupal 6.4
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:32:08 +0100 |
parents | c1f4ac30525a |
children |
comparison
equal
deleted
inserted
replaced
8:85cbd6048071 | 9:acef7ccb09b5 |
---|---|
1 <?php | 1 <?php |
2 // $Id: user.admin.inc,v 1.18 2008/01/16 22:54:41 goba Exp $ | 2 // $Id: user.admin.inc,v 1.18.2.1 2008/08/13 23:59:14 drumm Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * Admin page callback file for the user module. | 6 * Admin page callback file for the user module. |
7 */ | 7 */ |
705 $output .= drupal_get_form('user_admin_check_host'); | 705 $output .= drupal_get_form('user_admin_check_host'); |
706 return $output; | 706 return $output; |
707 } | 707 } |
708 | 708 |
709 /** | 709 /** |
710 * Menu callback: add an access rule | 710 * Menu callback: add an access rule. |
711 */ | 711 */ |
712 function user_admin_access_add($mask = NULL, $type = NULL) { | 712 function user_admin_access_add($mask = NULL, $type = NULL) { |
713 if ($edit = $_POST) { | 713 $edit = array(); |
714 if (!$edit['mask']) { | 714 $edit['aid'] = 0; |
715 form_set_error('mask', t('You must enter a mask.')); | 715 $edit['mask'] = $mask; |
716 } | 716 $edit['type'] = $type; |
717 else { | |
718 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit['mask'], $edit['type'], $edit['status']); | |
719 $aid = db_last_insert_id('access', 'aid'); | |
720 drupal_set_message(t('The access rule has been added.')); | |
721 drupal_goto('admin/user/rules'); | |
722 } | |
723 } | |
724 else { | |
725 $edit['mask'] = $mask; | |
726 $edit['type'] = $type; | |
727 } | |
728 return drupal_get_form('user_admin_access_add_form', $edit, t('Add rule')); | 717 return drupal_get_form('user_admin_access_add_form', $edit, t('Add rule')); |
729 } | 718 } |
730 | 719 |
731 /** | 720 /** |
732 * Menu callback: edit an access rule | 721 * Menu callback: edit an access rule. |
733 */ | 722 */ |
734 function user_admin_access_edit($aid = 0) { | 723 function user_admin_access_edit($aid = 0) { |
735 if ($edit = $_POST) { | 724 $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); |
736 if (!$edit['mask']) { | |
737 form_set_error('mask', t('You must enter a mask.')); | |
738 } | |
739 else { | |
740 db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid); | |
741 drupal_set_message(t('The access rule has been saved.')); | |
742 drupal_goto('admin/user/rules'); | |
743 } | |
744 } | |
745 else { | |
746 $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); | |
747 } | |
748 return drupal_get_form('user_admin_access_edit_form', $edit, t('Save rule')); | 725 return drupal_get_form('user_admin_access_edit_form', $edit, t('Save rule')); |
749 } | 726 } |
750 | 727 |
751 /** | 728 /** |
752 * Form builder; Configure access rules. | 729 * Form builder; Configure access rules. |
753 * | 730 * |
754 * @ingroup forms | 731 * @ingroup forms |
755 */ | 732 */ |
756 function user_admin_access_form(&$form_state, $edit, $submit) { | 733 function user_admin_access_form(&$form_state, $edit, $submit) { |
734 $form = array(); | |
735 $form['aid'] = array( | |
736 '#type' => 'value', | |
737 '#value' => $edit['aid'], | |
738 ); | |
757 $form['status'] = array( | 739 $form['status'] = array( |
758 '#type' => 'radios', | 740 '#type' => 'radios', |
759 '#title' => t('Access type'), | 741 '#title' => t('Access type'), |
760 '#default_value' => isset($edit['status']) ? $edit['status'] : 0, | 742 '#default_value' => isset($edit['status']) ? $edit['status'] : 0, |
761 '#options' => array('1' => t('Allow'), '0' => t('Deny')), | 743 '#options' => array('1' => t('Allow'), '0' => t('Deny')), |
775 '#default_value' => $edit['mask'], | 757 '#default_value' => $edit['mask'], |
776 '#description' => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), | 758 '#description' => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), |
777 '#required' => TRUE, | 759 '#required' => TRUE, |
778 ); | 760 ); |
779 $form['submit'] = array('#type' => 'submit', '#value' => $submit); | 761 $form['submit'] = array('#type' => 'submit', '#value' => $submit); |
762 $form['#submit'] = array('user_admin_access_form_submit'); | |
780 | 763 |
781 return $form; | 764 return $form; |
765 } | |
766 | |
767 /** | |
768 * Submit callback for user_admin_access_form(). | |
769 */ | |
770 function user_admin_access_form_submit($form, &$form_state) { | |
771 $edit = $form_state['values']; | |
772 if ($edit['aid']) { | |
773 db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $edit['aid']); | |
774 drupal_set_message(t('The access rule has been saved.')); | |
775 } | |
776 else { | |
777 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit['mask'], $edit['type'], $edit['status']); | |
778 drupal_set_message(t('The access rule has been added.')); | |
779 } | |
780 $form_state['redirect'] = 'admin/user/rules'; | |
782 } | 781 } |
783 | 782 |
784 function user_admin_access_check_validate($form, &$form_state) { | 783 function user_admin_access_check_validate($form, &$form_state) { |
785 if (empty($form_state['values']['test'])) { | 784 if (empty($form_state['values']['test'])) { |
786 form_set_error($form_state['values']['type'], t('No value entered. Please enter a test string and try again.')); | 785 form_set_error($form_state['values']['type'], t('No value entered. Please enter a test string and try again.')); |