You are here

function mobile_tools_roles_configuration_form in Mobile Tools 6.2

Same name and namespace in other branches
  1. 5 mobile_tools.module \mobile_tools_roles_configuration_form()
  2. 6.3 mobile_tools_roles.admin.inc \mobile_tools_roles_configuration_form()
  3. 6 mobile_tools_roles.inc \mobile_tools_roles_configuration_form()
  4. 7.2 mobile_tools_roles/mobile_tools_roles.module \mobile_tools_roles_configuration_form()
  5. 7.2 mobile_tools_roles/mobile_tools_roles.inc \mobile_tools_roles_configuration_form()

Configuration form for creating mobile user roles.

1 string reference to 'mobile_tools_roles_configuration_form'
mobile_tools_roles_menu in modules/mobile_tools_roles/mobile_tools_roles.module
Implementation of hook_menu().

File

modules/mobile_tools_roles/mobile_tools_roles.admin.inc, line 10
Generate configuration form and save settings.

Code

function mobile_tools_roles_configuration_form() {
  $form['mobile_tools_roles_configuration'] = array(
    '#type' => 'fieldset',
    '#title' => t('Mobile roles configuration'),
    '#collapsible' => TRUE,
    '#description' => t('Mobile Tools Roles provides the ability to create mobile versions of existing user roles. Mobile roles only apply to site visitors who are using a mobile device and take the place of normal site roles. Permissions for mobile roles can be set on the <a href="@permissions">permissions</a> page.', array(
      '@permissions' => '/admin/user/permissions',
    )),
  );
  $form['mobile_tools_roles_configuration']['mobile_tools_enable_roles'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable mobile user roles'),
    '#default_value' => variable_get('mobile_tools_enable_roles', 0),
    '#description' => t('When activated, site visitors will get the mobile versions of their normal roles when the site is being mobilized.'),
  );
  if (variable_get('mobile_tools_enable_roles', 0)) {
    $form['mobile_tools_roles'] = array(
      '#type' => 'fieldset',
      '#title' => t('Mobile roles'),
      '#collapsible' => TRUE,
      '#tree' => TRUE,
      '#description' => t('Enable or disable the mobile version of each user role. When no mobile role is created, the user will keep its normal role. The settings can also be configured in the !roles configuration section.', array(
        '!roles' => l('roles', 'admin/user/roles'),
      )),
    );

    // Build a query to select all current roles and role names
    $query = "SELECT r.rid, r.name FROM {role} r";

    // Execute the query
    $result = db_query($query);

    // Get the current Mobile Tools Roles setting
    $roles = variable_get('mobile_tools_roles', array());

    // Process all of the currently available roles
    while ($role = db_fetch_object($result)) {

      // Build a query to count the current number of Mobile Tools Roles relations
      $query = "SELECT COUNT(*) as count FROM {mobile_tools_roles_relations} WHERE mrid = %d";

      // Execute the query
      $count = db_result(db_query($query, $role->rid));

      // Display a checkbox to create a mobile version of each non-mobile role
      if ($count == 0) {
        $form['mobile_tools_roles'][$role->rid] = array(
          '#type' => 'checkbox',
          '#title' => $role->name,
          '#default_value' => isset($roles[$role->rid]) ? $roles[$role->rid] : 0,
          '#description' => t('Enable to create the %role role.', array(
            '%role' => $role->name . ' (Mobile)',
          )),
        );
      }
    }
    $form['mobile_tools_roles']['mobile_tools_roles_overview'] = array(
      '#value' => _mobile_tools_roles_overview(),
    );
  }

  // Add a submit function
  $form['#submit'][] = 'mobile_tools_roles_configuration_form_submit';
  return system_settings_form($form);
}