captcha_questions_dblog.module in Captcha Questions 7
Enables logging and display of failed form submissions.
The logging is performed in captcha_questions.module.
File
captcha_questions_dblog/captcha_questions_dblog.moduleView source
<?php
/**
* @file
* Enables logging and display of failed form submissions.
*
* The logging is performed in captcha_questions.module.
*/
/**
* Implements hook_menu().
*/
function captcha_questions_dblog_menu() {
$items = array();
$items['admin/config/people/captcha_questions/failed_submissions'] = array(
'title' => 'Failed submissions',
'description' => 'Lists all failed submissions from captcha questions',
'page callback' => 'captcha_questions_dblog_view',
'access arguments' => array(
'administer captcha questions settings',
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Fetch and display failed form submissions.
*
* @return array
* Returns themed table with pager
*/
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;
}
Functions
Name | Description |
---|---|
captcha_questions_dblog_menu | Implements hook_menu(). |
captcha_questions_dblog_view | Fetch and display failed form submissions. |