You are here

function webform2pdf_edit_form in Webform2PDF 6

Same name and namespace in other branches
  1. 6.2 includes/webform2pdf.settings.inc \webform2pdf_edit_form()
  2. 7.4 includes/webform2pdf.settings.inc \webform2pdf_edit_form()
  3. 7.3 includes/webform2pdf.settings.inc \webform2pdf_edit_form()

Overview form of all components for this webform.

1 string reference to 'webform2pdf_edit_form'
webform2pdf_menu in ./webform2pdf.module
Implementation of hook_menu().

File

./webform2pdf.module, line 635

Code

function webform2pdf_edit_form($form_state, $node) {
  $form = array();
  $result = db_query("SELECT * FROM {webform2pdf} WHERE nid = %d AND enabled = 1", $node->nid);
  $default = db_fetch_array($result);
  $form['enabled'] = array(
    '#default_value' => $default['enabled'],
    '#type' => 'checkbox',
    '#title' => t('Generate PDF Document.'),
  );
  if ($default['enabled']) {
    $webform2pdf_default = variable_get('webform2pdf_default', '');

    // Needed because of file upload
    $form['#attributes'] = array(
      'enctype' => 'multipart/form-data',
    );
    $form['base'] = array(
      '#type' => 'fieldset',
      '#title' => t('General settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['base']['page_format'] = array(
      '#type' => 'select',
      '#title' => t('Paper size'),
      '#default_value' => $default['page_format'],
      '#options' => array(
        '4A0' => '4A0',
        '2A0' => '2A0',
        'A0' => 'A0',
        'A1' => 'A1',
        'A2' => 'A2',
        'A3' => 'A3',
        'A4' => 'A4',
        'A5' => 'A5',
        'A6' => 'A6',
        'A7' => 'A7',
        'A8' => 'A8',
        'A9' => 'A9',
        'A10' => 'A10',
        'B0' => 'B0',
        'B1' => 'B1',
        'B2' => 'B2',
        'B3' => 'B3',
        'B4' => 'B4',
        'B5' => 'B5',
        'B6' => 'B6',
        'B7' => 'B7',
        'B8' => 'B8',
        'B9' => 'B9',
        'B10' => 'B10',
        'C0' => 'C0',
        'C1' => 'C1',
        'C2' => 'C2',
        'C3' => 'C3',
        'C4' => 'C4',
        'C5' => 'C5',
        'C6' => 'C6',
        'C7' => 'C7',
        'C8' => 'C8',
        'C9' => 'C9',
        'C10' => 'C10',
        'RA0' => 'RA0',
        'RA1' => 'RA1',
        'RA2' => 'RA2',
        'RA3' => 'RA3',
        'RA4' => 'RA4',
        'SRA0' => 'SRA0',
        'SRA1' => 'SRA1',
        'SRA2' => 'SRA2',
        'SRA3' => 'SRA3',
        'SRA4' => 'SRA4',
        'LETTER' => t('Letter'),
        'LEGAL' => t('Legal'),
        'EXECUTIVE' => t('Executive'),
        'FOLIO' => t('Folio'),
      ),
    );
    $form['base']['page_orientation'] = array(
      '#type' => 'radios',
      '#title' => t('Page orientation'),
      '#default_value' => $default['page_orientation'],
      '#options' => array(
        'P' => t('Portrait'),
        'L' => t('Landscape'),
      ),
    );

    // E-mail settings
    $form['email'] = array(
      '#type' => 'fieldset',
      '#title' => t('E-mail settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['email']['pdf_send_email'] = array(
      '#type' => 'checkbox',
      '#title' => t('Attach PDF as an attachment to the e-mails sent to the form recipients.'),
      '#default_value' => $default['pdf_send_email'],
    );
    $send_mail = array();
    if (!empty($node->webform['email'])) {
      $send_mail['email'] = $node->webform['email'];
    }
    $options = _webform_component_options($node->webform['components'], 'email');
    if (is_array($node->webform['components'])) {
      foreach ($node->webform['components'] as $cid => $component) {
        if (isset($component['extra']['email']) && $component['extra']['email']) {
          $send_mail[$cid] = t('Form component: %component', array(
            '%component' => $component['name'],
          ));
        }
      }
    }
    if (count($send_mail)) {
      $def = unserialize($default['no_send_email_addr']);
      if (!is_array($def)) {
        $def = array();
      }
      $form['email']['no_send_email_addr'] = array(
        '#title' => t("Don't attach PDF file"),
        '#type' => 'checkboxes',
        '#options' => $send_mail,
        '#default_value' => $def,
        '#description' => t("PDF file won't be attached to the e-mail sent to the following recipients."),
      );
    }

    // Header
    $form['header'] = array(
      '#type' => 'fieldset',
      '#title' => t('PDF header'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['header']['h_left_logo'] = array(
      '#type' => 'value',
      '#value' => $default['h_left_logo'],
    );
    if ($default['h_left_logo']) {
      $logo_file = _webform2pdf_get_file($default['h_left_logo']);
      $form['header']['h_left_logo_img'] = array(
        '#type' => 'item',
        '#title' => t('Logo on the left side'),
        '#value' => theme('image', $logo_file->filepath, 'Header left logo.', $logo_file->filename),
      );
      $form['header']['h_left_logo_del'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete left side logo.'),
      );
    }
    else {
      $form['header']['h_left_logo_file'] = array(
        '#type' => 'file',
        '#title' => t('Upload left side logo'),
        '#size' => 60,
        '#maxlength' => 250,
        '#description' => t("Upload left side logo. If the size of the uploaded image is more than !size, it will be resized to this size.", array(
          '!size' => $webform2pdf_default['h_left_logo_size'],
        )),
      );
    }
    $form['header']['h_txt'] = array(
      '#type' => 'textarea',
      '#title' => t('Header text'),
      '#rows' => '5',
      '#default_value' => $default['h_txt'],
      '#resizable' => FALSE,
      '#description' => t("PDF header text. 5 rows maximum.") . theme('webform_token_help'),
    );
    $form['header']['h_txt_align'] = array(
      '#type' => 'select',
      '#title' => t('Text alignment'),
      '#default_value' => $default['h_txt_align'],
      '#options' => array(
        'L' => t('Align left'),
        'C' => t('Align center'),
        'R' => t('Align right'),
      ),
    );
    $form['header']['h_font_family'] = array(
      '#type' => 'select',
      '#title' => t('Font Family'),
      '#default_value' => $default['h_font_family'],
      '#options' => array(
        'helvetica' => 'Helvetica',
        'times' => 'Times',
        'courier' => 'Courier',
        'dejavusans' => 'Dejavu Sans',
        'dejavuserif' => 'Dejavu Serif',
        'freesans' => 'Free Sans',
        'freeserif' => 'Free Serif',
        'freemono' => 'Free Mono',
      ),
      '#description' => t('Set the font family to be used.'),
    );
    $form['header']['h_font_size'] = array(
      '#type' => 'textfield',
      '#title' => t('Font Size'),
      '#default_value' => $default['h_font_size'],
      '#size' => 2,
      '#maxlength' => 3,
      '#description' => t('Set the font size to be used for header text. This is the base value for the scaling applied to other text styles.'),
    );
    $form['header']['h_right_logo'] = array(
      '#type' => 'value',
      '#value' => $default['h_right_logo'],
    );
    if ($default['h_right_logo']) {
      $logo_file = _webform2pdf_get_file($default['h_right_logo']);
      $form['header']['h_right_logo_img'] = array(
        '#type' => 'item',
        '#title' => t('Logo on the right side'),
        '#value' => theme('image', $logo_file->filepath, 'Header right logo.', $logo_file->filename),
      );
      $form['header']['h_right_logo_del'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete right logo.'),
      );
    }
    else {
      $form['header']['h_right_logo_file'] = array(
        '#type' => 'file',
        '#title' => t('Upload right logo'),
        '#size' => 60,
        '#maxlength' => 250,
        '#description' => t("Upload right side logo. If the size of the uploaded image is more than !size, it will be resized to this size.", array(
          '!size' => $webform2pdf_default['h_right_logo_size'],
        )),
      );
    }

    // PDF body (page)
    $form['page'] = array(
      '#type' => 'fieldset',
      '#title' => t('Content of the PDF document'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $tokens = _webform2pdf_list_template_vars($node);
    array_unshift($tokens, '%pagebreak');
    $form['page']['p_body'] = array(
      '#type' => 'textarea',
      '#title' => t('Page body'),
      '#rows' => '10',
      '#default_value' => $default['p_body'],
      '#description' => t("The content of the PDF file can be defined here, the text can be formatted with HTML and CSS tags. The form elements can be referred with the following special strings: !vars. Select form elements can be outputted in different ways, write one of the following strings after the element name to choose from them: '-nl', '-all', '-nl-all'. '-nl ' modifier writes every selected element into a new line, '-all' lists every option, and marks which were selected from them. '-nl-all' lists all of the options in separate lines, and marks selected ones.", array(
        '!vars' => implode(', ', $tokens),
      )) . theme('webform_token_help'),
    );
    $form['page']['format'] = filter_form($default['format']);
    $form['page']['p_txt_align'] = array(
      '#type' => 'select',
      '#title' => t('Text alignment'),
      '#default_value' => $default['p_txt_align'],
      '#options' => array(
        'L' => t('Align left'),
        'C' => t('Align center'),
        'R' => t('Align right'),
      ),
    );
    $form['page']['p_font_family'] = array(
      '#type' => 'select',
      '#title' => t('Font Family'),
      '#default_value' => $default['p_font_family'],
      '#options' => array(
        'helvetica' => 'Helvetica',
        'times' => 'Times',
        'courier' => 'Courier',
        'dejavusans' => 'Dejavu Sans',
        'dejavuserif' => 'Dejavu Serif',
        'freesans' => 'Free Sans',
        'freeserif' => 'Free Serif',
        'freemono' => 'Free Mono',
      ),
      '#description' => t('Set the font family to be used.'),
    );
    $form['page']['p_font_size'] = array(
      '#type' => 'textfield',
      '#title' => t('Font Size'),
      '#default_value' => $default['p_font_size'],
      '#size' => 2,
      '#maxlength' => 3,
      '#description' => t('Set the font size to be used for header text. This is the base value for the scaling applied to other text styles.'),
    );

    // Footer
    $form['footer'] = array(
      '#type' => 'fieldset',
      '#title' => t('PDF footer'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['footer']['f_left_logo'] = array(
      '#type' => 'value',
      '#value' => $default['f_left_logo'],
    );
    if ($default['f_left_logo']) {
      $logo_file = _webform2pdf_get_file($default['f_left_logo']);
      $form['footer']['f_left_logo_img'] = array(
        '#type' => 'item',
        '#title' => t('Logo on the left side'),
        '#value' => theme('image', $logo_file->filepath, 'Footer left logo.', $logo_file->filename),
      );
      $form['footer']['f_left_logo_del'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete left side logo.'),
      );
    }
    else {
      $form['footer']['f_left_logo_file'] = array(
        '#type' => 'file',
        '#title' => t('Upload left side logo'),
        '#size' => 60,
        '#maxlength' => 250,
        '#description' => t("Upload left side logo. If the size of the uploaded image is more than !size, it will be resized to this size.", array(
          '!size' => $webform2pdf_default['f_left_logo_size'],
        )),
      );
    }
    $form['footer']['f_txt'] = array(
      '#type' => 'textarea',
      '#title' => t('Footer text'),
      '#rows' => '2',
      '#default_value' => $default['f_txt'],
      '#resizable' => FALSE,
      '#description' => t("The PDF footer text. 2 rows maximum. The following special element can be used: %pagenumber - number of the page, %totalpage - total page count.") . theme('webform_token_help'),
    );
    $form['footer']['f_txt_align'] = array(
      '#type' => 'select',
      '#title' => t('Text alignment'),
      '#default_value' => $default['f_txt_align'],
      '#options' => array(
        'L' => t('Align left'),
        'C' => t('Align center'),
        'R' => t('Align right'),
      ),
    );
    $form['footer']['f_font_family'] = array(
      '#type' => 'select',
      '#title' => t('Font Family'),
      '#default_value' => $default['f_font_family'],
      '#options' => array(
        'helvetica' => 'Helvetica',
        'times' => 'Times',
        'courier' => 'Courier',
        'dejavusans' => 'Dejavu Sans',
        'dejavuserif' => 'Dejavu Serif',
        'freesans' => 'Free Sans',
        'freeserif' => 'Free Serif',
        'freemono' => 'Free Mono',
      ),
      '#description' => t('Set the font family to be used.'),
    );
    $form['footer']['f_font_size'] = array(
      '#type' => 'textfield',
      '#title' => t('Font Size'),
      '#default_value' => $default['f_font_size'],
      '#size' => 2,
      '#maxlength' => 3,
      '#description' => t('Set the font size to be used for header text. This is the base value for the scaling applied to other text styles.'),
    );
    $form['footer']['f_right_logo'] = array(
      '#type' => 'value',
      '#value' => $default['f_right_logo'],
    );
    if ($default['f_right_logo']) {
      $logo_file = _webform2pdf_get_file($default['f_right_logo']);
      $form['footer']['f_right_logo_img'] = array(
        '#type' => 'item',
        '#title' => t('Logo on the right side'),
        '#value' => theme('image', $logo_file->filepath, 'Footer right logo.', $logo_file->filename),
      );
      $form['footer']['f_right_logo_del'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete right logo.'),
      );
    }
    else {
      $form['footer']['f_right_logo_file'] = array(
        '#type' => 'file',
        '#title' => t('Upload right logo'),
        '#size' => 60,
        '#maxlength' => 250,
        '#description' => t("Upload right side logo. If the size of the uploaded image is more than !size, it will be resized to this size.", array(
          '!size' => $webform2pdf_default['f_right_logo_size'],
        )),
      );
    }
  }
  else {

    // if 'Generate PDF' is not yet enabled
    $form['#submit'] = array(
      'webform2pdf_enable_edit_form_submit',
    );
  }
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $node->nid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  if ($default['enabled']) {
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
    );
  }
  return $form;
}