You are here

function uc_csv_add_new_report in Ubercart CSV 7.2

Same name and namespace in other branches
  1. 6.2 uc_csv.module \uc_csv_add_new_report()

Add new reports

Interface for adding a new report or editing an existing one

1 string reference to 'uc_csv_add_new_report'
uc_csv_menu in ./uc_csv.module
Implements hook_menu

File

./uc_csv.module, line 367

Code

function uc_csv_add_new_report($form, &$form_state) {
  $report = $form_state['build_info']['args'];

  /* if we are creating a new report, then the args will be empty and we will need to initialize */

  /* our object variables */
  if ($report == array()) {
    $report = new stdClass();
    $report->rid = $report->report_name = $report->shipping_address = NULL;
    $report->billing_address = $report->products = $report->orderby = NULL;
    $report->track = $report->file_type = $report->email_enable = $report->email_address = NULL;
  }
  else {
    $report = $report[0];
  }

  // set up our form of properties for the report being sought.
  $form = array();
  $form['rid'] = array(
    '#type' => 'hidden',
    '#default_value' => $report->rid,
  );
  $form['export_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Export Options'),
    '#weight' => 2,
    '#collapsible' => TRUE,
  );
  $form['status_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Order Statuses to Export'),
    '#weight' => 3,
    '#collapsible' => TRUE,
  );
  $form['email'] = array(
    '#type' => 'fieldset',
    '#title' => t('Email Options'),
    '#weight' => 4,
    '#collapsible' => TRUE,
  );
  $form['other'] = array(
    '#type' => 'fieldset',
    '#title' => t('Report Email Options'),
    '#weight' => 4,
    '#collapsible' => TRUE,
  );
  $form['report_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Report Name'),
    '#default_value' => $report->report_name,
    '#max_length' => 96,
    '#required' => TRUE,
    '#weight' => 1,
  );
  $default_options = array();
  if ($report->shipping_address) {
    $default_options[] = 'shipping';
  }
  if ($report->billing_address) {
    $default_options[] = 'billing';
  }
  if ($report->products) {
    $default_options[] = 'products';
  }
  $form['export_options']['options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Export Options'),
    '#default_value' => $default_options,
    '#options' => array(
      'shipping' => t('Shipping Address'),
      'billing' => t('Billing Address'),
      'products' => t('Products'),
    ),
    '#description' => t('Select the information you want exported in your report'),
  );

  /* get a list of the order statuses available/created */
  $statuses = array();
  if (isset($report->statuses) && $report->statuses) {
    $default_statuses = unserialize($report->statuses);
  }
  else {
    $default_statuses = array();
  }
  $result = db_query("SELECT order_status_id,title,state\n                      FROM {uc_order_statuses}\n                      ORDER BY weight ASC");
  while ($sdata = $result
    ->fetchObject()) {
    $statuses[$sdata->order_status_id] = $sdata->title;
  }
  $form['status_options']['statuses'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Order Statuses to Export'),
    '#default_value' => $default_statuses,
    '#options' => $statuses,
    '#description' => t('Select the order statuses to be exported in this report.'),
  );
  $form['email']['email_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Check if you would like to have generated reports emailed as opposed to downloaded on generation.'),
    '#description' => t('This is especially useful for when you have cron or drush generated emails that you do not want to have to deal with retrieving. Emails will be sent to the email address configured in this report.'),
    '#default_value' => $report->email_enable,
  );
  $form['email']['email_address'] = array(
    '#type' => 'textfield',
    '#title' => t('Email address where you wish the report to be send to.'),
    '#default_value' => $report->email_address,
  );
  $form['other']['orderby'] = array(
    '#type' => 'select',
    '#title' => t('Order By'),
    '#default_value' => $report->orderby,
    '#options' => array(
      'order_id' => 'Order ID',
      'last_name' => 'Customer Last Name',
    ),
    '#description' => t('How you would like your report sorted.'),
  );
  $form['other']['track'] = array(
    '#type' => 'select',
    '#title' => t('Track Last Exported Orders'),
    '#default_value' => $report->track,
    '#options' => array(
      '0' => 'No',
      '1' => 'Yes',
    ),
    '#description' => t('Select Yes if you would like for each export to be progressive instead of all inclusive.'),
  );
  $form['other']['file_type'] = array(
    '#type' => 'select',
    '#title' => t('Type of File To Export'),
    '#default_value' => $report->file_type,
    '#options' => array(
      'csv' => 'CSV (Comma Separated Values)',
      'xls' => 'Microsoft Excel XML Export',
    ),
    '#description' => t('The type of file to be exported. Use Excel if trying to export data with special characters (foreign language) in it.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Report Options'),
    '#weight' => 5,
  );
  return $form;
}