Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

avatar_selection_edit_form

Definition

avatar_selection_edit_form($form_state)
contributions/avatar_selection/avatar_selection.module, line 750

Description

Create the form structure for listing the avatars and managing them in the 'Manage Avatars' tab under the Avatar Selection administration page.

Parameters

$form_state General variable, used to control the processing of the form.

Return value

Return the structure of the form.

Code

<?php
function avatar_selection_edit_form($form_state) {
  $form = array();

  if (!variable_get('user_pictures', 0)) {
    drupal_set_message(t('User Pictures option is disabled.  You will need to enable this option before you can use the Avatar Selection module.  You may configure this setting on the <a href="@url">User settings</a> page.', array('@url' => url('admin/user/settings'))));
  }

  drupal_add_css(drupal_get_path('module', 'avatar_selection') .'/avatar_selection.css');

  $set_type = arg(4);
  $set_id = arg(5);

  $selects = _avatar_selection_image_list("", $set_type, $set_id);
  if (!count($selects['avatars'])) {
    drupal_set_message(t('There are no avatars configured.'));
  }

  else {

    if (!isset($form_state['values'])) {
      $step = "list";
    }
    else {
      $step = "edit";
    }
    $form['step'] = array(
      '#type' => 'value',
      '#value' => $step,
    );


    if ($step == "list") {

      if ($set_type == 'role') {
        $sets = avatar_selection_handler_filter_role();
      }
      else if ($set_type == 'og') {
        $sets = og_all_groups_options();
      }
      drupal_set_title(t('Manage Avatars - %name', array('%name' => $sets[$set_id])));

      $form['select_avatar'] = array(
        '#type' => 'radios',
        '#title' => t('Select an avatar to edit'),
        '#options' => $selects['avatars'],
        '#required' => TRUE,
        '#attributes' => array('class' => 'user_avatar_select'),
      );

      $form['search'] = array(
        '#type' => 'submit',
        '#value' => t('Edit'),
        '#submit' => array('avatar_selection_edit_list_form_submit'),
      );

      $images_per_page = variable_get('avatar_selection_avatar_per_page', 30);
      $js_settings = array(
        'num_images_per_page' => ($images_per_page ? $images_per_page : 1),
        'num_images' => $selects['total'],
        'image_url' => file_create_url(file_create_path('avatar_selection')),
        'images' => $selects['avatars_indexed'],
      );
      drupal_add_js(array('avatar_selection' => $js_settings), 'setting');
      drupal_add_js(drupal_get_path('module', 'avatar_selection') .'/js/avatar_selection.js', 'module', 'header');

    }
    else if ($step == "edit") {
      drupal_set_title(t('Manage Avatars'));
      $form['#redirect'] = array('admin/settings/avatar_selection/edit');
      $roles = avatar_selection_handler_filter_role();
      $avs_access = $og_access = array();

      $result = db_query("SELECT avatar, access, og_access FROM {avatar_selection} avs WHERE avatar = '%s'", $form_state['values']['select_avatar']);
      while ($avatar = db_fetch_object($result)) {
        $avs_access = preg_split('/\s*,\s*/', $avatar->access);
        $og_access = preg_split('/\s*,\s*/', $avatar->og_access);
      }

      $image_path = file_create_path('avatar_selection');
      $selected_avatar = $form_state['values']['select_avatar'];
      $image = theme('image', $image_path .'/'. $selected_avatar);
      $form['avatar_image'] = array('#value' => $image);
      $form['select_avatar'] = array(
        '#type' => 'value',
        '#value' => $form_state['values']['select_avatar'],
      );

      $form['permissions'] = array(
        '#type' => 'fieldset',
        '#title' => t('Permissions'),
        '#weight' => 1,
      );
      $form['permissions']['access'] = array(
        '#type' => 'checkboxes',
        '#title' => t('User Roles'),
        '#default_value' => $avs_access,
        '#options' => $roles,
        '#description' => t('Only the checked roles will be able to see this avatar icon; if no roles are checked, access will not be restricted.'),
      );

      if (module_exists("og")) {
        $form['permissions']['og_access'] = array(
          '#type' => 'checkboxes',
          '#title' => t('Organic Groups'),
          '#default_value' => $og_access,
          '#options' => og_all_groups_options(),
          '#description' => t('Only users in the checked organic groups will be able to see this avatar icon; if no groups are checked, access will not be restricted.'),
        );
      }

      $form['update'] = array(
        '#type' => 'submit',
        '#value' => t('Update'),
        '#weight' => 9,
        '#submit' => array('avatar_selection_edit_update_form_submit'),
      );
      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delete'),
        '#weight' => 10,
        '#submit' => array('avatar_selection_edit_delete_form_submit'),
      );
    }

  }

  return $form;
}
?>