You are here

function imce_profile_form in IMCE 7

Same name and namespace in other branches
  1. 6.2 inc/imce.admin.inc \imce_profile_form()
  2. 6 inc/admin.inc \imce_profile_form()

Profile form.

1 string reference to 'imce_profile_form'
imce_profile_operations in inc/imce.admin.inc
Add-Edit-Delete profiles.

File

inc/imce.admin.inc, line 267
Serves administration pages of IMCE.

Code

function imce_profile_form($form, &$form_state, $pid = 0) {
  if ($pid && ($profile = imce_load_profile($pid))) {
    drupal_set_title($profile['name']);
  }
  else {
    $pid = 0;
    $profile = imce_sample_profile();
    $profile['name'] = '';
  }

  // Import profile.
  if (isset($_GET['import']) && ($imported = imce_load_profile($_GET['import']))) {
    if (empty($form_state['post'])) {
      drupal_set_message(t('Settings were imported from the profile %name', array(
        '%name' => $imported['name'],
      )));
    }

    // Preserve the original name.
    $imported['name'] = $profile['name'];
    $profile = $imported;
  }

  // Store the original profile just in case.
  $form_state['profile'] = $profile;
  $form = array(
    '#tree' => TRUE,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile name'),
    '#default_value' => $profile['name'],
    '#description' => t('Give a name to this profile.'),
    '#required' => TRUE,
  );
  $form['import'] = array(
    '#markup' => imce_profile_import_html($pid),
  );
  $form['usertab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display file browser tab in user profile pages.'),
    '#default_value' => $profile['usertab'],
  );
  $form['filesize'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum file size per upload'),
    '#default_value' => $profile['filesize'],
    '#description' => t('Set to 0 to use the maximum value available.') . ' ' . t('Your PHP settings limit the maximum file size per upload to %size.', array(
      '%size' => format_size(file_upload_max_size()),
    )),
    '#field_suffix' => t('MB'),
  );
  $form['quota'] = array(
    '#type' => 'textfield',
    '#title' => t('Directory quota'),
    '#default_value' => $profile['quota'],
    '#description' => t('Define the upload quota per directory.') . ' ' . t('Set to 0 to use the maximum value available.'),
    '#field_suffix' => t('MB'),
  );
  $form['tuquota'] = array(
    '#type' => 'textfield',
    '#title' => t('Total user quota'),
    '#default_value' => $profile['tuquota'],
    '#description' => t('This quota measures the size of all user uploaded files in the database and does not include FTP files. You can either use both quotations together or safely ignore this by setting the value to 0.'),
    '#field_suffix' => t('MB'),
  );
  $form['extensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Permitted file extensions'),
    '#default_value' => $profile['extensions'],
    '#maxlength' => 255,
    '#description' => t('Specify the allowed file extensions for uploaded files. Separate extensions with a space and do not include the leading dot.') . ' ' . t('Set to * to remove the restriction.'),
  );
  $form['dimensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum image dimensions'),
    '#default_value' => $profile['dimensions'],
    '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction. If an <a href="!image-toolkit-link">image toolkit</a> is installed, files exceeding this value will be scaled down to fit.', array(
      '!image-toolkit-link' => url('admin/config/media/image-toolkit'),
    )),
    '#field_suffix' => '<kbd>' . t('WIDTHxHEIGHT') . '</kbd>',
  );
  $form['filenum'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum number of files per operation'),
    '#default_value' => $profile['filenum'],
    '#description' => t('You can allow users to select multiple files for operations such as delete, resize, etc. Entire batch file operation is executed in a single drupal load, which may be good. However there will be an increase in script execution time, cpu load and memory consumption possibly exceeding the limits of your server, which is really bad. For unlimited number of file handling, set this to 0.'),
  );

  // Directories.
  $form['directories']['#theme'] = 'imce_directories';
  $form['directories']['#weight'] = 1;
  for ($i = 0; $i < count($profile['directories']); $i++) {
    $form['directories'][$i] = imce_directory_form($profile['directories'][$i]);
  }
  $form['directories'][$i] = imce_directory_form();
  $form['directories'][$i + 1] = imce_directory_form();

  // Thumbnails.
  $form['thumbnails']['#theme'] = 'imce_thumbnails';
  $form['thumbnails']['#weight'] = 2;
  for ($i = 0; $i < count($profile['thumbnails']); $i++) {
    $form['thumbnails'][$i] = imce_thumbnail_form($profile['thumbnails'][$i]);
  }
  $form['thumbnails'][$i] = imce_thumbnail_form();
  $form['thumbnails'][$i + 1] = imce_thumbnail_form();
  $form = array(
    'profile' => $form,
  );
  $form['pid'] = array(
    '#type' => 'hidden',
    '#value' => $pid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['#validate'][] = 'imce_profile_validate';
  $form['#submit'][] = 'imce_profile_submit';
  return $form;
}