function captcha_questions_dblog_view in Captcha Questions 7
Fetch and display failed form submissions.
Return value
array Returns themed table with pager
1 string reference to 'captcha_questions_dblog_view'
- captcha_questions_dblog_menu in captcha_questions_dblog/
captcha_questions_dblog.module - Implements hook_menu().
File
- captcha_questions_dblog/
captcha_questions_dblog.module, line 31 - Enables logging and display of failed form submissions.
Code
function captcha_questions_dblog_view() {
$output = '';
$header = array(
array(
'data' => t('Submission'),
'field' => 'dblogid',
),
array(
'data' => t('Timestamp'),
'field' => 'timestamp',
),
array(
'data' => t('IP'),
'field' => 'IP',
),
array(
'data' => t('Form ID'),
'field' => 'form_id',
),
array(
'data' => t('Question asked'),
'field' => 'question_asked',
),
array(
'data' => t('Answer given'),
'field' => 'answer_given',
),
array(
'data' => t('Correct answer'),
'field' => 'answer_correct',
),
);
$rows = array();
// Fetching all entries.
$entries = db_select('captcha_questions_dblog', 'log')
->extend('PagerDefault')
->limit(5)
->extend('TableSort')
->orderByHeader($header)
->fields('log', array(
'dblogid',
'timestamp',
'ip',
'form_id',
'question_asked',
'answer_given',
'answer_correct',
))
->execute();
// Constructing rows from $entries matching $header.
foreach ($entries as $e) {
$rows[] = array(
$e->dblogid,
format_date($e->timestamp, 'custom', 'Y-m-d H:m:s'),
$e->ip,
$e->form_id,
truncate_utf8($e->question_asked, '30', TRUE, 20),
$e->answer_given,
$e->answer_correct,
);
}
global $pager_total_items;
$output .= 'Found a total of ' . $pager_total_items[0] . ' failed submissions';
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
));
$output .= theme('pager');
return $output;
}