You are here

function gdpr_task_edit_gdpr_sar_form in General Data Protection Regulation 7

Form callback for export tasks.

File

modules/gdpr_tasks/gdpr_tasks.admin.inc, line 108
Administrative page and form callbacks for the GDPR Tasks module.

Code

function gdpr_task_edit_gdpr_sar_form($form, &$form_state) {
  $task = $form_state['task'] = $form_state['build_info']['args'][0];
  $form = gdpr_task_form($form, $form_state);
  ctools_include('export');
  $plugins = ctools_export_load_object('gdpr_fields_field_data');
  $inc_label_map = array(
    'inc' => '[' . t('Include') . ']',
    'maybe' => '[' . t('Maybe') . ']',
  );

  // Don't try to show task details if it has not yet been processed.
  if ($task->status == 'requested') {
    return array(
      'message' => array(
        '#markup' => 'This task has not yet been processed. Please run cron or check back later.',
      ),
    );
  }
  if (!empty($task->gdpr_tasks_sar_export_parts)) {
    foreach ($task->gdpr_tasks_sar_export_parts[LANGUAGE_NONE] as $part) {
      $header = array();
      $rows = array();
      if (($handle = fopen(drupal_realpath($part['uri']), "r")) !== FALSE) {
        $row_type = 'plugin';
        $type = array();
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
          switch ($row_type) {
            case 'plugin':
              foreach ($data as $key => $plugin_id) {
                if (isset($plugins[$plugin_id])) {
                  $plugin = $plugins[$plugin_id];
                  $inc = $plugin
                    ->getSetting('gdpr_fields_rta');
                }
                $type[$key] = isset($inc) ? $inc_label_map[$inc] : '';
              }
              $row_type = 'header';
              break;
            case 'header':
              $header = $data;
              $rows[] = $type;
              $row_type = 'row';
              break;
            default:
              $rows[] = $data;
              break;
          }
        }
        fclose($handle);
      }
      $form[$part['filename']] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#caption' => t('File contents for @filename', array(
          '@filename' => $part['filename'],
        )),
      );
    }
  }
  $form['actions']['submit']['#value'] = t('Process');
  $form['actions']['submit']['#name'] = 'export';
  $form['gdpr_tasks_manual_data']['#access'] = FALSE;
  if ($task->status == 'closed') {

    // Disable export field form element.
    $form['gdpr_tasks_sar_export']['#disabled'] = TRUE;
    $form['gdpr_tasks_sar_export_parts']['#access'] = FALSE;
    $form['gdpr_tasks_sar_export_assets']['#access'] = FALSE;
    $form['actions']['#access'] = FALSE;
  }
  else {
    $form['gdpr_tasks_sar_export']['#access'] = FALSE;
  }
  return $form;
}