You are here

function imagepicker_admin_images in Image Picker 6.2

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

File

./imagepicker.admin.inc, line 1837
admin settings functions

Code

function imagepicker_admin_images() {
  drupal_add_css(IMAGEPICKER_PATH . '/imagepicker.css');
  drupal_add_js(IMAGEPICKER_PATH . '/imagepicker.js');
  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) == 'browse_all' || arg(4) == 'stats' || arg(4) == 'users' || arg(4) == 'list_all') {
    $action = arg(4);
    variable_del('imagepicker_currentuser');
    variable_set('imagepicker_currentgroup', 0);
    $uid = variable_get('imagepicker_currentuser', '');
  }
  $imgaction = '';
  if (arg(6) == 'browse_all' || arg(6) == 'browse' || arg(6) == 'edit' || arg(6) == 'delete' || arg(6) == 'browseadmin' || arg(6) == 'upload' || arg(6) == 'stats' || arg(6) == 'groups' || arg(6) == 'quota') {
    $imgaction = arg(6);
  }
  $img_id = 0;
  if (is_numeric(arg(7))) {
    $img_id = arg(7);
  }
  $content = '';
  if (arg(6) == 'upload') {
    module_load_include('inc', 'imagepicker', 'imagepicker.upload');
    if (variable_get('imagepicker_upload_progress_enabled', 1)) {
      $content .= imagepicker_upload_progress_get_script(variable_get('imagepicker_upload_progress_delay', 0));
    }
  }
  $name = "";
  if ($uid) {
    $account = user_load(array(
      'uid' => $uid,
    ));
    $name = $account->name;
  }
  $content .= drupal_get_form('imagepicker_user_search_form', 'images');
  $content .= '<p>' . t('Managing images for ') . ($name ? l($name, "user/{$uid}") : 'All') . '</p>';
  if ($uid) {
    if ($img_id) {
      if ($imgaction == 'edit') {
        module_load_include('inc', 'imagepicker', 'imagepicker.edit');
        $img = _imagepicker_get_img($img_id, FALSE, $account);
        $imgsrc = imagepicker_get_image_path($img, 'browser', array(
          'uid' => $account->uid,
          'name' => $account->name,
        ));
        $content .= theme('imagepicker_image_edit_header', $img, $imgsrc);
        $content .= drupal_get_form('imagepicker_edit_form', $img, 'admin', $account);
      }
      elseif ($imgaction == 'delete') {
        imagepicker_image_delete($img_id, $account, 'admin');
      }
      else {
        $content .= imagepicker_admin_view($img_id, $account);
      }
    }
    elseif ($imgaction == 'upload') {
      $content .= imagepicker_quota_ok('admin', $account, t('Upload file for %name', array(
        '%name' => $name,
      )));
    }
    elseif ($imgaction == 'stats') {
      $content .= imagepicker_group_stats($account, t('Statistics for %name', array(
        '%name' => $name,
      )));
    }
    elseif ($imgaction == 'browseadmin') {
      $content .= _imagepicker_browse_admin('admin', $account, FALSE, 1, t('List images for %name', array(
        '%name' => $name,
      )));
    }
    elseif ($imgaction == 'quota') {
      $usedbytes = imagepicker_get_all_bytes($account) + 1;
      $usedbytesprint = _imagepicker_bkmg($usedbytes);
      $quota = 0;
      if (variable_get('imagepicker_quota_enable', 1)) {
        if (variable_get('imagepicker_quota_byrole', 0)) {
          $roleid = variable_get('imagepicker_quota_role', 2);
          if (imagepicker_user_has_role($roleid, $account) && $account->uid > 1) {
            $quota = variable_get('imagepicker_quota_default', 0);
          }
        }
        else {
          $quota = isset($account->imagepicker_quota) ? $account->imagepicker_quota : variable_get('imagepicker_quota_default', 0);
        }
      }
      $label = t('Quota for %name', array(
        '%name' => $name,
      ));
      $imgtot = _imagepicker_user_has_img($account);
      $pl = format_plural($imgtot, '1 image', '@count images');
      if ($quota) {
        $pused = round($usedbytes / ($quota * 1000000) * 100, 2);
        $message = t('User %name has used %pused percent or %usedbytesprint of quota %quotaprint and has %pl.', array(
          '%name' => $name,
          '%pused' => $pused,
          '%usedbytesprint' => $usedbytesprint,
          '%pl' => $pl,
          '%quotaprint' => imagepicker_get_quota_list($quota + 1),
        ));
      }
      else {
        $message = t('User %name has used %usedbytesprint and has %pl.', array(
          '%name' => $name,
          '%usedbytesprint' => $usedbytesprint,
          '%pl' => $pl,
        ));
      }
      if (!variable_get('imagepicker_quota_byrole', 0)) {
        $form = drupal_get_form('imagepicker_quota_form', $account);
      }
      else {
        $form = "";
      }
      $content .= theme('imagepicker_quota', $form, $message, $label);
    }
    elseif ($imgaction == 'groups') {
      drupal_goto(IMAGEPICKER_ADMIN_PATH . '/groups/user/' . $uid);
    }
    else {
      $content .= _imagepicker_browse('admin', $account, t('Browse images for %name', array(
        '%name' => $name,
      )));
    }
  }
  else {
    if ($action == 'stats') {
      $content .= imagepicker_group_stats(FALSE, t('Statistics'));
    }
    elseif ($action == 'browse_all') {
      $content .= _imagepicker_browse_public('admin', variable_get('imagepicker_browse_public', 0), t('Browse All Images'));
    }
    elseif ($action == 'list_all') {
      $content .= _imagepicker_browse_admin('admin', FALSE, TRUE, variable_get('imagepicker_browse_public', 0), t('List All Images'));
    }
    else {
      $content .= imagepicker_admin_users_list('images', t('Users'));
    }
  }
  return $content;
}