<?php
// $Id: basicevent.module,v 1.7.2.1 2006/05/08 20:55:21 killes Exp $

/**
 * @file
 * An extremly simple module to implement the event API.
 */

/**
 * Implementation of hook_help().
 */
function basicevent_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('A story-like node that implements the event API automatically. Depends on the event module (4.6 or later).');
    case 'node/add#event':
      return t('An event is a story which can be given a start and end date, thus appearing in the events calendar.');
  }
}

/**
 * Implementation of hook_node_info().
 */
function basicevent_node_info() {
  return array('event' => array('name' => t('event'), 'base' => 'basicevent'));
}

/**
 * Implementation of hook_perm().
 */
function basicevent_perm() {
  return array('create events', 'edit own events');
}

/**
 * Implementation of hook_access().
 */
function basicevent_access($op, $node) {
  global $user;
  switch($op) {
    case 'create':
      return user_access('create events');
      break;
    case 'update':
    case 'delete':
      if (user_access('edit own events') && ($user->uid == $node->uid)) {
        return TRUE;
      }
      break;
  }
}

/**
 * Implementation of hook_menu().
 */
function basicevent_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $items[] = array('path' => 'node/add/event', 'title' => t('event'),
      'access' => user_access('create events'));
  }

  return $items;
}

/**
 * Implementation of hook_form().
 */
function basicevent_form(&$node) {
  // warn them if this isn't set to appear in the calendar
  if (variable_get('event_nodeapi_event', 'never') == 'never') {
    $link = l(t('event content-type settings page'), 'admin/settings/content-types/event');
    drupal_set_message(t('The event node is currently set to never appear in the calendar. You will not be able to set the start and end dates until an administrator changes the content-type settings. This is done using the %link.', array('%link' => $link)));
  }

  $form['title'] = array(
    '#type' => 'textfield', 
    '#title' => t('Title'), 
    '#default_value' => $node->title, 
    '#size' => 60, 
    '#maxlength' => 128, 
    '#required' => TRUE
  );
  $form['body_filter']['body'] = array(
    '#type' => 'textarea', 
    '#title' => t('Body'), 
    '#default_value' => $node->body, 
    '#required' => TRUE
  );
  $form['body_filter']['format'] = filter_form($node->format);
  return $form;
}
