View source
<?php
function date_tools_help($section, $arg) {
switch ($section) {
case 'admin/structure/date':
return '<p>' . t('Tools for creating and importing dates and calendars.') . '</p>';
case 'admin/structure/date/change':
return '<p>' . t('Change a date field from one type to another. Very experimental, use at your own risk!') . '</p>';
case 'admin/structure/date/date_wizard':
$output = t('Fill out the following form to auto-create a date content type, with a datetime field and matching pre-configured calendar. A calendar and upcoming events block will be created, an ical feed will be added to the calendar, and the mini calendar, calendar legend, and upcoming events blocks will be added to the sidebar of the default theme. Nodes created from this new content type will include a link to the calendar, and the calendar will have a link to the \'add new date\' form. You can also add new date fields to an existing content type by entering the existing content type name instead of creating a new one.') . '</p><p>' . t('Only a limited set of options are displayed here to make this easy to set up. Once the date has been created you will be able to make other changes to the date settings and add other fields to your new content type on the Manage fields screen, and make changes to the calendar on the Views edit page.') . '</p>';
return $output;
}
}
function date_tools_permission() {
return array(
'administer date tools' => array(
'title' => t('Administer date tools'),
),
);
}
function date_tools_menu() {
$items = array();
$items['admin/structure/date'] = array(
'title' => 'Date Tools',
'description' => 'Tools to import and auto-create dates and calendars. ',
'access arguments' => array(
'administer date tools',
),
'page callback' => 'date_tools_page',
);
$items['admin/structure/date/about'] = array(
'title' => 'About',
'description' => 'Tools to import and auto-create dates and calendars. ',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -5,
'page callback' => 'date_tools_page',
'access arguments' => array(
'administer date tools',
),
);
$items['admin/structure/date/date_wizard'] = array(
'title' => 'Date wizard',
'description' => 'Easy creation of date content types and calendars. ',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'date_tools_wizard_form',
),
'access arguments' => array(
'administer date tools',
),
'file' => 'date_tools.wizard.inc',
);
$items['admin/structure/date/remove'] = array(
'title' => 'Remove calendar',
'access arguments' => array(
'administer date tools',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'date_tools_remove_form',
3,
),
'type' => MENU_CALLBACK,
);
$items['admin/structure/date/change'] = array(
'title' => 'Change type',
'access arguments' => array(
'administer date tools',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'date_tools_change_type_form',
),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
'file' => 'date_tools.change_type.inc',
);
return $items;
}
function date_tools_page() {
$choices = array();
$choices[] = t('Dates and calendars can be complicated to set up. The !date_wizard makes it easy to create a simple date content type and related calendar. ', array(
'!date_wizard' => l(t('Date wizard'), 'admin/structure/date/date_wizard'),
));
$content = '<ul><li>' . implode('</li><li>', $choices) . '</li></ul>';
if (module_exists('calendar')) {
$calendar_options = variable_get('calendar_default_view_options', array());
$calendars = array();
$node_types = node_type_get_names();
foreach ($calendar_options as $key => $option) {
$bundle = str_replace('calendar_', '', $key);
if (array_key_exists($bundle, $node_types)) {
$type = $node_types[$bundle];
$calendars[] = array(
l($type, 'admin/structure/types/manage/' . $bundle . '/fields'),
l($key, 'admin/structure/views/edit/' . $key),
t('The calendar %view is a default calendar created for the content type %bundle. ', array(
'%view' => $key,
'%bundle' => $type,
)),
l(t('remove !view', array(
'!view' => $key,
)), 'admin/structure/date/remove/' . $key),
);
}
else {
calendar_remove($bundle);
}
}
if (!empty($calendars)) {
$header = array(
t('Content Type'),
t('Calendar'),
t('Description'),
t('Operations'),
);
$content .= theme('table', array(
'header' => $header,
'rows' => $calendars,
));
}
}
return $content;
}
function date_tools_remove_form(&$form_state, $view_name) {
$form = array();
$form['view_name'] = array(
'#type' => 'value',
'#value' => $view_name,
);
$output = confirm_form($form, t('Are you sure you want to remove the view %view?', array(
'%view' => $view_name,
)), 'admin/structure/date', t('This action cannot be undone.'), t('Remove'), t('Cancel'));
return $output;
}
function date_tools_remove_form_submit($form, &$form_state) {
$form_values = $form_state['values'];
$view_name = $form_values['view_name'];
if ($view_name && $form_values['confirm']) {
calendar_remove($view_name);
drupal_set_message(t('Removed calendar %calendar. ', array(
'%calendar' => $view_name,
)));
}
$form_state['redirect'] = 'admin/structure/date';
}