You are here

function shrinktheweb_admin_log in ShrinkTheWeb 7

Same name and namespace in other branches
  1. 6 shrinktheweb.admin.inc \shrinktheweb_admin_log()
1 string reference to 'shrinktheweb_admin_log'
shrinktheweb_menu in ./shrinktheweb.module
Implementation of hook_menu().

File

./shrinktheweb.admin.inc, line 2

Code

function shrinktheweb_admin_log($form, $form_state) {
  $form = array();
  if (!isset($form_state['storage']['confirm'])) {
    $log_records = array();

    // format the tableselect header
    $header = array(
      'domain' => array(
        'data' => t('Domain'),
        'field' => 'sl.stw_domain',
      ),
      'hash' => array(
        'data' => t('Hash'),
        'field' => 'sl.stw_hash',
      ),
      'timestamp' => array(
        'data' => t('Timestamp'),
        'field' => 'sl.stw_timestamp',
      ),
      'capturedon' => array(
        'data' => t('Captured on'),
        'field' => 'sl.stw_capturedon',
      ),
      'quality' => array(
        'data' => t('Quality'),
        'field' => 'sl.stw_quality',
      ),
      'full' => array(
        'data' => t('Full'),
        'field' => 'sl.stw_full',
      ),
      'xmax' => array(
        'data' => t('Xmax'),
        'field' => 'sl.stw_xmax',
      ),
      'ymax' => array(
        'data' => t('Ymax'),
        'field' => 'sl.stw_ymax',
      ),
      'nrx' => array(
        'data' => t('nrX'),
        'field' => 'sl.stw_nrx',
      ),
      'nry' => array(
        'data' => t('nrY'),
        'field' => 'sl.stw_nry',
      ),
      'invalid' => array(
        'data' => t('Invalid'),
        'field' => 'sl.stw_invalid',
      ),
      'stwerrcode' => array(
        'data' => t('STW error code'),
        'field' => 'sl.stw_stwerrcode',
      ),
      'error' => array(
        'data' => t('Error'),
        'field' => 'sl.stw_error',
      ),
      'errcode' => array(
        'data' => t('Error'),
        'field' => 'sl.stw_errcode',
      ),
    );

    // get the log records
    $result = db_select('shrinktheweb_log', 'sl')
      ->fields('sl')
      ->extend('PagerDefault')
      ->limit(25)
      ->extend('TableSort')
      ->orderByHeader($header)
      ->addTag('shrinktheweb_log_records')
      ->execute();
    foreach ($result as $record) {
      $log_records[$record->stw_siteid] = array(
        'domain' => $record->stw_domain,
        'hash' => $record->stw_hash,
        'timestamp' => date("M d, Y, H:i:s", $record->stw_timestamp),
        'capturedon' => date("M d, Y, H:i:s", $record->stw_capturedon),
        'quality' => $record->stw_quality,
        'full' => $record->stw_full,
        'xmax' => $record->stw_xmax,
        'ymax' => $record->stw_ymax,
        'nrx' => $record->stw_nrx,
        'nry' => $record->stw_nry,
        'invalid' => $record->stw_invalid,
        'stwerrcode' => $record->stw_stwerrcode,
        'error' => $record->stw_error,
        'errcode' => $record->stw_errcode,
      );
    }

    //check if there are any records in the log
    if (empty($log_records)) {
      return array(
        'no_records' => array(
          '#markup' => t('The log is empty.'),
        ),
      );
    }
    $form['log_records'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $log_records,
      '#tree' => FALSE,
    );
    $form['pager'] = array(
      '#theme' => 'pager',
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Delete selected records'),
    );
    return $form;
  }
  else {
    return confirm_form($form, t('Do you want to delete the record(s)?'), 'admin/config/media/shrinktheweb/log');
  }
}