You are here

function _gallery_assist_form in Gallery Assist 6

Build the form section for upload- and items-administration.

3 calls to _gallery_assist_form()
gallery_assist_ui_ga_items_form in modules/gallery_assist_ui/gallery_assist_ui.module
gallery_assist_upload_js in ./gallery_assist.module
Upload callback over ahah. Prepare the data for save and rebuild the form.
_get_ga_form in ./gallery_assist.module

File

./gallery_assist.module, line 1142
Drupal content type with gallery functionality.

Code

function _gallery_assist_form(&$node) {
  global $user;
  $form = array(
    '#theme' => 'gallery_assist_form_new',
    '#cache' => TRUE,
    '#weight' => 0,
  );
  if (!empty($node->gallitems) && is_array($node->gallitems)) {
    drupal_add_js(drupal_get_path('module', 'gallery_assist') . '/js/gallery_assist.js', 'module', 'footer');
    $form['gallery_items']['#theme'] = 'gallery_assist_form_current';
    $form['gallery_items']['#tree'] = TRUE;
    foreach ($node->gallitems as $key => $item) {
      $item = (object) $item;

      // Visualize the item image in the form
      $img = image_get_info($item->thmb_path);
      $top = $img['height'] < 80 ? (80 - $img['height']) / 2 : 0;
      $mtop = $img['width'] > $img['height'] ? 'margin-top:' . $top . 'px;' : '';
      $item_attr = array(
        'style' => 'margin:0;padding:0;border:0;' . $mtop,
      );
      if (function_exists('imagecache_preset') && $node->gallconf[$node->type]['use_imagecache'] == 1) {
        $ic = gallery_assist_get_preset_more_info($node->gallconf[$node->type]['thm_presetid']);
        $item->image = theme('imagecache', $node->gallconf[$node->type]['thm_presetname'], $item->opath, $item->palt, $item->ptitle, $item_attr, FALSE);
      }
      else {
        $direction = $img['width'] >= $img['height'] ? 'width' : 'height';
        $item->image = theme('image', file_create_url($item->thmb_path), $item->palt, $item->ptitle, $item_attr, FALSE);
      }
      $item->image_link = '<div class="thmb_form_image" style="width:80px;max-width:80px;height:80px;max-height:80px;margin-left:10px;overflow:hidden;">' . l($item->image, 'node/' . $node->nid . '/' . $item->pid, array(
        'html' => TRUE,
      )) . '</div>';
      $jump_link_text = t('Jump to update-bottom to save the changes');
      $changes_warning_text = t('Changes made in this table will be saved by click Update.');

      // Item form.
      $form['gallery_items'][$key]['remove'] = array(
        '#type' => 'checkbox',
        '#default_value' => !empty($item->remove),
      );
      $form['gallery_items'][$key]['item'] = array(
        '#value' => $item->image_link,
      );
      $form['gallery_items'][$key]['ptitle'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#value' => $item->ptitle,
        '#prefix' => '<a name="' . $item->pid . '"></a>',
        '#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-ptitle" style="display:none;" class="warning"><span class="warning">*</span> Changes made in this table will be saved by click Update.</div>',
      );

      //
      $form['gallery_items'][$key]['copyright'] = array(
        '#type' => 'textfield',
        '#title' => t('Copyright'),
        '#size' => '50%',
        '#value' => $item->copyright,
        '#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-copyright" style="display:none;" class="warning"><span class="warning">*</span> Changes made in this table will be saved by click Update.</div>',
      );

      //
      $form['gallery_items'][$key]['pdescription'] = array(
        '#type' => 'textarea',
        '#rows' => 2,
        '#title' => t('Caption'),
        '#value' => $item->pdescription,
        '#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-pdescription" style="display:none;" class="warning"><span class="warning">*</span> ' . $changes_warning_text . '</div><div id="jump-to-update-link" class="jump-to-update-link">' . l($jump_link_text, 'node/' . $item->nid . '/edit', array(
          'fragment' => 'update-buttom',
        )) . '</div>',
      );

      //
      if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
        $form['gallery_items'][$key]['weight'] = array(
          '#type' => 'weight',
          '#delta' => count($node->gallitems),
          '#default_value' => $item->weight,
        );
      }
      else {
        $form['gallery_items'][$key]['weight'] = array(
          '#type' => 'textfield',
          '#default_value' => $item->weight,
        );
      }
      $form['gallery_items'][$key]['pid'] = array(
        '#type' => 'value',
        '#value' => $item->pid,
      );
      $form['gallery_items'][$key]['cover'] = array(
        '#type' => 'hidden',
        '#value' => $item->cover,
      );
      $form['gallery_items'][$key]['gid'] = array(
        '#type' => 'hidden',
        '#value' => $item->gid,
      );
      $form['gallery_items'][$key]['new'] = array(
        '#type' => 'value',
        '#value' => FALSE,
      );
      $form['gallery_items'][$key]['did'] = array(
        '#type' => 'value',
        '#value' => $item->did,
      );
      $form['gallery_items'][$key]['lang'] = array(
        '#type' => 'hidden',
        '#value' => $node->lang ? $node->lang : $node->language,
      );
      $form['gallery_items'][$key]['aid'] = array(
        '#type' => 'hidden',
        '#value' => $item->aid,
      );
    }
  }
  $formats = explode(' ', $node->gallconf[$node->type]['extensions']);
  $desc = t('Permitted formats: @formats. ', array(
    '@formats' => implode(', ', $formats),
  ));
  $pager_limit = variable_get('gallery_assist_editform_pager_limit', 25);
  $form['new']['pager_bottom'] = array(
    '#type' => 'markup',
    '#value' => theme('pager', NULL, $pager_limit, 0, NULL, 5),
    '#weight' => 19,
  );
  $count = $node->gallconf[$node->type]['ga_counter'];
  $limit = $node->gallconf[$node->type]['max_form_items'];
  if (empty($node->gallconf[$node->type]['max_items'])) {
    $display_field = TRUE;
  }
  elseif ($node->gallconf[$node->type]['max_items'] > $count) {
    $diff = $node->gallconf[$node->type]['max_items'] - $count;
    $display_field = TRUE;
    if ($diff >= $limit) {
      $limit = $limit;
    }
    else {
      $limit = $diff;
    }
  }
  else {
    $display_field = FALSE;
    $limit_message = t('<div id="ga-amount-achaived" class="message warning">' . t('The maximum allowed number of uploads (@max-amount) was achieved.', array(
      '@max-amount' => $node->gallconf[$node->type]['max_items'],
    )) . '</div>');
  }
  if ($node->gallconf[$node->type]['user_size'] > 0) {
    $used_space = file_space_used($node->uid);
    if ($used_space >= $node->gallconf[$node->type]['user_size']) {
      $display_field = FALSE;
      $limit_message = t('<div id="ga-amount-achaived" class="message warning">' . t('Your disk quota of @quota KB was achieved.', array(
        '@quota' => $node->gallconf[$node->type]['user_size'],
      )) . '</div>');
    }
  }
  if ($display_field) {
    for ($i = 0; $i < $limit; ++$i) {
      $form['new']['pictures' . $i] = array(
        '#type' => 'file',
        '#title' => t('Add new item'),
        '#size' => 40,
        '#description' => $desc,
        '#weight' => 20,
      );
    }
    $help = array(
      'module' => 'gallery_assist',
      'help_link' => 'add-and-edit-gallery-items',
      'text' => t('Enter here the copyright in case all pictures you will just upload and all should having the same copyright.'),
    );
    $form['new']['temp_copyright'] = array(
      '#type' => 'textfield',
      '#title' => t('Copyright'),
      '#size' => 19,
      '#default_value' => $node->temp_copyright,
      '#description' => gallery_assist_advanced_help_builder($help),
      '#weight' => 22,
    );
  }
  else {
    $form['new']['pictures' . $i] = array(
      '#type' => 'markup',
      '#value' => $limit_message,
      '#weight' => 22,
    );
  }
  $form['new']['get_pager_value'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['page'],
  );
  $form['new']['picsubmit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#name' => 'picsubmit',
    '#ahah' => array(
      'path' => $node->type == 'gallery_assist' ? 'gallery_assist_upload/js' : 'gallery_assist_' . $node->type . '_upload/js',
      'wrapper' => 'gallery-assist-list-wrapper',
      'progress' => array(
        'type' => 'bar',
        'message' => t('Please wait...'),
      ),
    ),
    '#submit' => array(
      'node_form_submit_build_node',
    ),
    '#prefix' => '<a name="update-buttom"></a>',
    '#weight' => 24,
  );
  unset($node->check_all_links);
  return $form;
}