一部の人にとっては簡単かもしれませんが、私にとっては大きな問題です。私がやりたいのは、2 つのイベントの日程と会場を比較して、衝突しないようにすることです。これが私がこれまでに行ったことです:
<?php
require_once (LIB_PATH.DS.'database.php');
require_once ('../includes/initialize.php');
class Event extends DatabaseObject {
protected static $table_name="event_tbl";
protected static $db_fields = array('id', 'visible', 'event_title', 'start_date', 'end_date', 'start_time', 'end_time', 'venue', 'event_type', 'event_description', 'event_program', 'reminder_date', 'reminder_time');
public $id;
public $event_title;
public $start_date;
public $end_date;
public $start_time;
public $end_time;
public $venue;
public $event_type;
public $event_description;
public $event_program;
public $visible;
public $reminder_date;
public $reminder_time;
public function avoid_clash($time1, $time2, $database_venue, $time3, $time4, $venues) {
$timeStart = strtotime("{$time1}");
$timeEnd = strtotime("{$time2}");
$time = strtotime("{$time3}") - strtotime("{$time4}");
if ($result =($time > $timeStart && $time < $timeEnd) && $database_venue==$venues) {
$session->message('Warning: This event clashes with another!');
redirect_to('event_management.php');
}
}
}
/*function process_avoid_clash($time1, $time2, $time3, $time4, $venues) {
$event = self::find_from_event();
$row = fetch_array($event);
foreach ($row as $rows) {
$time1 = $rows['start_date']." ".$rows['start_time'];
$time2 = $rows['end_date']." ".$rows['end_time'];
$database_venue = $rows['venue'];
if ($time1 && $time2 && $database_venue) {
avoid_clash($time1, $time2, $time3, $time4, $venues);
} else {
die("find_from_event failed!");
}
}
}*/
?>
次に、2 つのイベントが衝突した場合に送信時にユーザーに警告するフォームを使用してテストする方法を次に示します。
<?php
require_once ('../includes/initialize.php');
if(!$session->is_logged_in()) {
redirect_to("login.php");
}
?>
<?php
if (isset($_POST['submit'])) {
$event = new Event();
$even = Event::find_public();
$time3 = $_POST['start_date']." ".$_POST['start_time'];
$time4 = $_POST['end_date']." ".$_POST['end_time'];
$venues = $_POST['venue'];
foreach($even as $events):
$time1 = $events->start_date." ".$events->start_time;
$time2 = $events->end_date." ".$events->end_time;
$database_venue = $events->venue;
if ($time1 && $time2 && $database_venue) {
$event->avoid_clash($time1, $time2, $database_venue, $time3, $time4, $venues);
}
endforeach;
$event-> event_title = $_POST['event_title'];
$event-> start_date = $_POST['start_date'];
$event-> end_date = $_POST['end_date'];
$event-> start_time = $_POST['start_time'];
$event-> end_time = $_POST['end_time'];
$event-> venue = $_POST['venue'];
$event-> event_type = $_POST['event_type'];
$event-> event_description = $_POST['event_description'];
$event-> event_program = $_POST['event_program'];
$event-> visible = $_POST['visible'];
$event-> reminder_date = $_POST['reminder_date'];
$event-> reminder_time = $_POST['reminder_time'];
$event->create();
$session->message('Event successfully created!');
redirect_to('event_management.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>New Event</title>
<link rel="stylesheet" type="text/css" href="../anytime/anytime.css"/>
<script src="../anytime/jquery.min.js"></script>
<script src="../anytime/jquery-migrate-1.0.0.js"></script>
<script src="../anytime/anytime.js"></script>
<link href="../assets/css/test_project.css" rel="stylesheet" type="text/css" />
<link href="../assets/css/links.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<div id="header">
<div class="logo"></div>
<div class="menu">
<div id="navcontainer">
<ul id="navlist">
</ul>
</div>
<br class="clear"/>
</div>
<br class="clear"/>
</div>
<div id="wrapper">
<div id="sidebar1">
<p><?php echo output_message($message); ?></p>
<form id="form1" name="form1" method="post" action="new_event.php">
<table width="578" height="322" border="0" cellpadding="0">
<tr>
<td colspan="3" align="right" valign="top">Event Title:</td>
<td colspan="5" align="left" valign="top"><input type="text" name="event_title" /></td>
</tr>
<tr>
<td width="3" align="center" valign="top"> </td>
<td width="89" align="center" valign="top"><input name="start_date" type="text" size="14" id="start_date" value="START DATE"/></td>
<td width="60" align="center" valign="top"><input name="start_time" type="text" size="8" id="start_time" value="TIME"/></td>
<script>
AnyTime.picker("start_date",
{format: "%Y-%c-%e"});
$("#start_time").AnyTime_picker(
{ format: "%H:%i", LabelTitle: "Time",
labelHour: "Hour", labelMinute: "Minute" });
</script>
<td width="54" align="center" valign="top"><strong>TO</strong></td>
<td width="71" align="center" valign="top"><input name="end_date" type="text" size="14" id="end_date" value="END DATE"/></td>
<td width="74" align="center" valign="top"><input name="end_time" type="text" size="8" id="end_time" value="TIME"/></td>
<script>
AnyTime.picker("end_date",
{format: "%Y-%c-%e"});
$("#end_time").AnyTime_picker(
{ format: "%H:%i", LabelTitle: "Time",
labelHour: "Hour", labelMinute: "Minute" });
</script>
<td width="67" align="center" valign="top"> </td>
<td width="142" align="center" valign="top"> </td>
</tr>
<tr>
<td colspan="3" align="right" valign="top">Venue:</td>
<td colspan="5" align="left" valign="top"><input type="text" name="venue" /></td>
</tr>
<tr>
<td colspan="3" align="right" valign="top">Event Type:</td>
<td colspan="5" align="left" valign="top"><input type="text" name="event_type" /></td>
</tr>
<tr>
<td height="59" colspan="3" align="right" valign="top">Event Description:</td>
<td colspan="5" align="left" valign="top"><textarea name="event_description"></textarea></td>
</tr>
<tr>
<td height="51" colspan="3" align="right" valign="top">Event Program: </td>
<td colspan="5" align="left" valign="top"><textarea name="event_program"></textarea></td>
</tr>
<tr>
<td height="24" colspan="3" align="right" valign="top">Visible:</td>
<td colspan="5" align="left" valign="top"><input name="visible" type="radio" value="0" />
No
<input name="visible" type="radio" value="1" />
Yes</td>
</tr>
<tr>
<td height="40" colspan="3" align="right" valign="top">Reminder:</td>
<td align="left" valign="top">
<input name="reminder_date" type="text" size="10" id="reminder_date" /> </td>
<td align="left" valign="top">
<input name="reminder_time" type="text" size="10" id="reminder_time"/></td>
<script>
AnyTime.picker("reminder_date",
{format: "%Y-%c-%e"});
$("#reminder_time").AnyTime_picker(
{ format: "%H:%i", LabelTitle: "Time",
labelHour: "Hour", labelMinute: "Minute" });
</script>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td height="40" colspan="3" align="right" valign="top"><input type="submit" name="submit" value="Create Event" /></td>
<td height="40" align="left" valign="top"> <input name="New" type="button" id="New" value="Cancel" onclick="location.href='event_management.php'"/></td>
</tr>
</table>
</form>
</div>
<?php include_layout_template('footer.php'); ?>
情報や提案は大歓迎です。