You are here

function theme_webform_edit_file in Webform 5

Same name and namespace in other branches
  1. 5.2 components/file.inc \theme_webform_edit_file()
  2. 6.2 components/file.inc \theme_webform_edit_file()

File

components/file.inc, line 86

Code

function theme_webform_edit_file($form) {

  // Add a little javascript to check all the items in one type.
  $javascript = '
    <script type="text/javascript">
      function check_category_boxes () {
        var checkValue = !document.getElementById("edit-field-extra-filtering-types-"+arguments[0]+"-"+arguments[1]).checked;
        for(var i=1; i < arguments.length; i++) {
          document.getElementById("edit-field-extra-filtering-types-"+arguments[0]+"-"+arguments[i]).checked = checkValue;
        }
      }
  </script>
 ';
  drupal_set_html_head($javascript);

  // Format the components into a table.
  $per_row = 5;
  $rows = array();
  foreach (element_children($form['extra']['filtering']['types']) as $key => $filtergroup) {
    $row = array();
    $first_row = count($rows);
    if ($form['extra']['filtering']['types'][$filtergroup]['#type'] == 'checkboxes') {

      // Add the title.
      $row[] = $form['extra']['filtering']['types'][$filtergroup]['#title'];
      $row[] = "&nbsp;";

      // Convert the checkboxes into individual form-items.
      $checkboxes = expand_checkboxes($form['extra']['filtering']['types'][$filtergroup]);

      // Render the checkboxes in two rows.
      $checkcount = 0;
      $jsboxes = "";
      foreach ($checkboxes as $key => $checkbox) {
        if ($checkbox['#type'] == 'checkbox') {
          $checkcount++;
          $jsboxes .= "'" . $checkbox['#return_value'] . "',";
          if ($checkcount <= $per_row) {
            $row[] = array(
              'data' => drupal_render($checkbox),
            );
          }
          elseif ($checkcount == $per_row + 1) {
            $rows[] = array(
              'data' => $row,
              'style' => 'border-bottom: none;',
            );
            $row = array(
              array(
                'data' => '&nbsp;',
              ),
              array(
                'data' => '&nbsp;',
              ),
            );
            $row[] = array(
              'data' => drupal_render($checkbox),
            );
          }
          else {
            $row[] = array(
              'data' => drupal_render($checkbox),
            );
          }
        }
      }

      // Pretty up the table a little bit.
      $current_cell = $checkcount % $per_row;
      if ($current_cell > 0) {
        $colspan = $per_row - $current_cell + 1;
        $row[$current_cell + 1]['colspan'] = $colspan;
      }

      // Add the javascript links.
      $jsboxes = substr($jsboxes, 0, strlen($jsboxes) - 1);
      $rows[] = array(
        'data' => $row,
      );
      $select_link = ' <a href="javascript:check_category_boxes(\'' . $filtergroup . '\',' . $jsboxes . ')">(select)</a>';
      $rows[$first_row]['data'][1] = array(
        'data' => $select_link,
        'width' => 40,
      );
      unset($form['extra']['filtering']['types'][$filtergroup]);
    }
    elseif ($filtergroup != 'size') {

      // Add other fields to the table (ie. additional extensions).
      $row[] = $form['extra']['filtering']['types'][$filtergroup]['#title'];
      unset($form['extra']['filtering']['types'][$filtergroup]['#title']);
      $row[] = array(
        'data' => drupal_render($form['extra']['filtering']['types'][$filtergroup]),
        'colspan' => $per_row + 1,
      );
      unset($form['extra']['filtering']['types'][$filtergroup]);
      $rows[] = array(
        'data' => $row,
      );
    }
  }
  $header = array(
    array(
      'data' => t('Category'),
      'colspan' => '2',
    ),
    array(
      'data' => t('Types'),
      'colspan' => $per_row,
    ),
  );

  // Create the table inside the form.
  $form['extra']['filtering']['types']['table'] = array(
    '#value' => theme('table', $header, $rows),
  );
  $output = drupal_render($form);

  // Prefix the upload location field with the default path for webform.
  $output = str_replace("Upload Directory: </label>", "Upload Directory: </label>" . variable_get('file_directory_path', 'files') . "/webform/", $output);
  return $output;
}