| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Module Admin Functions
|
| 6 |
*
|
| 7 |
* All of the code and functions associated with admin/settings/thisdayinhistory
|
| 8 |
*/
|
| 9 |
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Admin settings screen
|
| 13 |
*/
|
| 14 |
function thisdayinhistory_admin_overview() {
|
| 15 |
$total = db_result(db_query("SELECT COUNT(*) FROM {node} n where type = 'thisdayinhistory'"));
|
| 16 |
return "<label><strong>Content</strong></label>\n<div>Historical events: $total </div>";
|
| 17 |
}
|
| 18 |
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Displays a list of currently-defined blocks.
|
| 22 |
*/
|
| 23 |
function thisdayinhistory_blocks_configure() {
|
| 24 |
$form = array();
|
| 25 |
$form['name'] = array(
|
| 26 |
'#type' => 'textfield',
|
| 27 |
'#size' => 32,
|
| 28 |
'#maxlength' => 64
|
| 29 |
);
|
| 30 |
$form['submit'] = array(
|
| 31 |
'#type' => 'submit',
|
| 32 |
'#value' => t('Add block')
|
| 33 |
);
|
| 34 |
|
| 35 |
return $form;
|
| 36 |
}
|
| 37 |
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Renders the block list, including the "Add block" row.
|
| 41 |
*/
|
| 42 |
function theme_thisdayinhistory_blocks_configure($form) {
|
| 43 |
$header = array(t('Name'), t('Block ID'), t('Filters'), array('data' => t('Operations'), 'colspan' => 2));
|
| 44 |
$result = db_query('SELECT tdihb.* FROM {thisdayinhistory_blocks} tdihb ORDER BY tdihb.name');
|
| 45 |
$rows = array();
|
| 46 |
|
| 47 |
while ($block = db_fetch_object($result)) {
|
| 48 |
$filters = array();
|
| 49 |
|
| 50 |
if ($block->nid_filter) {
|
| 51 |
$filters[] = t('node');
|
| 52 |
}
|
| 53 |
|
| 54 |
if ($block->rid_filter) {
|
| 55 |
$filters[] = t('role');
|
| 56 |
}
|
| 57 |
|
| 58 |
if ($block->uid_filter) {
|
| 59 |
$filters[] = t('user');
|
| 60 |
}
|
| 61 |
|
| 62 |
if ($block->tid_filter) {
|
| 63 |
$filters[] = t('term');
|
| 64 |
}
|
| 65 |
|
| 66 |
$rows[] = array(
|
| 67 |
$block->name,
|
| 68 |
$block->bid,
|
| 69 |
implode(', ', (count($filters) ? $filters : array(t('none')))),
|
| 70 |
l(t('configure block'), "admin/build/block/configure/thisdayinhistory/$block->bid"),
|
| 71 |
l(t('delete block'), "admin/settings/thisdayinhistory/blocks/delete/$block->bid")
|
| 72 |
);
|
| 73 |
}
|
| 74 |
|
| 75 |
$rows[] = array(
|
| 76 |
drupal_render($form['name']),
|
| 77 |
array('data' => drupal_render($form['submit']), 'colspan' => 4)
|
| 78 |
);
|
| 79 |
|
| 80 |
$output = drupal_render($form);
|
| 81 |
|
| 82 |
if (count($rows)) {
|
| 83 |
$output .= theme('table', $header, $rows);
|
| 84 |
}
|
| 85 |
else {
|
| 86 |
$output .= theme('table', $header, array(array(array('data' => t('No blocks are defined.'), 'colspan' => 4))));
|
| 87 |
}
|
| 88 |
|
| 89 |
return $output;
|
| 90 |
}
|
| 91 |
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Validates that the new block name is valid.
|
| 95 |
*/
|
| 96 |
function thisdayinhistory_blocks_configure_validate($form, &$form_state) {
|
| 97 |
$name = trim($form_state['values']['name']);
|
| 98 |
|
| 99 |
if (!$name) {
|
| 100 |
form_set_error('name', t('You must specify a valid block name.'));
|
| 101 |
}
|
| 102 |
else if (db_result(db_query("SELECT COUNT(*) FROM {thisdayinhistory_blocks} tdihb WHERE tdihb.name = '%s'", $name))) {
|
| 103 |
form_set_error('name', t('The block name %name already exists. Please choose another block name.', array('%name' => $name)));
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 107 |
|
| 108 |
/**
|
| 109 |
* Creates the new block.
|
| 110 |
*/
|
| 111 |
function thisdayinhistory_blocks_configure_submit($form, &$form_state) {
|
| 112 |
db_query("INSERT INTO {thisdayinhistory_blocks}
|
| 113 |
(name, block_type, nid_filter, rid_filter, uid_filter, tid_filter, vid, header, header_format)
|
| 114 |
VALUES ('%s', 0, '', '', '', '', 0, '', 0)", trim($form_state['values']['name']));
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
/**
|
| 119 |
* Confirms the deletion a block.
|
| 120 |
*/
|
| 121 |
function thisdayinhistory_block_delete_confirmation($form_state, $bid) {
|
| 122 |
$block = db_fetch_object(db_query('SELECT tdihb.name FROM {thisdayinhistory_blocks} tdihb WHERE tdihb.bid = %d', $bid));
|
| 123 |
|
| 124 |
$form = array();
|
| 125 |
$form['bid'] = array(
|
| 126 |
'#type' => 'value',
|
| 127 |
'#value' => $bid
|
| 128 |
);
|
| 129 |
$form['block_name'] = array(
|
| 130 |
'#type' => 'value',
|
| 131 |
'#value' => $block->name
|
| 132 |
);
|
| 133 |
|
| 134 |
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $block->name)), 'admin/settings/thisdayinhistory/blocks', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
|
| 135 |
}
|
| 136 |
|
| 137 |
/**
|
| 138 |
* Deletes the specified block.
|
| 139 |
*/
|
| 140 |
function thisdayinhistory_block_delete_confirmation_submit($form, &$form_state) {
|
| 141 |
db_query("DELETE FROM {thisdayinhistory_blocks} WHERE bid = %d", $form_state['values']['bid']);
|
| 142 |
drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['block_name'])));
|
| 143 |
cache_clear_all();
|
| 144 |
|
| 145 |
$form_state['redirect'] = 'admin/settings/thisdayinhistory/blocks';
|
| 146 |
return;
|
| 147 |
}
|