You are here

function img_assist_header_form in Image Assist 6.2

Same name and namespace in other branches
  1. 5.3 img_assist.module \img_assist_header_form()
  2. 5 img_assist.module \img_assist_header_form()
  3. 5.2 img_assist.module \img_assist_header_form()
  4. 6 img_assist.module \img_assist_header_form()

Related topics

1 string reference to 'img_assist_header_form'
img_assist_header in ./img_assist.module

File

./img_assist.module, line 634
Image Assist module

Code

function img_assist_header_form(&$form_state, $mode) {
  global $user;

  // Upload image.
  if ($mode == 'uploading') {
    $form[] = array(
      '#value' => '<div id="header-uploading">',
    );
    $form[] = array(
      '#value' => '<strong>' . t('Upload: ') . '</strong>' . t('Fill in the form below to upload a new image.'),
    );
    $form[] = array(
      '#value' => '</div><div id="header-startover">',
    );
    $form['startover'] = array(
      '#type' => 'button',
      '#value' => t('Start Over'),
      '#button_type' => 'button',
      '#attributes' => array(
        'onclick' => 'parent.onClickStartOver();',
      ),
    );
    $form[] = array(
      '#value' => '</div>',
    );
  }
  elseif ($mode == 'properties') {
    $form[] = array(
      '#value' => '<div id="header-properties">',
    );
    $form[] = array(
      '#value' => '<strong>' . t('Properties: ') . '</strong>' . t('Change how the image is displayed.'),
    );
    $form[] = array(
      '#value' => '</div><div id="header-startover">',
    );
    $form['startover'] = array(
      '#type' => 'button',
      '#value' => t('Start Over'),
      '#button_type' => 'button',
      '#attributes' => array(
        'onclick' => 'parent.onClickStartOver()',
      ),
    );
    $form[] = array(
      '#value' => '</div>',
    );
  }
  else {
    $form[] = array(
      '#value' => '<div id="header-browse">',
    );
    $form[] = array(
      '#value' => '<strong>' . t('Browse Images: ') . '</strong>',
    );
    $views = variable_get('img_assist_views', drupal_map_assoc(array(
      'img_assist_browser',
    )));
    foreach ($views as $view_name => $view_title) {
      if ($view_name == 'img_assist_browser') {

        // @todo execute() performs a full query, we just need the count here.
        // Get my images and count.
        $myimages = views_get_view('img_assist_browser');
        $myimages
          ->set_arguments(array(
          $user->uid,
        ));
        $myimages->get_total_rows = TRUE;

        // Required for overridden default view.
        $myimages
          ->execute();
        $options['img_assist_browser/' . $user->uid] = t('My Images') . " ({$myimages->total_rows})";

        // Get all images and count.
        if (user_access('access all images')) {
          $allimages = views_get_view('img_assist_browser');
          $allimages
            ->set_arguments(array(
            'all',
          ));
          $allimages->get_total_rows = TRUE;

          // Required for overridden default view.
          $allimages
            ->execute();
          $options['img_assist_browser/all'] = t('All Images') . " ({$allimages->total_rows})";
        }

        // Get category list.
        if (module_exists('taxonomy') && ($vocabs = variable_get('img_assist_vocabs', array()))) {
          $term_counts = _img_assist_term_count_nodes($vocabs);

          // Get all images or only user's images depending on permissions.
          $user_arg = user_access('access all images') ? 'all' : $user->uid;
          foreach ($vocabs as $vid) {
            $vocab = taxonomy_vocabulary_load($vid);
            $terms = taxonomy_get_tree($vid);
            if ($terms) {
              foreach ($terms as $key => $value) {
                $tid = $value->tid;
                $name = $value->name;
                $count = isset($term_counts[$tid]) ? $term_counts[$tid] : 0;
                $options[$vocab->name]["img_assist_browser/{$user_arg}/" . $tid] = "{$name} ({$count})";
              }
            }
          }
        }
      }
      else {
        $view = views_get_view($view_name);
        $view
          ->execute();
        $view_title = $view
          ->get_title() == '' ? $view_name : $view
          ->get_title();
        $options[$view_name] = "{$view_title} ({$view->total_rows})";
      }
    }
    $form['browse'] = array(
      '#type' => 'select',
      '#default_value' => 'img_assist_browser/' . $user->uid,
      '#options' => $options,
      '#attributes' => array(
        'onchange' => 'parent.onChangeBrowseBy(this)',
      ),
    );
    if (user_access('create images')) {
      $form['upload'] = array(
        '#type' => 'button',
        '#prefix' => ' ' . t('or') . ' ',
        '#value' => t('Upload'),
        '#suffix' => ' ' . t('a new image'),
        '#button_type' => 'button',
        '#attributes' => array(
          'onclick' => 'parent.onClickUpload()',
        ),
      );
    }
    $form[] = array(
      '#value' => '</div><div id="header-cancel">',
    );
    $form['cancel'] = array(
      '#type' => 'button',
      '#value' => t('Cancel'),
      '#button_type' => 'button',
      '#attributes' => array(
        'onclick' => 'parent.cancelAction()',
      ),
    );
    $form[] = array(
      '#value' => '</div>',
    );
  }
  return $form;
}