Events
Eingetragen von Hinrich (136)
am 19.09.2005 - 18:26 Uhr in
am 19.09.2005 - 18:26 Uhr in
Hallo,
derzeit richte ich eine Site unter Drupal ein. Wesentlich ist dabei für mich eine zumindest listenartige Erfassung und Darstellung von Terminen (ganztags). Da das letzte Release von Drupal nicht mit PHP 5.0.5 arbeitet, habe ich die CVS-Version genommen, bei der der Fehler mit den Referenzen beseitigt ist. So weit, so schlecht. Wenn ich das Modul event installiere, bricht Drupal mit einem Memory-Overflow ab (menu.module:215).
Gibt es ein anderes kleines Modul, dass obige Anforderung erfüllt? Oder einen Patch für das Problem?
Danke für die Info.
- Anmelden oder Registrieren um Kommentare zu schreiben
ob es einen Patch für das
am 20.09.2005 - 07:26 Uhr
ob es einen Patch für das event Modul gibt kannst du am ehesten bei dem Schöpfer erfragen drupal.org user profile : gerhard killesreiter
MfG Micha
- work in progress mit Langmi.de
Alternatives Modul
am 26.09.2005 - 12:18 Uhr
Das Problem mit dem Speicher ist gelöst.
Aber nochmal die Frage nach einem alternativen Modul. Das event-Modul macht mich nicht so wirklich glücklich.
Hallo Hinrich, beschreibe
am 26.09.2005 - 19:49 Uhr
Hallo Hinrich,
beschreibe doch dein Problem mal näher.
Was genau gefällt dir nicht am Event-Modul? Welche speziellen Anforderungen kann das Event-Modul nicht erfüllen?
Grüße
Björn
Misslich
am 26.09.2005 - 22:52 Uhr
Hallo Björn,
zum einen erscheint in der Artikelübersicht bei allen Artikeln ein "Startdatum", was lästig ist. Weiter kann man keine Tages-Events anlegen, um die es mir aber vorrangig geht (da ist die Uhrzeit störend). Der Block zeigt zwar an, wie viele Tage es noch hin ist, bis ein Event erreicht wird, aber das Datum verschweigt er (Listenansicht).
Was ich brauche, ist nur eine chronologisch sortierte Liste von Terminen, die einen oder mehrere Tage dauern. Die Uhrzeit ist irrelevant, und die beste Darstellungsform für solche Termine (Veranstaltungen, die immer einen Tag dauern) ist eine Liste. Auch diesen Minimalissmus lässt sich das Modul leider nicht bringen.
Hinrich
Events
am 27.09.2005 - 04:09 Uhr
Ansich könntest du doch einfach eine entsprechende Kategorie anlegen, zB. Kategorie: Events, und dann die Artikel während des Eintrags manuell datieren. Man kann einen Artikel auch für zukünftige Termine eintragen, wobei dann der jeweils neueste als erster erscheint. Funktionieren tut das. Man könnte es auch mit dem Kalender verbinden.
mfg holger
www.ebec.net | www.stnetwork.de
Beste Grüße, Holger
---
IT-News und IT-Jobs auf w3Projekt.com
Flickwerk
am 27.09.2005 - 08:18 Uhr
Das könnte man, aber es wäre doch wohl nur Flickwerk.
Ich werde wohl was basteln müssen...
Kein Flickwerk mehr
am 28.09.2005 - 19:23 Uhr
So, ich habe mir was gebastelt. Zu sehen unter http://jagdparcours.info/termine.html (falls es jemanden interessiert).
Das ganze Teil ist zwar Quick & Dirty, aber es tut, was ich will. Und darauf kommt es mir an.
Sollte es jemanden interessieren, möge er sich melden.
Ja, mich interessiert´s
am 28.09.2005 - 19:26 Uhr
Ja, mich interessiert´s sehr! Ich bitte hiermit freundlichst um Erläuterung!
Grüße
Björn
Das Modul
am 28.09.2005 - 21:14 Uhr
Nun denn, das Modul ist für Drupal entwickelt. Die Funktionen werden über _menu implementiert, wobei die Service-Funktionen über die Callback-Methode erreicht werden.
Es hat mich rund 5 Stunden gekostet, dieses Q&D-Modul zu erstellen, was im Grunde deutlich macht, wie einfach die Entwicklung von Modulen für Drupal ist, bedenkt man, dass ich mich mit dem System seit einer Woche auseinander setze.
Ein ähnliches Modul hatte ich vor Jahren mal für PostNuke entwickelt, so dass mir die Systematik von Drupal schnell in den Kopf ging, da mir Hooks dadurch vertraut sind. Mal abgesehen vom Resourcen-Hunger gefällt mir das System gut.
Wer Spass daran hat, mag sich den Source antun, der aber sicher nicht State-Of-The-Art ist, sondern mehr an einen 1980er Nudel-Source erinnert.
Das Modul dient zwar für Termine im Schießsport, lässt sich aber sicher mit wenigen Handgriffen auf anderen, listenmäßige Termine anpassen. Man muss ja nicht den Source oder die Datenbank ändern, sondern kann einfach die Übersetzung verändern. Und die Strings für Disziplin und Ziele lassen sich über die Einstellungen anpassen. Eine Anwendung um beispielsweise Weihnachtsmärkte zu erfassen, lässt sich ausschließlich über diese Methoden erstellen.
Ach ja, wer den Source nicht mag, schweigt bitte. Das Modul insgesamt will ich eigentlich unter drupal.org veröffentlichen, denn hier gibt es ja keine Projekte (Zaun-Wink)...
/* $Id$ */
/**
* Project: shootevents
* File: shootevents.module
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @link http://drupal.org/
* @copyright 2005 TIRO Communication
* @author Hinrich Donner <hd at tiro-communication dot net>
* @package shootevents
* @version 0.1.1
*/
/*
* Some definitions. There is no need to change it here. Use the settings...
*/
define('SHOOTEVENTS_DIS_DEFAULT', 'Compak-Sporting,Doubles,Parcours de Chasse,ZZ');
define('SHOOTEVENTS_TARGETS_DEFAULT', '25,50,75,100,125,150,200,250,300');
define('SHOOTEVENTS_MAXDISP_BLOCK', 7);
define('SHOOTEVENTS_MAXDISP_LIST', 25);
define('SHOOTEVENTS_DATE_SHORT', '%d.%m.%y');
define('SHOOTEVENTS_DATE_LONG', '%e. %B %Y');
/**
* Initialize Module
*/
function shootevents_init()
{
$path = drupal_get_path('module', 'shootevents');
$css = $path . '/shootevents.css';
theme_add_style($css);
}
/**
* Bind Menu Items
* @return array
*/
function shootevents_menu()
{
$items = array();
$items[] = array('path' => 'shootevents',
'title' => t("shoot events"),
'callback' => '_shootevents_all',
'access' => user_access('access shootevents'),
'type' => MENU_NORMAL_ITEM);
$items[] = array('path' => 'shootevents/add',
'title' => t("add a shoot events"),
'callback' => '_shootevents_add',
'access' => user_access('create shootevents'),
'type' => MENU_NORMAL_ITEM);
$items[] = array('path' => 'shootevents/view',
'title' => t("shoot events"),
'callback' => '_shootevents_all',
'access' => user_access('access shootevents'),
'type' => MENU_CALLBACK);
$items[] = array('path' => 'shootevents/modify',
'title' => t("edit a shoot events"),
'callback' => '_shootevents_modify',
'access' => user_access('create shootevents'),
'type' => MENU_CALLBACK);
$items[] = array('path' => 'shootevents/delete',
'title' => t("delete a shoot events"),
'callback' => '_shootevents_delete',
'access' => user_access('create shootevents'),
'type' => MENU_CALLBACK);
return $items;
}
/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function shootevents_help($section = '')
{
$output = '';
switch ($section)
{
case "admin/modules#description":
$output = t("Displays a list of shooting events");
break;
case "admin/help#shootevents":
$output = t("This module manage a simple list of shooting events.");
break;
}
return $output;
}
/**
* Set Up Access Levels
*/
function shootevents_perm()
{
return array('access shootevents',
'create shootevents',
'administer shootevents');
}
/*
* Cron
*/
function shootevents_cron()
{
// Delete expired entries
//
$sql = sprintf("DELETE FROM {shootevents} WHERE start<'%s'", strftime("%Y-%m-%d", time()));
db_query(db_rewrite_sql($sql));
}
/**
* Generate HTML for the shootevents block
* @param op the operation from the URL
* @param delta offset
* @returns block HTML
*/
function shootevents_block($op = 'list', $delta = 0)
{
// listing of blocks, such as on the admin/block page
if ($op == "list")
{
$block[0]["info"] = t('Shooting events');
return $block;
}
else
{
// Check access
if (!user_access('access shootevents'))
return array();
// Load items
//
$lim = variable_get("shootevents_maxdisp_block", SHOOTEVENTS_MAXDISP_BLOCK);
$sql = sprintf("SELECT e.name, e.start, e.dis, e.targets FROM {shootevents} e WHERE e.start>='%s' ORDER BY e.start ASC",
strftime('%Y-%m-%d', time()));
$dbr = db_query_range(db_rewrite_sql($sql), 0, $lim);
if (db_num_rows($dbr) == 0)
{
return array();
}
else
{
// Prepare output
//
$_dark = false;
$format = variable_get("shootevents_date_short", SHOOTEVENTS_DATE_SHORT);
$content = "<table class=\"block-shootevents\">\n";
while ($row = db_fetch_object($dbr))
{
$dark = ($_dark ? 'dark' : 'light');
$_dark = !$_dark;
$content .= "<tr class=\"$dark\">"
. "<td class=\"$dark\"><strong>"
. strftime($format, _shootevents_convert_date($row->start, true))
. ":</strong> " . check_plain($row->name) . "<br /><small>"
. sprintf(t("%s targets %s"), check_plain($row->targets), check_plain($row->dis))
. "</small></td>\n</tr>\n";
}
$content .= "</table>\n";
}
// our block content
$block['subject'] = t("Upcoming Events");
$block['content'] = $content
. "<div class=\"more-link\">".
l(t("more"), "shootevents", array("title" => t("More events...")))
."</div>";
return $block;
}
}
/**
* Module configuration settings
* @return settings HTML or deny access
*/
function shootevents_settings()
{
// only administrators can access this module
if (!user_access('administer shootevents'))
return message_access();
// $limitnum = variable_get("onthisdate_maxdisp", 3);
$output = '';
$output .= "<p>" . t("Remember to customize the style sheet stored in <em>shootevents.css</em> in your module directory.") . "</p>\n";
$output .= "<h2>" . t("General Settings") . "</h2>\n"
. "<p>" . t("Set up some properties for the block settings.") . "</p>";
$output .= form_textfield(t("Disciplines"),
"shootevents_dis",
variable_get("shooterevents_dis", SHOOTEVENTS_DIS_DEFAULT),
60,
65535,
t("Define the possible disciplines. Each discipline has to be seperated by comma."),
null,
true);
$output .= form_textfield(t("Targets"),
"shootevents_targets",
variable_get("shooterevents_targets", SHOOTEVENTS_TARGETS_DEFAULT),
60,
65535,
t("Define the possible number of targets. Each value has to be seperated by comma."),
null,
true);
$output .= "<h2>" . t("Block Settings") . "</h2>\n"
. "<p>" . t("Set up some properties for the block settings.") . "</p>";
$output .= form_textfield(t("Maximum number of events in the block"),
"shootevents_maxdisp_block",
variable_get("shootevents_maxdisp_block", SHOOTEVENTS_MAXDISP_BLOCK),
3,
3,
t("The maximum number of links to display in the block."));
$output .= form_textfield(t("Date format"),
"shootevents_date_short",
variable_get("shootevents_date_short", SHOOTEVENTS_DATE_SHORT),
25,
255,
t("The date format in the block.") . ' ' . t("Refer PHP manual for strftime() to learn more about the format."),
null,
true);
$output .= "<h2>" . t("List Settings") . "</h2>\n"
. "<p>" . t("Set up some properties for the list.") . "</p>";
$output .= form_textfield(t("Maximum number of events on the list"),
"shootevents_maxdisp_list",
variable_get("shootevents_maxdisp_list", SHOOTEVENTS_MAXDISP_LIST),
3,
3,
t("The maximum number of links to display on the list."));
$output .= form_textfield(t("Date format"),
"shootevents_date_long",
variable_get("shootevents_date_long", SHOOTEVENTS_DATE_LONG),
25,
255,
t("The date format in the list.") . ' ' . t("Refer PHP manual for strftime() to learn more about the format."),
null,
true);
$output .= form_checkbox(t("Show supporter"),
"shootevents_show_supporter",
1,
variable_get("shootevents_show_supporter", 1),
t("If checked, the username of the user who has inserted the event is shown."));
return $output;
}
/**
* Display Function For The List
*/
function _shootevents_all($offset = 0)
{
// only administrators can access this module
if (!user_access('access shootevents'))
{
drupal_set_message(message_access(), 'error');
drupal_goto('node');
}
$content = '';
$content .= "<div class=\"shootevents\">\n";
$lim = variable_get("shootevents_maxdisp_list", SHOOTEVENTS_MAXDISP_LIST);
$sql = sprintf("SELECT e.*, u.name username FROM {shootevents} e, {users} u WHERE e.start>='%s' AND e.uid=u.uid ORDER BY e.start ASC",
strftime('%Y-%m-%d', time()));
$dbr = db_query_range(db_rewrite_sql($sql), (int) $offset, $lim);
if (db_num_rows($dbr) == 0)
{
$content .= "<p>" . t("At this time we do not have any event in the database.") . "</p>\n";
}
else
{
global $user;
// Build output
//
$fmt = variable_get("shootevents_date_long", SHOOTEVENTS_DATE_LONG);
$show_supporter = variable_get("shootevents_show_supporter", true);
$_dark = false;
$path = drupal_get_path('module', 'shootevents');
$content .= "<table class=\"shootevents\">\n"
. "<tr>\n"
. "<th>" . t("Date") . "</th>\n"
. "<th>" . t("Event") . "</th>\n"
. "<th>" . t("Federation") . "</th>\n"
. "</tr>\n";
while ($row = db_fetch_object($dbr))
{
$dark = ($_dark ? 'dark' : 'light');
$_dark = !$_dark;
$edit_img = "<img src=\"$path/edit.gif\" alt=\"" . t("edit") . "\" title=\"".t("Edit this event")."\" />";
$edit_x_img = "<img src=\"$path/edit_x.gif\" alt=\"" . t("edit impossible") . "\" title=\"".t("You cannot edit this event")."\" />";
$delete_img = "<img src=\"$path/delete.gif\" alt=\"" . t("delete") . "\" title=\"".t("Delete this event")."\" />";
$delete_x_img = "<img src=\"$path/delete_x.gif\" alt=\"" . t("delete impossible") . "\" title=\"".t("You cannot delete this event")."\" />";
$edit = "<a href=\"" . url(sprintf('shootevents/modify/%u', $row->id)) . "\">$edit_img</a>";
$edit_x = $edit_x_img;
$delete = "<a href=\"" . url(sprintf('shootevents/delete/%u', $row->id)) . "\">$delete_img</a>";
$delete_x = $delete_x_img;
// Build location string
//
if (empty($row->location) && !empty($row->country))
$location = check_plain($row->country) . '<br />';
elseif (!empty($row->location) && empty($row->country))
$location = check_plain($row->location) . '<br />';
elseif (empty($row->location) && empty($row->country))
$location = '';
else
$location = check_plain($row->location) . ' (' . check_plain($row->country) . ')<br />';
// build federeation link
//
if (empty($row->org_url))
$org = check_plain($row->org);
else
$org = "<a href=\"" . $row->org_url . "\" target=\"_blank\" title=\""
. sprintf(t("Visit homepage of %s"), check_plain($row->org))
. "\">" . check_plain($row->org) . "</a>";
$content .= "<tr class=\"$dark\">\n"
. "<td class=\"dark\" nowrap>"
. "<strong>" . strftime($fmt, _shootevents_convert_date($row->start, true));
if (strcmp('0000-00-00', $row->end))
$content .= "<br /> - "
. strftime($fmt, _shootevents_convert_date($row->end, true));
$content .= "</strong>"
. "</td>\n"
. "<td class=\"dark\">";
if ((user_access('create shootevents') && ($user->uid == $row->uid))
|| user_access('administer shootevents'))
$content .= $delete . $edit;
elseif (user_access('create shootevents'))
$content .= $delete_x . $edit_x;
$content .= "<strong>" . check_plain($row->name) . "</strong><br />\n<small>"
. sprintf(t("%s, %s targets"), check_plain($row->dis), check_plain($row->targets)) ."<br />\n"
. $location
. ($show_supporter ? t("Reported by ") . check_plain($row->username) : '')
. "</small></td>\n"
. "<td class=\"dark\">$org"
. "</td>\n"
. "</tr>\n";
}
$content .= "</table>\n";
// Build paginator
//
$sql = sprintf("SELECT COUNT(*) rows FROM {shootevents} WHERE start>='%s'",
strftime('%Y-%m-%d', time()));
$row = db_fetch_array(db_query_range(db_rewrite_sql($sql), 0, 1));
$rows = $row['rows'];
$offsets = array();
for ($i = 0; $i < $rows; $i += $lim)
$offsets[] = $i;
if (count($offsets) > 1)
{
$content .= '<div class=\"shootevents-pager\"><p>' . t("Pages") . ': ';
$first = true;
foreach ($offsets as $page => $new_offset)
{
if (!$first)
$content .= ', ';
if ($new_offset == $offset)
$content .= "<em>" . sprintf('%u', $page+1) . "</em>";
elseif ($new_offset == 0)
$content .= l(sprintf('%u', $page+1),
sprintf('shootevents', $new_offset));
else
$content .= l(sprintf('%u', $page+1),
sprintf('shootevents/view/%u', $new_offset));
$first = false;
}
}
$content .= "</p></div>\n";
}
if (user_access('create shootevents'))
{
$content .= "<h2>" . t("Information") . "</h2>"
. '<p>'
. t("You are allowed to create new events.") . ' ';
if (user_access('administer shootevents'))
$content .= t("You are able to modify and delete all events in the database.");
else
$content .= t("You are able to modify and delete the events you have submitted later.");
$content .= '</p>';
$content .= '<p>' . t("On deletion <strong>no</strong> further confirmation will be requested.") . '</p>';
}
$content .= "</div>\n";
print theme("page", $content);
}
/**
* Display Function For The List
*/
function _shootevents_modify($id)
{
// can access this module
if (!user_access('create shootevents'))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
global $user;
// Get the fields and save if possible
if (!strcmp('edit', $_POST['edit']['se_op']))
{
$se_id = (int) $_POST['edit']['se_id'];
$se_uid = (int) $_POST['edit']['se_uid'];
extract(_shootevents_get_validated_fields());
if (count(form_get_errors()) == 0)
{
// No errors, so store the entry
//
if (!user_access('administer shootevents') || !(($user->uid == $_POST['edit']['se_uid']) && user_access('create shootevents')))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
_shootevents_update($se_id, $se_uid, $se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url);
}
}
else
{
// First time, get data
//
$sql = sprintf("SELECT * FROM {shootevents} WHERE id='%u'", $id);
$dbr = db_query(db_rewrite_sql($sql));
if (db_num_rows($dbr) == 0)
{
drupal_set_message(t("Invalid id!"));
drupal_goto('shootevents');
}
$row = db_fetch_array($dbr);
if (!user_access('administer shootevents') || !(($user->uid == $row['uid']) && user_access('create shootevents')))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
// Init vars
foreach ($row as $field => $value)
{
$var = "se_$field";
$$var = $value;
}
// Beautify some vars
//
$se_start = strftime('%d.%m.%Y', _shootevents_convert_date($se_start, true));
$se_end = (strcmp('0000-00-00', $se_end)
? strftime('%d.%m.%Y', _shootevents_convert_date($se_end, true))
: '');
}
$form_content = _shootevents_get_form($se_name,
$se_start,
$se_end,
$se_dis,
$se_targets,
$se_location,
$se_country,
$se_org,
$se_org_url);
$form_content .= form_hidden('se_id', $se_id);
$form_content .= form_hidden('se_uid', $se_uid);
$form_content .= form_hidden('se_op', 'edit');
$form_content .= form_submit(t("Modify"));
$content = t("Please make your modifications in the form.");
$content .= form($form_content,
'post');
print theme("page", $content);
}
/**
* Display Function For The List
* @param int $id The Id
*/
function _shootevents_delete($id)
{
// can access this module
if (!user_access('create shootevents'))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
global $user;
$sql = sprintf("SELECT uid FROM {shootevents} WHERE id='%u'", $id);
$dbr = db_query(db_rewrite_sql($sql));
if (db_num_rows($dbr) == 0)
{
drupal_set_message(t("Invalid id!"));
drupal_goto('shootevents');
}
$row = db_fetch_object($dbr);
if (!user_access('administer shootevents') || !(($user->uid == $row->uid) && user_access('create shootevents')))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
$sql = sprintf("DELETE FROM {shootevents} WHERE id='%u'", $id);
if (db_query(db_rewrite_sql($sql)))
drupal_set_message(t("Event removed from database."));
else
drupal_set_message(t("An error occured while removing the event."), 'error');
drupal_goto('shootevents');
}
/**
* Display Function For The List
*/
function _shootevents_add()
{
// can access this module
if (!user_access('create shootevents'))
{
drupal_set_message(message_access(), 'error');
drupal_goto('shootevents');
}
// Get the fields and save if possible
if (!strcmp('add', $_POST['edit']['se_op']))
{
extract(_shootevents_get_validated_fields());
if (count(form_get_errors()) == 0)
{
// No errors, so store the entry
//
_shootevents_insert($se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url);
}
}
$form_content = _shootevents_get_form($se_name,
$se_start,
$se_end,
$se_dis,
$se_targets,
$se_location,
$se_country,
$se_org,
$se_org_url);
$form_content .= form_hidden('se_op', 'add');
$form_content .= form_submit(t("Add"));
$content = t("To add a shooting event fill out the form.");
$content .= form($form_content,
'post');
print theme("page", $content);
}
/**
* Validate A Date
* @param string $date The date in the format DD.MM.YYYY
* @return int The timestamp or FALSE on error
*/
function _shootevents_convert_date($date, $from_db = false)
{
if ($from_db)
list ($year,
$month,
$day) = explode('-', $date);
else
{
// Split
if (!preg_match("/([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})/", $date, $r))
return false;
list ($dummy, $day, $month, $year) = $r;
}
// Validate date itsself
if (!checkdate($month, $day, $year))
return false;
$result = mktime(0, 0, 0, $month, $day, $year);
return $result;
}
/**
* Return Timestamp Of the Current Day Without Time
* @return int
*/
function _shootevents_date()
{
static $result;
if (isset($result))
return $result;
$result = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
return $result;
}
function _shootevents_get_validated_fields()
{
// Validate data at all
//
if (!valid_input_data($_POST['edit']))
{
form_set_error('se_op', t("Your input ist not acceptable."));
return array();
}
// Required name
$se_name = trim($_POST['edit']['se_name']);
if (empty($se_name))
form_set_error('se_name', t("You must enter a name."));
// Validate date
$se_start = trim($_POST['edit']['se_start']);
$se_end = trim($_POST['edit']['se_end']);
if (empty($se_start))
form_set_error('se_start', t("You must enter the first day."));
elseif (false === ($_se_start = _shootevents_convert_date($se_start)))
form_set_error('se_start', t("The given date of the first day is invalid."));
elseif (_shootevents_date() > $_se_start)
form_set_error('se_start', t("You cannot set up an event in the past."));
elseif (!empty($se_end))
{
if (false === ($_se_end = _shootevents_convert_date($se_end)))
form_set_error('se_end', t("The date of the last day is invalid."));
elseif ($_se_end < $_se_start)
form_set_error('se_end', t("The last day must be later than the first day"));
}
$se_location = trim($_POST['edit']['se_location']);
$se_country = trim($_POST['edit']['se_country']);
$se_dis = trim($_POST['edit']['se_dis']);
$se_targets = trim($_POST['edit']['se_targets']);
$se_org = trim($_POST['edit']['se_org']);
$se_org_url = trim($_POST['edit']['se_org_url']);
if (!empty($se_org_url) && empty($se_org))
form_set_error('se_org', t("If an URL is given for the federation, you must enter the name of the federation as well."));
if (!empty($se_org_url) && !valid_url($se_org_url, true))
form_set_error('se_org_url', t("The format of the URL of the federation is invalid."));
return get_defined_vars();
}
/**
* Create An Array With Field Names And Values
* @return array
*/
function _shootevents_make_field_array($se_uid, $se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url)
{
$fields = array('name' => db_escape_string($se_name),
'uid' => db_escape_string($se_uid),
'start' => strftime('%Y-%m-%d', _shootevents_convert_date($se_start)),
'dis' => db_escape_string($se_dis),
'targets' => db_escape_string($se_targets));
if (!empty($se_end))
$fields['end'] = strftime('%Y-%m-%d', _shootevents_convert_date($se_end));
if (!empty($se_location))
$fields['location'] = db_escape_string($se_location);
if (!empty($se_country))
$fields['country'] = db_escape_string($se_country);
if (!empty($se_org))
$fields['org'] = db_escape_string($se_org);
if (!empty($se_org_url))
$fields['org_url'] = db_escape_string($se_org_url);
return $fields;
}
/**
* Insert A New Record
*/
function _shootevents_insert($se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url)
{
global $user;
$fields = _shootevents_make_field_array($user->uid,
$se_name,
$se_start,
$se_end,
$se_dis,
$se_targets,
$se_location,
$se_country,
$se_org,
$se_org_url);
$sql = "INSERT INTO {shootevents} (" . join(', ', array_keys($fields)) . ") VALUES ('" . join("', '", $fields) . "')";
if (db_query(db_prefix_tables($sql)))
drupal_set_message(sprintf(t("The event '%s' is saved."), check_plain($se_name)));
else
drupal_set_message(sprintf(t("An error occured while saving the event '%s'."), check_plain($se_name)), 'error');
drupal_goto('shootevents/add');
}
/**
* Update A Record
*/
function _shootevents_update($se_id, $se_uid, $se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url)
{
$fields = _shootevents_make_field_array($se_uid,
$se_name,
$se_start,
$se_end,
$se_dis,
$se_targets,
$se_location,
$se_country,
$se_org,
$se_org_url);
$sets = array();
foreach ($fields as $field => $value)
$sets[] = "$field='$value'";
$sql = sprintf("UPDATE {shootevents} SET " . join(', ', $sets) . "WHERE id='%u'", $se_id);
if (db_query(db_prefix_tables($sql)))
drupal_set_message(sprintf(t("The event '%s' is saved."), check_plain($se_name)));
else
drupal_set_message(sprintf(t("An error occured while saving the event '%s'."), check_plain($se_name)), 'error');
drupal_goto('shootevents');
}
/**
* Return The Formular
* @return string The HTML
*/
function _shootevents_get_form($se_name, $se_start, $se_end, $se_dis, $se_targets, $se_location, $se_country, $se_org, $se_org_url)
{
$err = form_get_errors();
$form_content = '';
$form_content .= form_textfield(t("Shooting event name"),
'se_name',
$se_name,
60,
255,
t("The name of the shooting event, e.g. <strong>F.I.T.A.S.C. World Championship</strong>."),
null,
true);
$form_content .= form_textfield(t("First day of the event"),
'se_start',
$se_start,
10,
10,
t("The first day of the shooting event."),
null,
true);
$form_content .= form_textfield(t("Last day of the event"),
'se_end',
$se_end,
10,
10,
t("The last day of the shooting event if it durate more than one day. Leave blank otherwise."));
$form_content .= form_select(t("Discipline"),
'se_dis',
$se_dis,
_shootevents_get_discipline_list(),
t("Select the discipline of the shooting event."));
$form_content .= form_select(t("Targets"),
'se_targets',
$se_targets,
_shootevents_get_target_list(),
t("Select number of targets of the shooting event."));
$form_content .= form_textfield(t("Location"),
'se_location',
$se_location,
60,
255,
t("The location of the shooting event, e.g. <strong>Jagdparcours Springe</strong>."));
$form_content .= form_textfield(t("Country"),
'se_country',
$se_country,
60,
255,
t("The country of the location of the shooting event, e.g. <strong>Germany</strong>."));
$form_content .= form_textfield(t("Federation"),
'se_org',
$se_org,
60,
255,
t("The organisating federation of the shooting event, e.g. <strong>F.I.T.A.S.C.</strong>."));
$form_content .= form_textfield(t("Federations website"),
'se_org_url',
$se_org_url,
60,
255,
t("The homepage of the organisating federation, e.g. <strong>http://www.fitasc.com</strong>."));
return $form_content;
}
/**
* Return A List Of Available Disciplines
* @return array
*/
function _shootevents_get_discipline_list()
{
static $result;
if (isset($result))
return $result;
// Select available disciplines
$_dis = explode(',', variable_get("shootevents_dis", SHOOTEVENTS_DIS_DEFAULT));
$result = array();
foreach ($_dis as $dis)
$result[$dis]= $dis;
return $result;
}
/**
* Return A List Of Available Target Numbers
* @return array
*/
function _shootevents_get_target_list()
{
static $result;
if (isset($result))
return $result;
// Select available disciplines
$_dis = explode(',', variable_get("shootevents_targets", SHOOTEVENTS_TARGETS_DEFAULT));
$result = array();
foreach ($_dis as $dis)
$result[$dis]= $dis;
return $result;
}
Re: Das Modul
am 29.09.2005 - 18:48 Uhr
Hallo Hinrich, danke für das Modul!
Ich find´s eigentlich ganz gut, wenn die Module zentral auf drupal.org veröffentlicht werden... ;-)
Grüße
Björn
Re: Das Modul
am 30.09.2005 - 00:19 Uhr
Hallo Hinrich, danke für das Modul!
Da nicht für.
Ich find´s eigentlich ganz gut, wenn die Module zentral auf drupal.org veröffentlicht werden...
Ja, das sehe ich auch so, allerdings habe ich es bisher noch nicht machen können. Offensichtlich unterliegt die Eintragung für Projekte der Moderation, was ich begrüße, und die Moderatoren machen gerade ein langes Wochenende.
Modul im CVS
am 29.11.2005 - 23:10 Uhr
Das Modul ist nun im CVS bei drupal.org (modules/shootevents).
Es läuft mit der aktuellen CVS-Version, vielleicht auch mit der 4.6.x.
Wer's mag und gebrauchen kann, melde sich mal, ansonsten ist es auch egal...