You are here

function imagepicker_admin_groups in Image Picker 5.2

Same name and namespace in other branches
  1. 6.2 imagepicker.admin.inc \imagepicker_admin_groups()
  2. 7 imagepicker.admin.inc \imagepicker_admin_groups()
1 string reference to 'imagepicker_admin_groups'
imagepicker_menu in ./imagepicker.module
Implementation of hook_menu().

File

./imagepicker.module, line 1661
Enables permitted roles to upload images for insertion into configured nodes.

Code

function imagepicker_admin_groups() {
  drupal_add_css(drupal_get_path('module', 'imagepicker') . '/imagepicker.css');
  if (!arg(4)) {
    variable_del('imagepicker_currentuser');
    variable_set('imagepicker_currentgroup', 0);
    $action = 'users';
  }
  $uid = variable_get('imagepicker_currentuser', '');
  if (arg(4) == 'user' && is_numeric(arg(5))) {
    $uid = arg(5);
  }
  elseif (arg(4) == 'stats' || arg(4) == 'users') {
    $action = arg(4);
  }
  if ((arg(6) == 'browse' || arg(6) == 'edit' || arg(6) == 'delete') && is_numeric(arg(7))) {
    $gidaction = arg(6);
    $gid = arg(7);
    if (arg(6) == 'browse') {
      variable_set('imagepicker_currentgroup', $gid);
      drupal_goto('admin/settings/imagepicker/images/user/' . $uid . '/browse');
    }
  }
  $name = "";
  if ($uid) {
    $user = user_load(array(
      'uid' => $uid,
    ));
    $result = db_query("SELECT u.name FROM {users} u, {imagepicker} i WHERE u.uid = %d AND u.uid=i.uid", $uid);
    $row = db_fetch_array($result);
    $name = $row['name'];
    $menu = array(
      l(t('All groups'), 'admin/settings/imagepicker/groups'),
      l(t('Groups'), 'admin/settings/imagepicker/groups/user/' . $uid),
      l(t('Images'), 'admin/settings/imagepicker/images/user/' . $uid . '/browse'),
      l(t('Stats'), 'admin/settings/imagepicker/groups/user/' . $uid . '/stats'),
    );
  }
  elseif ($action) {
    $menu = array(
      l(t('Groups'), 'admin/settings/imagepicker/groups/users'),
      l(t('Stats'), 'admin/settings/imagepicker/groups/stats'),
    );
  }
  $content .= drupal_get_form('imagepicker_group_search_form');
  $content .= '<p>' . t('Managing groups for ') . ($name ? l($name, "user/{$uid}") : 'All') . '</p>';
  if (is_array($menu)) {
    $content .= theme_item_list($menu, NULL, 'ul', $attributes = array(
      'class' => 'tabs secondary',
    ));
  }
  if ($uid) {

    // show groups for $uid
    if ($gid) {
      if ($gidaction == 'edit') {
        $record = imagepicker_get_user_group($gid);
        $content .= drupal_get_form('imagepicker_groups_form', $record);
      }
      elseif ($gidaction == 'delete') {
        $content .= drupal_get_form('imagepicker_group_delete_form', $gid);
      }
    }
    elseif (arg(6) == 'stats') {
      $content .= "<fieldset><legend>" . t('Statistics for %name', array(
        '%name' => $name,
      )) . "</legend>";
      $content .= imagepicker_group_stats($user);
      $content .= '</fieldset>';
    }
    else {
      $content .= "<fieldset><legend>" . t('Groups for %name', array(
        '%name' => $name,
      )) . "</legend>";
      $content .= imagepicker_groups_list('admin', $user);
      $content .= '</fieldset>';
      $content .= drupal_get_form('imagepicker_groups_form', 0, $user);
    }
  }
  else {
    if ($action == 'stats') {
      $content .= '<fieldset><legend>' . t('Statistics') . '</legend>';
      $content .= imagepicker_group_stats();
      $content .= '</fieldset>';
    }
    else {
      $content .= '<fieldset><legend>' . t('Groups') . '</legend>';
      $content .= imagepicker_admin_groups_list('groups');
      $content .= '</fieldset>';
    }
  }
  return $content;
}