mb_user.admin.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /*
  3. * @file
  4. * Function file to administer the MB User module settings.
  5. */
  6. /**
  7. * Provides the MB User settings form.
  8. */
  9. function mb_user_admin() {
  10. $module = 'mb_user';
  11. $mb_user_mappings = mb_get_mappings($module);
  12. $mb_user_values = mb_get_values($module);
  13. $form['#mappings'] = $mb_user_mappings;
  14. foreach ($mb_user_mappings as $type => $v) {
  15. // Provide "Cancel" button settings.
  16. $form[$module][$type][$module . '_cancel_' . $type] = array(
  17. '#type' => 'select',
  18. '#options' => mb_cancel_button_positions(),
  19. '#default_value' => variable_get($module . '_cancel_' . $type, 0),
  20. );
  21. // Provide "Save and continue" button settings.
  22. $form[$module][$type][$module . '_sac_' . $type] = array(
  23. '#type' => 'select',
  24. '#options' => mb_save_button_positions($module),
  25. '#default_value' => variable_get($module . '_sac_' . $type, 0)
  26. );
  27. // Provide "Save and create new" button settings.
  28. $form[$module][$type][$module . '_sacn_' . $type] = array(
  29. '#type' => 'select',
  30. '#options' => mb_save_button_positions($module),
  31. '#default_value' => variable_get($module . '_sacn_' . $type, 0)
  32. );
  33. }
  34. $form['submit']['save'] = array(
  35. '#type' => 'submit',
  36. '#name' => 'save',
  37. '#value' => t('Save')
  38. );
  39. $form['submit']['reset'] = array(
  40. '#type' => 'submit',
  41. '#name' => 'reset',
  42. '#value' => t('Reset to defaults'),
  43. );
  44. return $form;
  45. }
  46. /**
  47. * Display the MB User settings form page.
  48. *
  49. * @return
  50. * The complete HTML formatted administer page.
  51. */
  52. function theme_mb_user_admin($variables) {
  53. _mb_load_css('admin');
  54. $module = 'mb_user';
  55. $mappings = array();
  56. $output = '';
  57. $extra_info = '';
  58. $rows = array();
  59. $form = drupal_get_form($module . '_admin');
  60. $mappings = $form['#mappings'];
  61. $output = '<h3>' . t('User settings') . '</h3>';
  62. $output .= '<p>' . t('Which %module functions are used by different user pages.', array('%module' => t('More Buttons User'))) . '</p>';
  63. $header = array(t('Cancel'), t('Save and continue'), t('Save and create new'));
  64. $i = 1;
  65. foreach ($mappings as $type => $maps) {
  66. // Provide own odd/even functionality.
  67. $evenodd = $i % 2 ? 'odd-mb' : 'even-mb';
  68. $evenodd = $i & 1 ? 'odd-mb' : 'even-mb';
  69. $rows[] = array('data' => array($maps['name'], array('colspan' => 2)), 'class' => array($evenodd . ' ' . $evenodd . '-type'));
  70. // The row contains the form elements.
  71. $rows[] = array(
  72. 'data' => array(
  73. drupal_render($form[$module][$type][$module . '_cancel_' . $type]),
  74. drupal_render($form[$module][$type][$module . '_sac_' . $type]),
  75. drupal_render($form[$module][$type][$module . '_sacn_' . $type])
  76. ),
  77. 'class' => array($evenodd . ' ' . $evenodd . '-elements')
  78. );
  79. unset($form[$module][$type]);
  80. ++$i;
  81. }
  82. $output .= theme('table', array(
  83. 'header' => $header,
  84. 'rows' => $rows,
  85. 'attributes' => array('class' => array('mb-admin-table', $module . '-admin-table'))
  86. ));
  87. // Display additional informations.
  88. if ($extra_info != '') {
  89. $output .= $extra_info;
  90. }
  91. $output .= drupal_render($output);
  92. $output .= drupal_render_children($form);
  93. $output .= '<p style="text-align: right">' . t('Module development by <a href="@development-url">Quiptime Group</a>.', array('@development-url' => url('http://www.quiptime.com'))) . '</p>';
  94. return $output;
  95. }
  96. /**
  97. * Save settings from admin form.
  98. */
  99. function mb_user_admin_submit($form, &$form_state) {
  100. $module = 'mb_user';
  101. $mappings = $form['#mappings'];
  102. if ($form_state['clicked_button']['#id'] == 'edit-save') {
  103. // Save the MB User button settings.
  104. foreach ($mappings as $type => $maps) {
  105. variable_set($module . '_cancel_' . $type, $form_state['values'][$module . '_cancel_' . $type]);
  106. variable_set($module . '_sac_' . $type, $form_state['values'][$module . '_sac_' . $type]);
  107. variable_set($module . '_sacn_' . $type, $form_state['values'][$module . '_sacn_' . $type]);
  108. }
  109. drupal_set_message(t('Your changes have been saved.'), 'status');
  110. }
  111. elseif ($form_state['clicked_button']['#id'] == 'edit-reset') {
  112. $form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-user/reset';
  113. }
  114. }
  115. /**
  116. * Menu callback to define the confirm form output.
  117. *
  118. * @return
  119. * The confirm form.
  120. */
  121. function mb_user_reset() {
  122. $question = t('Are you sure you want to reset all %module settings?', array('%module' => t('More Buttons User')));
  123. $information = '<p>' . t('This action disables the settings for all buttons. This action cannot be undone.') . '</p>';
  124. return confirm_form(array(),
  125. $question,
  126. array('path' => 'admin/config/mb/buttons/more-buttons-user', 'attributes' => array('class' => 'button')), $information,
  127. t('Reset'),
  128. t('Cancel')
  129. );
  130. }
  131. /**
  132. * Resave all system variables of the MB User module to reset the module settings.
  133. */
  134. function mb_user_reset_submit($form, &$form_state) {
  135. // Resave variables.
  136. $page_types = array_keys(mb_user_type_get_types());
  137. foreach ($page_types as $type) {
  138. variable_set('mb_user_cancel_' . $type, 0);
  139. variable_set('mb_user_sac_' . $type, 0);
  140. variable_set('mb_user_sacn_' . $type, 0);
  141. }
  142. drupal_set_message(t('The %module settings have been set back.', array('%module' => t('More Buttons User'))), 'status');
  143. watchdog('More Buttons User', 'The %module settings have been set back.', array('%module' => t('More Buttons User')), WATCHDOG_NOTICE, l(t('view'), 'admin/config/mb/buttons/more-buttons-user'));
  144. $form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-user';
  145. }