You are here

function _imagepicker_browse_admin in Image Picker 5

Same name and namespace in other branches
  1. 5.2 imagepicker.module \_imagepicker_browse_admin()
  2. 6.2 imagepicker.functions.inc \_imagepicker_browse_admin()
  3. 7 imagepicker.functions.inc \_imagepicker_browse_admin()
1 call to _imagepicker_browse_admin()
imagepicker_user_browse_admin in ./imagepicker.module

File

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

Code

function _imagepicker_browse_admin($src = "iframe") {
  global $user;
  $content = "";

  // paths
  if ($src == 'iframe') {
    $editpath = "imagepicker/edit/";
    $deletepath = "imagepicker/delete/";
    $imgpath = 'imagepicker/browse/';
  }
  else {
    $editpath = 'user/' . $user->uid . '/imagepicker/edit/';
    $deletepath = 'user/' . $user->uid . '/imagepicker/delete/';
    $imgpath = 'user/' . $user->uid . '/imagepicker/browse/';
  }

  // if there are groups
  $gid = 0;
  if (imagepicker_get_groups() && imagepicker_has_grouplist()) {

    // add groups select here
    $content .= drupal_get_form('imagepicker_browse_groups_form');
    $gids = imagepicker_get_user_group_state();
    $gid = $gids[0];
  }
  $how_many = variable_get('imagepicker_advanced_browser_page', 25);

  // filter by selected group
  if ($gid) {
    $sql = "SELECT i.img_id, i.uid, i.img_name, i.img_title, i.img_description, i.img_date\n      FROM {imagepicker} i, {imagepicker_group_images} g\n      WHERE i.uid = %d AND i.img_id = g.img_id AND g.gid = %d\n      ORDER BY i.img_id";
    $result = pager_query($sql, $how_many, 0, NULL, array(
      $user->uid,
      $gid,
    ));
  }
  else {
    $sql = "SELECT * FROM {imagepicker} WHERE uid=%d ORDER BY img_id";
    $result = pager_query($sql, $how_many, 0, NULL, array(
      $user->uid,
    ));
  }
  $rows = array();
  while ($row = db_fetch_array($result)) {

    // img_id img_name 	img_title 	img_description
    $img_name = check_plain($row['img_name']);
    $description = check_plain($row['img_description']);
    if (strlen($description) > 30) {
      $description = substr($description, 0, 30) . '...';
    }
    $row_data = array(
      l($img_name, $imgpath . $row['img_id']),
      check_plain($row['img_title']),
      $description,
      check_plain($row['img_date']),
      l(t('Edit'), $editpath . $row['img_id']),
      l(t('Delete'), $deletepath . $row['img_id']),
    );
    $rows[] = $row_data;
  }
  if (count($rows)) {
    $header = array(
      t('Name'),
      t('Title'),
      t('Description'),
      t('Date'),
      array(
        'data' => t('Actions'),
        'colspan' => 2,
      ),
    );
    $content .= '<div class="imgp_imgs_list">';
    $content .= theme('table', $header, $rows) . theme('pager', NULL, $how_many);
    $content .= '</div>';
  }
  else {
    $content = '<div class="messages">' . t('You do not have any uploaded images') . '</div>';
  }
  return $content;
}