You are here

function shrinktheweb_admin_log in ShrinkTheWeb 6

Same name and namespace in other branches
  1. 7 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_state) {
  $form = array();

  // dont show debug log viewer if Elements module is not installed and enabled
  if (!module_exists('elements')) {
    $form['error'] = array(
      '#value' => t('Please install and enable Elements module to support debug log viewer!'),
    );
    return $form;
  }
  if (!isset($form_state['storage']['confirm'])) {
    $log_records = array();

    // format the tableselect header
    $header = array(
      'domain' => array(
        'data' => t('Domain'),
        'field' => 'domain',
      ),
      'hash' => array(
        'data' => t('Hash'),
        'field' => 'hash',
      ),
      'timestamp' => array(
        'data' => t('Timestamp'),
        'field' => 'imestamp',
      ),
      'capturedon' => array(
        'data' => t('Captured on'),
        'field' => 'capturedon',
      ),
      'quality' => array(
        'data' => t('Quality'),
        'field' => 'quality',
      ),
      'full' => array(
        'data' => t('Full'),
        'field' => 'full',
      ),
      'xmax' => array(
        'data' => t('Xmax'),
        'field' => 'xmax',
      ),
      'ymax' => array(
        'data' => t('Ymax'),
        'field' => 'ymax',
      ),
      'nrx' => array(
        'data' => t('nrX'),
        'field' => 'nrx',
      ),
      'nry' => array(
        'data' => t('nrY'),
        'field' => 'nry',
      ),
      'invalid' => array(
        'data' => t('Invalid'),
        'field' => 'invalid',
      ),
      'stwerrcode' => array(
        'data' => t('STW error code'),
        'field' => 'stwerrcode',
      ),
      'error' => array(
        'data' => t('Error'),
        'field' => 'error',
      ),
      'errcode' => array(
        'data' => t('Error'),
        'field' => 'errcode',
      ),
      'referrer' => array(
        'data' => t('Referrer'),
        'field' => 'referrer',
      ),
    );

    // get the log records
    $result = db_query("SELECT * FROM {shrinktheweb_log}");
    while ($record = db_fetch_array($result)) {
      $log_records[$record['siteid']] = array(
        'domain' => $record['domain'],
        'hash' => $record['hash'],
        'timestamp' => $record['timestamp'],
        'capturedon' => $record['capturedon'],
        'quality' => $record['quality'],
        'full' => $record['full'],
        'xmax' => $record['xmax'],
        'ymax' => $record['ymax'],
        'nrx' => $record['nrx'],
        'nry' => $record['nry'],
        'invalid' => $record['invalid'],
        'stwerrcode' => $record['stwerrcode'],
        'error' => $record['error'],
        'errcode' => $record['errcode'],
        'referrer' => $record['referrer'],
      );
    }

    //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');
  }
}