You are here

hacked.forms.inc in Hacked! 7.3

The forms

File

hacked.forms.inc
View source
<?php

/**
 * @file
 * The forms
 */

/**
 * Attach helpers.
 */
require_once __DIR__ . '/hacked.helpers.inc';
function hacked_report_form($form, $form_state) {
  $header = [
    'project_name' => t('Project Name'),
    'version' => t('Version'),
    'changes' => t('Changes'),
    'details' => t('View details'),
    'status' => t('Status'),
  ];
  $core = [];
  $modules = [];
  $themes = [];
  foreach (_hacked_get_projects() as $project) {
    $temp = [
      'project_name' => $project['name'],
      'version' => $project['existing_version'],
      'changes' => '0 files changed, 0 files deleted, 0 files added',
      'details' => '<a href="#">' . t('View Details') . '</a>',
      'status' => 'Unchecked',
    ];
    switch ($project['project_type']) {
      case 'core':
        $core[$project['name']] = $temp;
        break;
      case 'module':
        $modules[$project['name']] = $temp;
        break;
      case 'theme':
        $themes[$project['name']] = $temp;
        break;
    }
  }
  $form['table-core'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $core,
    '#prefix' => t('Drupal core'),
  ];
  $form['table-modules'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $modules,
    '#prefix' => t('Modules'),
  ];
  $form['table-themes'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $themes,
    '#prefix' => t('Themes'),
  ];
  $form['check'] = [
    '#type' => 'submit',
    '#value' => t('Check selected'),
  ];
  $form['check_all'] = [
    '#type' => 'submit',
    '#value' => t('Check All'),
  ];
  $form['restore'] = [
    '#type' => 'submit',
    '#value' => t('Restore selected'),
  ];
  $form['restore_all'] = [
    '#type' => 'submit',
    '#value' => t('Restore All'),
  ];
  return $form;
}
function hacked_report_form_submit($form, $form_state) {
  $operation = $form_state['triggering_element']['#parents'][0];
  $core = array_filter($form_state['values']['table-core']);
  $modules = array_filter($form_state['values']['table-modules']);
  $themes = array_filter($form_state['values']['table-themes']);
  $selected_projects = array_merge($core, $modules, $themes);
  if (($operation == HACKED_OP_CHECK_SELECTED || $operation == HACKED_OP_RESTORE_SELECTED) && empty($selected_projects)) {
    drupal_set_message(t('No items selected.'), 'error');
    return;
  }
  switch ($operation) {
    case HACKED_OP_CHECK_SELECTED:
      _hacked_report_batch(HACKED_OP_CHECK_SELECTED, $selected_projects);
      break;
    case HACKED_OP_RESTORE_SELECTED:
      _hacked_report_batch(HACKED_OP_RESTORE_SELECTED, $selected_projects);
      break;
    case HACKED_OP_CHECK_ALL:
      _hacked_report_batch(HACKED_OP_CHECK_ALL);
      break;
    case HACKED_OP_RESTORE_ALL:
      _hacked_report_batch(HACKED_OP_RESTORE_ALL);
      break;
  }
}