Objet : devel-adl
Archives de la liste
- From: svn AT agendadulibre.org
- To: devel AT agendadulibre.org
- Subject: [Devel] r431 - branches/dui
- Date: Sun, 1 Mar 2009 18:42:51 +0100 (CET)
- List-archive: <http://agendadulibre.org/pipermail/devel>
- List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>
Author: ldayot
Date: Sun Mar 1 18:42:50 2009
New Revision: 431
Log:
Prise en compte du nouvel objet event et de l'adresse des evenements.
Added:
branches/dui/requestinfosevent.php
Modified:
branches/dui/cancelevent.php
branches/dui/editevent.php
branches/dui/submit.php
Modified: branches/dui/cancelevent.php
==============================================================================
--- branches/dui/cancelevent.php Sun Mar 1 18:40:26 2009 (r430)
+++ branches/dui/cancelevent.php Sun Mar 1 18:42:50 2009 (r431)
@@ -1,7 +1,8 @@
<?php
-/* Copyright 2008
+/* Copyright 2008-2009
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -19,75 +20,68 @@
* 02111-1307, USA.
*/
-include("bd.inc.php");
+include("class.bd.inc.php");
include("funcs.inc.php");
-include("session.inc.php");
-include("user.inc.php");
+include("class.session.inc.php");
+include("class.user.inc.php");
include("diff.inc.php");
+$db = new db();
+include("class.event.inc.php");
function cancel_event ($db, $user, $id)
{
global $moderatorlist;
- $oldevent = fetch_event($db, $id);
- if (! $oldevent)
+ $oldevent = new event($db, $id);
+ if ($oldevent->error)
exit;
- $oldevent->tags = eventTagsList($oldevent->id);
-
- $sql = "delete from events where id=" . $id;
- $ret = $db->query ($sql);
- if ($ret == FALSE)
+ $oldevent->delete();
+ if ($oldevent->error)
{
- error ("La requête <i>" . $sql . "</i> a échoué");
- return -1;
+ error ($oldevent->message);
+ return false;
}
- $oldevent_str =
- format_ascii_event ($db, $oldevent->title,
date_mysql2timestamp($oldevent->start_time),
- date_mysql2timestamp($oldevent->end_time),
- $oldevent->description, $oldevent->city,
$oldevent->region, $oldevent->locality,
- $oldevent->url, $oldevent->contact,
$oldevent->submitter, $oldevent->tags);
-
if ($user)
$modifier = $user->get_login();
else
$modifier = "le soumetteur de l'évènement";
- calendar_mail ($moderatorlist, "",
- "Annulation de l'évènement '" .
stripslashes($oldevent->title) . "'",
+ $mailBody =
"Bonjour,\n\n" .
- wordwrap("L'évènement '" . stripslashes($oldevent->title) .
"' a été; annulé par " . $modifier . ".\n") .
+ wordwrap("L'évènement '" . stripslashes($oldevent->title) .
+ "' a été; annulé par " . $modifier . ".\n") .
"Détail de l'évènement annulé :\n\n" .
"=======================================================\n" .
- $oldevent_str . "\n".
+ $oldevent->formatAscii() . "\n".
"=======================================================\n\n" .
"Bonne journée,\n\n".
"-- L'équipe de modération");
+ calendar_mail ($moderatorlist, "",
+ "Annulation de l'évènement '" .
stripslashes($oldevent->title) . "'",
+ $mailBody);
}
-$db = new db();
-
$id = get_safe_integer('id', 0);
$secret = get_safe_hash('secret', false);
+$event = new event($db, $id);
+if ($event->error)
+{
+ put_header("Annulation d'un évènement");
+ error($event->message);
+ put_footer();
+ exit;
+}
+
if ($secret == FALSE)
{
$user = new user($db);
}
else
{
- $sql = "select id from events where id='" . $id . "' and secret='" .
$secret . "'";
- $ret = $db->query($sql);
- if ($ret == FALSE)
- {
- put_header("Annulation d'un évènement");
- error ("La requête <i>" . $sql . "</i> a échoué");
- put_footer();
- exit;
- }
-
- if (mysql_num_rows($ret) != 1)
+ if ($event->secret != $secret)
{
put_header("Annulation d'un évènement");
error("Hash d'identification non reconnu");
@@ -102,7 +96,7 @@
{
put_header("Annulation d'un évènement");
$ret = cancel_event ($db, $user, $id);
- if ($ret == 0)
+ if ($ret)
{
echo "<p>L'évènement a bien été
annulé. Il n'apparaît plus dans l'Agenda du Libre.</p>";
}
@@ -119,10 +113,10 @@
put_header("Annulation d'un évènement");
-$event = fetch_event($db, $id);
-if (! $event)
+$event = new event($db, $id);
+if ($event->error)
{
- error("Pas d'évènement avec cet ID");
+ error($event->message);
put_footer();
exit;
}
@@ -155,13 +149,12 @@
echo '</div>';
echo '<p class="moderationheader">';
-echo ($user ? "<a href=\"moderation.php\">Modération</a> " :
""). ">>> Visualisation de l'évènement";
+echo ($user ? "<a href=\"moderation.php\">Modération</a> " :
"").
+ ">>> Visualisation de l'évènement";
echo "</p>";
echo '<div class="moderationbox">';
-echo format_event ($db, $event->title, strtotime($event->start_time),
strtotime($event->end_time),
- $event->description, $event->city, $event->region,
$event->locality, $event->url,
- $event->contact, $event->submitter,
eventTagsList($event->id));
+echo $event->formatHTML();
echo '</div>';
put_footer();
Modified: branches/dui/editevent.php
==============================================================================
--- branches/dui/editevent.php Sun Mar 1 18:40:26 2009 (r430)
+++ branches/dui/editevent.php Sun Mar 1 18:42:50 2009 (r431)
@@ -1,7 +1,8 @@
<?php
-/* Copyright 2008
+/* Copyright 2008-2009
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,265 +21,139 @@
*/
include("text.inc.php");
-include("bd.inc.php");
+include("class.bd.inc.php");
+$db = new db();
include("funcs.inc.php");
-include("session.inc.php");
-include("user.inc.php");
+include("class.session.inc.php");
+include("class.user.inc.php");
include("diff.inc.php");
-$db = new db();
+include("class.event.inc.php");
-function save_event ($db, $user, $id, $title, $start, $end, $description,
$city,
- $region, $locality, $url, $contact, $submitter, $tags)
+function alertModerators ($event, $modifier, $diff)
{
global $moderatorlist;
- $oldevent = fetch_event($db, $id);
- if (! $oldevent)
- return -1;
-
- $oldevent->tags = eventTagsList($oldevent->id);
-
- $sql = "UPDATE events SET " .
- "title=" . $db->quote_smart ($title) . ", "
.
- "start_time=" . $db->quote_smart (date_timestamp2mysql ($start)) . ", ".
- "end_time=" . $db->quote_smart (date_timestamp2mysql ($end)) . ", ".
- "description=" . $db->quote_smart ($description) . ", ".
- "city=" . $db->quote_smart ($city) . ", ".
- "region=" . $db->quote_smart ($region) . ", ".
- "locality=" . $db->quote_smart ($locality) . ", ".
- "url=" . $db->quote_smart ($url) . ", ".
- "contact=" . $db->quote_smart ($contact) . ", ".
- "submitter=" . $db->quote_smart ($submitter) . /*",
".
- "tags=" . $db->quote_smart ($tags) . "
".*/
- "where id=" . $db->quote_smart ($id);
-
- $ret = $db->query ($sql);
-
- if ($ret == FALSE)
- {
- error ("La requête <i>" . $sql . "</i> a échoué");
- return -1;
- }
-
- // about tags
- $event_id = $id;
- // delete old
- $query = "DELETE FROM tags_events WHERE event_id='$event_id'";
- $db->query($query);
-
- // add new
- // manual tags
- $aTags = explode(" ", $tags);
- $aTagsKnown = array();
- // get tags which already exist
- $query = "SELECT id, name FROM tags WHERE name IN ('". implode("', '",
$aTags). "')";
- $result = $db->query($query);
- while ($record = $db->fetchObject($result))
+ if ($event->moderated)
{
- $aTagsKnown[]=$record->name;
- }
- // Insert new tags
- if (count($aTagsNew = array_diff($aTags, $aTagsKnown))>0)
- {
- $query = "INSERT INTO tags (name) VALUES ('". implode("'), ('",
$aTagsNew). "')";
- $db->query($query);
- }
- // make link between event and tags
- $query = "INSERT INTO tags_events (event_id, tag_id) SELECT {$event_id},
id FROM tags WHERE name IN ('". implode("','", $aTags). "')";
- $result = $db->query($query);
-
- // may check if old tags are almost used, if not, delete them
-
- $oldevent_str =
- format_ascii_event ($db, $oldevent->title,
date_mysql2timestamp($oldevent->start_time),
- date_mysql2timestamp($oldevent->end_time),
- $oldevent->description, $oldevent->city, $oldevent->region,
$oldevent->locality,
- $oldevent->url, $oldevent->contact, $oldevent->submitter,
$oldevent->tags);
- $newevent_str =
- format_ascii_event ($db, $title, $start, $end,
- $description, $city, $region, $locality,
- $url, $contact, $submitter, $tags);
-
- $diff = @arr_diff (split ("\n", $oldevent_str), split ("\n",
$newevent_str), 1);
-
- if ($user)
- $modifier = $user->get_login();
- else
- $modifier = "le soumetteur de l'évènement";
-
-if ($oldevent->moderated)
- {
- calendar_mail ($moderatorlist, "",
- "Édition de l'évènement validé '" . $title . "'",
- "Bonjour,\n\n" .
- wordwrap("L'évènement validé '" . stripslashes($title) . "' a été
modifié par " . $modifier . ".\n") .
+ $mail_title = "Édition de l'évènement validé '" . $event->title . "'";
+ $mail_body = "Bonjour,\n\n" .
+ wordwrap("L'évènement validé '" . stripslashes($event->title).
+ "' a été modifié par " . $modifier . ".\n") .
"Modifications apportées:\n\n" .
$diff . "\n\n".
"Bonne journée\n\n".
- "-- L'équipe de modération");
- return "showevent.php?id=" . $oldevent->id;
- }
+ "-- L'équipe de modération";
+ $return = "showevent.php?id=" . $event->id;
+ }
else
- {
- calendar_mail ($moderatorlist, "",
- "Édition de l'évènement '" . $title . "'",
- "Bonjour,\n\n" .
- "L'évènement '" . stripslashes($title) . "' a été modifié par " .
$modifier . ".\n".
+ {
+ $mail_title = "Édition de l'évènement '" . $event->title . "'";
+ $mail_body = "Bonjour,\n\n" .
+ "L'évènement '" . stripslashes($event->title).
+ "' a été modifié par " . $modifier . ".\n".
"Cet évènement est en attente de modération à l'adresse\n" .
- calendar_absolute_url("moderate.php#" . $id) . "\n\n".
+ calendar_absolute_url("moderate.php#" . $event->id) . "\n\n".
"Modifications apportées:\n\n" .
$diff . "\n\n".
"Bonne journée\n\n".
- "-- L'équipe de modération");
- return "moderation.php";
- }
- return 0;
+ "-- L'équipe de modération";
+ $return = "moderation.php";
+ } // end if else
+
+ calendar_mail($moderatorlist, "", $mail_title, $mail_body);
+
+ return $return;
}
+function updateEvent($user, $newEvent, $oldEvent)
+{
+ global $moderatorlist;
+
+ if (! $newEvent->submitter)
+ $newEvent->submitter = $newEvent->contact;
+
+ $newEvent->save();
+
+ $diff = @arr_diff (split ("\n", $oldEvent->formatAscii()),
+ split ("\n", $newEvent->formatAscii()), 1);
+
+ $modifier = $user ? $user->get_login() : "le soumetteur de l'évènement";
+
+ return alertModerators($newEvent, $modifier, $diff);
+} // end function
+
+
$id = get_safe_integer('id', 0);
$secret = get_safe_hash('secret', false);
+calendar_setlocale();
+
+// Get fields and store in $event object
+if (isset($_POST['__event_save']) || isset($_POST['__event_preview']))
+{
+ $updatedEvent = new event($db, 0);
+ $updatedEvent->id = $id;
+ $updatedEvent->fromForm();
+ // Check information, find city, postalcode and coordonnates
+ $ret = $updatedEvent->check();
+ $message = $updatedEvent->message;
+}
+
+$event = new event($db, $id);
+if ($event->error)
+{
+ put_header("Édition d'un évènement");
+ error($event->message);
+ put_footer();
+ exit;
+}
+
+// check secret, if not is user logon?
if ($secret == FALSE)
{
$user = new user($db);
}
else
-{
- $sql = "select id from events where id='" . $id . "' and secret='" .
$secret . "'";
- $ret = $db->query($sql);
- if ($ret == FALSE)
- {
- put_header("Édition d'un évènement");
- error ("La requête <i>" . $sql . "</i> a échoué");
- put_footer();
- exit;
- }
-
- if (mysql_num_rows($ret) != 1)
+{
+ if ($event->secret != $secret)
{
put_header("Édition d'un évènement");
error("Hash d'identification non reconnu");
put_footer();
exit;
}
-
$user = false;
}
-
-if (isset($_POST['__event_save']))
+if (isset($_POST['__event_save']) && $ret)
{
calendar_setlocale();
- $event_tags = $_POST['__event_tags'];
-
- foreach($_POST['tags'] as $aTags)
- if (is_array($aTags))
- $event_tags .= " ". implode(' ', $aTags);
- else
- $event_tags .= " ". $aTags;
- $event_tags = str_replace(" ", " ", $event_tags);
-
- $returnaddr = save_event ($db, $user, $id,
- $_POST['__event_title'],
- mktime($_POST['__event_start_hour'],
- $_POST['__event_start_minute'],
- 0,
- $_POST['__event_start_month'],
- $_POST['__event_start_day'],
- $_POST['__event_start_year']),
- mktime($_POST['__event_end_hour'],
- $_POST['__event_end_minute'],
- 0,
- $_POST['__event_end_month'],
- $_POST['__event_end_day'],
- $_POST['__event_end_year']),
- $_POST['__event_description'],
- $_POST['__event_city'],
- $_POST['__event_region'],
- $_POST['__event_locality'],
- $_POST['__event_url'],
- $_POST['__event_contact'],
- $_POST['__event_submitter'],
- $event_tags);
+ $returnaddr = updateEvent($user, $updatedEvent, $event);
if ($returnaddr === false)
{
- error ("Problème lors de la sauvegarde de
l'évènement <i>" . $_POST['__event_title'] . "</i>");
+ put_header("Édition d'un évènement");
+ error ("Problème lors de la sauvegarde de
l'évènement <i>".
+ $_POST['__event_title'] . "</i>");
}
if ($returnaddr != "")
header("Location: " . $returnaddr);
put_header("Édition d'un évènement");
- echo "<p>Les modifications sur l'évènement <i>" .
$_POST['__event_title'] . "</i> ont bien été
enregistrées.</p>";
+ if (isset($message) && $message!="")
+ echo $message;
+ echo "<p>Les modifications sur l'évènement <i>" .
+ $_POST['__event_title'] . "</i> ont bien été
enregistrées.</p>";
put_footer();
exit;
-
} // end if
-
put_header("Édition d'un évènement");
-$event = fetch_event($db, $_REQUEST["id"]);
-if (! $event)
-{
- echo "<p>Pas d'évènement avec cet ID</p>";
- put_footer();
- exit;
-}
-
-if (isset($_POST['__event_preview']))
-{
- calendar_setlocale();
-
- $event_tags = $_REQUEST['__event_tags'];
- foreach($_POST['tags'] as $aTags)
- if (is_array($aTags))
- $event_tags .= " ". implode(' ', $aTags);
- else
- $event_tags .= " ". $aTags;
- $event_tags = str_replace(" ", " ", $event_tags);
-
- $id = $_REQUEST["id"];
- $title = $_POST['__event_title'];
- $start = mktime($_POST['__event_start_hour'],
- $_POST['__event_start_minute'],
- 0,
- $_POST['__event_start_month'],
- $_POST['__event_start_day'],
- $_POST['__event_start_year']);
- $end = mktime($_POST['__event_end_hour'],
- $_POST['__event_end_minute'],
- 0,
- $_POST['__event_end_month'],
- $_POST['__event_end_day'],
- $_POST['__event_end_year']);
- $description = $_POST['__event_description'];
- $city = $_POST['__event_city'];
- $region = $_POST['__event_region'];
- $locality = $_POST['__event_locality'];
- $url = $_POST['__event_url'];
- $contact = $_POST['__event_contact'];
- $submitter = $_POST['__event_submitter'];
- $tags = $event_tags;
-}
-else
-{
- $id = $event->id;
- $title = $event->title;
- $start = strtotime($event->start_time);
- $end = strtotime($event->end_time);
- $description = $event->description;
- $city = $event->city;
- $region = $event->region;
- $locality = $event->locality;
- $url = $event->url;
- $contact = $event->contact;
- $submitter = $event->submitter;
- $tags = eventTagsList($id);
-}
+if (isset($message) && $message!="") echo $message;
echo '<p class="moderationheader">';
echo ($user ? "<a href=\"moderation.php\">Modération</a> " : "").
@@ -292,11 +167,12 @@
echo '</div>';
}
-echo '<div class="moderationbox">';
-echo format_event ($db, $title, $start, $end, $description, $city,
- $region, $locality, $url, $contact, $submitter,
- $tags);
-echo '</div>';
+if (isset($updatedEvent))
+{
+ echo '<div class="moderationbox">';
+ echo $updatedEvent->formatHTML();
+ echo '</div>';
+}
echo '<p class="moderationheader">';
echo ($user ? "<a href=\"moderation.php\">Modération</a> " : "").
@@ -305,16 +181,12 @@
echo '<div class="moderationbox">';
-if ($user)
- $posturl = "?id=" . $id;
-else
- $posturl = "?id=" . $id . "&secret=" . $secret;
+$posturl = "?id=" . $id. ($user ? "" : "&secret=" . $secret);
-echo "<form action=\"" . $posturl . "\" method=\"post\">\n";
-edit_event ($db, $title, $start, $end, $description, $city,
- $region, $locality, $url, $contact, $submitter,
- $tags, TRUE);
-echo "</form>\n";
+if (isset($updatedEvent))
+ $updatedEvent->edit(true, true, $posturl);
+else
+ $event->edit(true, true, $posturl);
echo '</div>';
put_footer();
Added: branches/dui/requestinfosevent.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/dui/requestinfosevent.php Sun Mar 1 18:42:50 2009 (r431)
@@ -0,0 +1,137 @@
+<?php
+
+/* Copyright 2008-2009
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+include("text.inc.php");
+include("class.bd.inc.php");
+include("funcs.inc.php");
+$db = new db();
+include("class.session.inc.php");
+include("class.user.inc.php");
+$user = new user($db);
+include("class.event.inc.php");
+
+
+if (isset($_POST['__event_requestinfo_cancel']))
+{
+ header("Location: moderation.php");
+ exit;
+}
+else if (isset($_POST['__event_requestinfo_send']))
+{
+ $id = get_safe_integer('id', 0);
+
+ $event = new event($db, $id);
+ if ($event->error || $event->moderated)
+ {
+ put_header();
+ echo "<p>Opération interdite</p>";
+ error($event->message);
+ put_footer();
+ exit;
+ }
+
+ $text =
+ "Bonjour,\n\n" .
+ "Nous avons bien reçu votre proposition d'évènement
'" .
+ stripslashes($event->title) . "', et celui-ci a toute sa " .
+ "place dans $adl_title. Néanmoins, avant d'être " .
+ "validé, nous avons besoin de quelques informations " .
+ "complémentaires sur cet évènement :\n\n" .
+ stripslashes($_POST["__text"]) . "\n\n" .
+ "Nous vous invitons à ajouter ces informations en éditant
" .
+ "directement l'évènement à l'adresse suivante :
\n\n" .
+ calendar_absolute_url("editevent.php?id=" . $event->id
+ . "&secret=" . $event->secret) . "\n\n" .
+ "Avec tous nos remerciements pour votre contribution,\n\n" .
+ "-- \n" .
+ "L'équipe des modérateurs de $adl_title.";
+
+ $text = wordwrap($text);
+
+ calendar_mail($event->submitter, $moderatorlist,
+ "Demande d'informations sur l'évènement '" .
+ stripslashes($event->title) . "'", $text);
+
+ header("Location: moderation.php");
+}
+
+$id = get_safe_integer('id', 0);
+
+put_header("Demande d'informations sur un évènement");
+
+$event = new event($db, $id);
+if ($event->error)
+{
+ error($event->message);
+ put_footer();
+ exit;
+}
+
+if ($event->moderated)
+{
+ echo "<p>Évènement déjà
modéré</p>";
+ put_footer();
+ exit;
+}
+
+echo '<p class="moderationheader">';
+echo "<a href=\"moderation.php\">Modération</a>".
+ " >>> Demande d'informations sur
l'évènement";
+echo "</p>";
+
+?>
+
+<div class="moderationbox">
+<h2>Rédaction du message</h2>
+
+<form action="requestinfosevent.php?id=<?php echo $id ?>" method="post">
+<p>Bonjour,</p>
+
+<p>Nous avons bien reçu votre proposition d'évènement
'<? echo
+$event->title; ?>', et celui-ci a toute sa place dans <?php echo $adl_title;
?>.
+Néanmoins, avant d'être validé, nous avons besoin de
quelques
+informations complémentaires sur cet évènement :</p>
+
+<textarea id="__text" cols="80" rows="10" name="__text"></textarea>
+
+<p>Nous vous invitons à ajouter ces informations en éditant
directement
+l'évènement à l'adresse suivante :</p>
+
+<p><?php echo calendar_absolute_url("editevent.php?id=" . $event->id
+. "&secret=" . $event->secret) ?></p>
+
+<p>Avec tous nos remerciements pour votre contribution,</p>
+
+<p>L'équipe des modérateurs de <?php echo $adl_title; ?>.</p>
+
+<input name="__event_requestinfo_send" type="submit" value="Envoyer"/>
+<input name="__event_requestinfo_cancel" type="submit" value="Annuler"/>
+</form>
+</div>
+
+<?php
+echo '<div class="moderationbox">';
+echo $event->formatHTML();
+echo '</div>';
+
+put_footer();
+?>
Modified: branches/dui/submit.php
==============================================================================
--- branches/dui/submit.php Sun Mar 1 18:40:26 2009 (r430)
+++ branches/dui/submit.php Sun Mar 1 18:42:50 2009 (r431)
@@ -1,9 +1,10 @@
<?php
-/* Copyright 2004-2007
- * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
+/* Copyright 2004-2009
+ * - Melanie Bats <melanie POINT bats CHEZ utbm POINT fr>
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
- *
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
@@ -18,350 +19,84 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
- *
- * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
*/
-include("bd.inc.php");
-include("funcs.inc.php");
-
+include("class.bd.inc.php");
$db = new db();
-function alert_moderators ($db, $id, $title, $start, $end, $description,
$city,
- $region, $locality, $url, $contact, $submitter,
$tags)
-{
- global $moderatorlist;
-
- $mail_title = "Nouvel évènement à modérer : '" . $title . "'";
-
- $mail_body = "Bonjour,\n\n" .
- "Un nouvel évènement est à modérer sur\n" .
calendar_absolute_url("moderation.php") . "\n\n".
- format_ascii_event ($db, $title, $start, $end, $description, $city,
$region,
- $locality, $url, $contact, $submitter, $tags) .
"\n\n" .
- "Merci !\n" .
- "-- ". $GLOBALS["adl_title"];
-
- calendar_mail ($moderatorlist, "", $mail_title, $mail_body);
-
- return 0;
-}
-
-function notify_submitter ($db, $id, $title, $start, $end, $description,
$city,
- $region, $locality, $url, $contact, $submitter,
$tags,
- $secret)
-{
- $mail_title = "Votre évènement : '" . $title . "' est en attente de
modération";
-
- $mail_body = "Bonjour,\n\n" .
- wordwrap("Votre évènement intitulé '" . $title .
- "', qui aura lieu le '" . date_timestamp2humanreadable($start) .
- "' a bien été enregistré dans ". $GLOBALS["adl_title"]. ". ".
- "L'équipe de modération le prendra en charge très
prochainement. " .
- "Pendant la modération et après celle-ci si votre évènement est
validé, " .
- "vous pouvez éditer votre évènement à l'adresse :\n" .
- " " . calendar_absolute_url("editevent.php?id=" . $id .
"&secret=" . $secret) . "\n\n" .
- "et vous pouvez l'annuler en utilisant l'adresse :\n" .
- " " . calendar_absolute_url("cancelevent.php?id=" . $id .
"&secret=" . $secret) . "\n\n") .
- "Merci de votre participation !\n" .
- "-- ". $GLOBALS["adl_title"];;
-
- calendar_mail($submitter, "", $mail_title, $mail_body);
-}
-
-function add_event ($db, $title, $start, $end, $description, $city, $region,
$locality, $url, $contact, $submitter, $tags)
-{
- $error_cnt = 0;
-
- $title = stripslashes(strip_tags($title));
- $description = stripslashes(strip_tags($description,
"<p><strong><em><br/><a><ul><li><ol><b><i>"));
- $city = stripslashes(strip_tags($city));
- $url = stripslashes(strip_tags($url));
- $contact = stripslashes(strip_tags($contact));
- $submitter = stripslashes(strip_tags($submitter));
- $tags = stripslashes(strip_tags($tags));
-
- if (! $title)
- {
- error ("Titre vide");
- $error_cnt++;
- }
-
- if (stristr($title, "viagra"))
- {
- error ("Les spammeurs, dehors");
- $error_cnt++;
- }
-
- if (! $description)
- {
- error ("Description vide");
- $error_cnt++;
- }
-
- if (! $city)
- {
- error ("Ville vide");
- $error_cnt++;
- }
-
- if (! $url)
- {
- error ("URL vide");
- $error_cnt++;
- }
-
- if (strncmp ($url, "http://", 7) && strncmp($url, "https://", 8))
- {
- error ("URL ne commençant pas par http:// ou https://");
- $error_cnt++;
- }
-
- if ($start <= mktime())
- {
- error ("Le début de la manifestation est dans le
passé.");
- $error_cnt++;
- }
-
- if ($end <= mktime())
- {
- error ("La fin de la manifestation est dans le passé.");
- $error_cnt++;
- }
-
- if ($end <= $start)
- {
- error ("La fin de la manifestation est avant le début");
- $error_cnt++;
- }
-
- if (! ereg("^([-A-Za-z0-9_+.]*)@([-A-Za-z0-9_]*)\.([-A-Za-z0-9_.]*)$",
$contact))
- {
- error ("Email de contact invalide");
- $error_cnt++;
- }
-
- if (!empty($submitter) && !
ereg("^([-A-Za-z0-9_+.]*)@([-A-Za-z0-9_]*)\.([-A-Za-z0-9_.]*)$", $submitter))
- {
- error ("Email du soumetteur invalide");
- $error_cnt++;
- }
-
- $tags = ereg_replace(" +", " ", $tags);
- foreach(explode(" ", $tags) as $tag)
- {
- if ($tag == "")
- continue;
-
- if (! ereg("^[a-z0-9\-]*$", $tag))
- {
- error("Tag '" . $tag . "' invalide. Les tags ne doivent
contenir que des lettres minuscules, des chiffres ou des tirets.");
- $error_cnt++;
- }
- if (strlen($tag) < 3)
- {
- error("Tag '" . $tag . "' trop court. Les tags doivent faire
au moins 4 caractères de long.");
- $error_cnt++;
- }
- }
-
- if ($error_cnt != 0)
- {
- return -1;
- }
-
- if (! $submitter)
- $submitter = $contact;
-
- /* Checks are done, add to database */
- $sql = "INSERT INTO events
(title,description,start_time,end_time,city,region,locality,url,contact,submitter,".
/*"tags,".*/ "moderated, secret, submission_time) values (" .
- $db->quote_smart($title) . "," .
- $db->quote_smart($description) . "," .
- $db->quote_smart(date_timestamp2mysql ($start)) . "," .
- $db->quote_smart(date_timestamp2mysql ($end)) . "," .
- $db->quote_smart($city) . "," .
- $db->quote_smart($region) . "," .
- $db->quote_smart($locality) . "," .
- $db->quote_smart($url) . "," .
- $db->quote_smart($contact) . "," .
- $db->quote_smart($submitter) . "," .
- /*$db->quote_smart($tags) . "," .*/
- "'0'" . "," .
- "'" . md5(uniqid(rand(), true)) . "'" . "," .
- "NOW()" .
- ")";
-
- $ret = $db->query ($sql);
-
- if ($ret == FALSE)
- {
- error ("La requête a échoué.");
- return -1;
- }
-
- $event_id = $db->insertid();
-
- // manual tags
- $aTags = explode(" ", $tags);
- $aTagsKnown = array();
- // get tags which already exist
- $query = "SELECT id, name FROM tags WHERE name IN ('". implode("', '",
$aTags). "')";
- $result = $db->query($query);
- while ($record = $db->fetchObject($result))
- {
- $aTagsKnown[]=$record->name;
- }
- // Insert new tags
- if (count($aTagsNew = array_diff($aTags, $aTagsKnown))>0)
- {
- $query = "INSERT INTO tags (name) VALUES ('". implode("'), ('",
$aTagsNew). "')";
- $db->query($query);
- }
- // make link between event and tags
- $query = "INSERT INTO tags_events (event_id, tag_id) SELECT {$event_id},
id FROM tags WHERE name IN ('". implode("','", $aTags). "')";
- $result = $db->query($query);
-
- alert_moderators ($db, $db->insertid(), $title, $start, $end,
$description, $city,
- $region, $locality, $url, $contact, $submitter, $tags);
- notify_submitter ($db, $db->insertid(), $title, $start, $end,
$description, $city,
- $region, $locality, $url, $contact, $submitter, $tags);
- echo "<p><b>Votre évènement a bien été ajouté à la liste des évènements en
attente de modération." .
- "Il apparaîtra en ligne dès qu'un modérateur l'aura validé.</b></p>";
-
- echo "<p><a href=\"index.php\">Retour à l'Agenda</a></p>";
-
- return 0;
-}
+include("funcs.inc.php");
+include("class.event.inc.php");
put_header("Soumettre un évènement");
echo "<h2>Soumettre un évènement</h2>";
-$start = mktime();
-$end = mktime() + 60;
+$event = new event($db, 0);
+$event->start = mktime();
+$event->end = mktime() + 60;
-/* Convert form date to timestamp */
-if (isset($_POST['__event_start_day']))
+function alertModerators ($event)
{
- $start = mktime($_POST['__event_start_hour'],
- $_POST['__event_start_minute'],
- 0,
- $_POST['__event_start_month'],
- $_POST['__event_start_day'],
- $_POST['__event_start_year']);
-}
+ global $moderatorlist;
+ $mail_title = "Nouvel évènement à modérer : '" . $event->title . "'";
+ $mail_body = "Bonjour,\n\n" .
+ "Un nouvel évènement est à modérer sur\n" .
+ calendar_absolute_url("moderation.php") . "\n\n".
+ $event->formatAscii() . "\n\n" . "Merci !\n" .
+ "-- ". $GLOBALS["adl_title"];
+ $return = true;
+ calendar_mail($moderatorlist, "", $mail_title, $mail_body);
-if (isset($_POST['__event_end_day']))
-{
- $end = mktime($_POST['__event_end_hour'],
- $_POST['__event_end_minute'],
- 0,
- $_POST['__event_end_month'],
- $_POST['__event_end_day'],
- $_POST['__event_end_year']);
+ return $return;
}
-if (isset($_POST['__event_tags']))
-{
- // format tags
- $event_tags = $_POST['__event_tags'];
- if (is_array($_POST['tags']))
- {
- foreach($_POST['tags'] as $aTags)
- if (is_array($aTags))
- $event_tags .= " ". implode(' ', $aTags);
- else
- $event_tags .= " ". $aTags;
- }
- $event_tags = trim(str_replace(" ", " ", $event_tags));
-}
-else
- $event_tags = "";
-/* If user submitted event */
-if (isset($_POST['__event_save']))
+if (isset($_POST['__event_title'])) // if from form
{
- $ret = add_event ($db, $_POST['__event_title'],
- $start, $end,
- $_POST['__event_description'],
- $_POST['__event_city'],
- $_POST['__event_region'],
- $_POST['__event_locality'],
- $_POST['__event_url'],
- $_POST['__event_contact'],
- $_POST['__event_submitter'],
- $event_tags);
+ $event->fromForm();
+ $event->check();
+ if ($event->error==0)
+ {
+ if (! $event->submitter)
+ $event->submitter = $event->contact;
- if ($ret == 0)
+ $event->save();
+
+ if (! $event->error)
{
- /*
- * Event has been successfully added
- */
- put_footer();
- exit;
+ alertModerators($event);
+ $event->notifySubmitter();
+ echo "<p><b>Votre évènement a bien été ajouté à la liste des
évènements en attente de modération. " .
+ "Il apparaîtra en ligne dès qu'un modérateur l'aura
validé.</b></p>";
}
- else
+ else
{
- /*
- * Event couldn't be added. Display it so that the user can edit
- * it again
- */
- echo "<hr/>";
- echo format_event ($db, $_POST['__event_title'],
- $start, $end,
- $_POST['__event_description'],
- $_POST['__event_city'],
- $_POST['__event_region'],
- $_POST['__event_locality'],
- $_POST['__event_url'],
- $_POST['__event_contact'],
- $_POST['__event_submitter'],
- $event_tags);
- echo "<hr/>";
- $_preview = true;
+ error($event->message);
}
+ echo "<p><a href=\"index.php\">Retour à l'Agenda</a></p>";
+
+ if (! $event->error) $_sent = true;
+ }
+ $_preview = true;
}
/* Preview event */
-else if (isset($_POST['__event_preview']))
+if (isset($_POST['__event_preview']) || isset($_preview))
{
-
echo "<hr/>";
- echo format_event ($db, $_POST['__event_title'],
- $start, $end,
- $_POST['__event_description'],
- $_POST['__event_city'],
- $_POST['__event_region'],
- $_POST['__event_locality'],
- $_POST['__event_url'],
- $_POST['__event_contact'],
- $_POST['__event_submitter'],
- $event_tags);
+ echo $event->formatHTML();
echo "<hr/>";
$_preview = true;
}
-echo $adl_submit_summary;
-
-echo "<div id=\"advises\">\n$adl_submit_advises</div>\n";
-
-echo "<form method=\"post\" action=\"submit.php\">";
-
-if (isset($_POST['__event_title'])) echo $_POST['__event_title'];
-
-/* Display edit form */
-edit_event ($db, @$_POST['__event_title'],
- $start, $end,
- (isset($_POST['__event_description']) ?
$_POST['__event_description'] : "<p></p>"),
- @$_POST['__event_city'],
- @$_POST['__event_region'],
- @$_POST['__event_locality'],
- @$_POST['__event_url'],
- @$_POST['__event_contact'],
- @$_POST['__event_submitter'],
- @$event_tags,
- TRUE, isset($_preview));
+if (!isset($_sent) || $sent)
+{
+ echo $adl_submit_summary;
+ echo "<div id=\"advises\">\n$adl_submit_advises</div>\n";
+ if (isset($_POST['__event_title'])) echo $_POST['__event_title'];
-echo "</form>\n";
+ $event->edit(true, isset($ret) && $ret);
+}
put_footer();
?>
- [Devel] r431 - branches/dui, svn, 01/03/2009
Archives gérées par MHonArc 2.6.16.