Adds recurring events for the month
New eventform.php
<?php
session_start();
require("config.php");
require("./lang/lang.admin." . LANGUAGE_CODE . ".php");
require("functions.php");
include("../snews.php");
$id = (isset($_GET['id'])) ? $_GET['id'] : null;
if ($_SESSION[db('website').'Logged_In'] == token()) {
if (empty($id)) {
displayEditForm('Add');
} else {
if ($_SESSION[db('website').'Logged_In'] == token()) {
displayEditForm('Edit', $id);
} else {
echo $lang['accessdenied'];
}
}
} else {
echo $lang['accessdenied'];
}
# ###########################################################
function displayEditForm($mode, $id="")
{
global $lang;
if ($mode == "Add") {
$d = $_GET['d'];
$m = $_GET['m'];
$y = $_GET['y'];
$text = $title = "";
$headerstr = $lang['addheader'];
$buttonstr = $lang['addbutton'];
$pgtitle = $lang['addeventtitle'];
$qstr = "?flag=add";
$stime_vals = null;
$etime_vals = null;
} elseif ($mode == "Edit") {
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "SELECT y, m, d, start_time, end_time, title, text ";
$sql .= "FROM " . DB_TABLE_PREFIX . "mssgs WHERE id = $id";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if (!empty($row)) {
$qstr = "?flag=edit&id=$id";
$headerstr = $lang['editheader'];
$buttonstr = $lang['editbutton'];
$pgtitle = $lang['editeventtitle'];
$title = stripslashes($row["title"]);
$text = stripslashes($row["text"]);
$m = $row["m"];
$d = $row["d"];
$y = $row["y"];
}
$stime_vals = getPullDownTimeValues($row["start_time"]);
$etime_vals = getPullDownTimeValues($row["end_time"]);
#, $ehour, $eminute, $epm);
} else {
$lang['accesswarning'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo $pgtitle ?></title>
<link rel="stylesheet" type="text/css" href="css/popwin.css">
<script language="JavaScript">
function formSubmit() {
if (document.eventForm.title.value != "") {
document.eventForm.method = "post";
document.eventForm.action = "eventsubmit.php<?php echo $qstr ?>";
document.eventForm.submit();
} else {
alert("<?php echo $lang['titlemissing'] ?>");
}
}
</script>
</head>
<body>
<span class="add_new_header"><?php echo $headerstr ?></span>
<br><img src="images/clear.gif" width="1" height="5"><br>
<table border=0 cellspacing=7 cellpadding=0>
<form name="eventForm">
<tr>
<td nowrap valign="top" align="right" nowrap><span class="form_labels"></span></td>
<td><?php monthPullDown($m, $lang['months']); dayPullDown($d); yearPullDown($y); ?></td>
</tr>
<tr>
<td nowrap valign="top" align="right" nowrap>
<span class="form_labels"><?php echo $lang['title']?></span></td>
<td><input type="text" name="title" size="29" value="<?php echo $title ?>" maxlength="50"></td>
</tr>
<tr>
<td nowrap valign="top" align="right" nowrap>
<span class="form_labels"><?php echo $lang['text']?></span></td>
<td><textarea cols=22 rows=6 name="text"><?php echo $text ?></textarea></td>
</tr>
<tr>
<td valign="top" align="right" nowrap><span class="form_labels"><?php echo $lang['starttime'] ?></span></td>
<td><?php hourPullDown($stime_vals['hour'], "start"); ?><b>:</b><?php minPullDown($stime_vals['minute'], "start"); amPmPullDown($stime_vals['pm'], "start"); ?></td>
</tr>
<tr>
<td valign="top" align="right" nowrap><span class="form_labels"><?php echo $lang['endtime'] ?></span></td>
<td><?php hourPullDown($etime_vals['hour'], "end"); ?><b>:</b><?php minPullDown($etime_vals['minute'], "end"); amPmPullDown($etime_vals['pm'], "end"); ?></td>
</tr>
<tr>
<? if ($mode == "Add") { ?>
<td nowrap valign="top" align="right">Or</td>
<td width="208"></td>
</tr>
<tr>
<td nowrap valign="top" align="right"><span class="form_labels">Reoccuring Event:<br>
</span><span class="form_labels">Days of this month:</span></td>
<td width="208">
<table border="0" cellspacing="2" cellpadding="0">
<tr height="19">
<td align="right" width="41" height="19">1<input type="checkbox" name="1" value="1" border="0"></td>
<td align="right" width="38" height="19">2<input type="checkbox" name="2" value="1" border="0"></td>
<td align="right" width="38" height="19">3<input type="checkbox" name="3" value="1" border="0"></td>
<td align="right" width="40" height="19">4<input type="checkbox" name="4" value="1" border="0"></td>
<td align="right" width="39" height="19">5<input type="checkbox" name="5" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">6<input type="checkbox" name="6" value="1" border="0"></td>
<td align="right" width="38" height="19">7<input type="checkbox" name="7" value="1" border="0"></td>
<td align="right" width="38" height="19">8<input type="checkbox" name="8" value="1" border="0"></td>
<td align="right" width="40" height="19">9<input type="checkbox" name="9" value="1" border="0"></td>
<td align="right" width="39" height="19">10<input type="checkbox" name="10" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">11<input type="checkbox" name="11" value="1" border="0"></td>
<td align="right" width="38" height="19">12<input type="checkbox" name="12" value="1" border="0"></td>
<td align="right" width="38" height="19">13<input type="checkbox" name="13" value="1" border="0"></td>
<td align="right" width="40" height="19">14<input type="checkbox" name="14" value="1" border="0"></td>
<td align="right" width="39" height="19">15<input type="checkbox" name="15" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">16<input type="checkbox" name="16" value="1" border="0"></td>
<td align="right" width="38" height="19">17<input type="checkbox" name="17" value="1" border="0"></td>
<td align="right" width="38" height="19">18<input type="checkbox" name="18" value="1" border="0"></td>
<td align="right" width="40" height="19">19<input type="checkbox" name="19" value="1" border="0"></td>
<td align="right" width="39" height="19">20<input type="checkbox" name="20" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">21<input type="checkbox" name="21" value="1" border="0"></td>
<td align="right" width="38" height="19">22<input type="checkbox" name="22" value="1" border="0"></td>
<td align="right" width="38" height="19">23<input type="checkbox" name="23" value="1" border="0"></td>
<td align="right" width="40" height="19">24<input type="checkbox" name="24" value="1" border="0"></td>
<td align="right" width="39" height="19">25<input type="checkbox" name="25" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">26<input type="checkbox" name="26" value="1" border="0"></td>
<td align="right" width="38" height="19">27<input type="checkbox" name="27" value="1" border="0"></td>
<td align="right" width="38" height="19">28<input type="checkbox" name="28" value="1" border="0"></td>
<td align="right" width="40" height="19">29<input type="checkbox" name="29" value="1" border="0"></td>
<td align="right" width="39" height="19">30<input type="checkbox" name="30" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">31<input type="checkbox" name="31" value="1" border="0"></td>
<td align="right" width="38" height="19"></td>
<td align="right" width="38" height="19"></td>
<td align="right" width="40" height="19"></td>
<td align="right" width="39" height="19"></td>
</tr>
</table>
</td><? } ?>
</tr>
<tr><td></td><td><br><input type="button" value="<?php echo $buttonstr ?>" onClick="formSubmit()"> <input type="button" value="<?php echo $lang['cancel'] ?>" onClick="window.close();"></td></tr>
</form>
</table>
</body>
</html>
<?php
}
# ###########################################################
function getPullDownTimeValues($time)
{
$hour = (int) substr($time, 0, 2);
$minute = (int) substr($time, 3, 2);
$pm = false;
if ($hour == 55) {
$hour = 0;
$minute = 0;
} elseif ($hour > 12) {
$hour = $hour - 12;
$pm = true;
} elseif ($hour == 12) {
$pm = true;
} elseif ($hour == 0) {
$hour = 12;
$pm = false;
}
return Array('hour' => $hour, 'minute' => $minute, 'pm' => $pm);
}
# ###########################################################
?>
New eventsubmit.php
<?php
session_start();
require("config.php");
require("./lang/lang.admin." . LANGUAGE_CODE . ".php");
require("functions.php");
include("../snews.php");
if ($_SESSION[db('website').'Logged_In'] == token()) {
switch ($_GET['flag']) {
case "add" :
submitEventData();
break;
case "edit":
$id = (int) $_GET['id'];
if (!empty($id))
submitEventData($id);
else
$lang['accesswarning'];
break;
case "delete":
$month = (int) $_GET['month'];
$year = (int) $_GET['year'];
$id = (int) $_GET['id'];
if (!(empty($id) && empty($month) && empty($year)))
deleteEvent($id, $month, $year);
else
$lang['accesswarning'];
break;
default:
$lang['accesswarning'];
}
} else {
echo $lang['accessdenied'];
}
function submitEventData ($id="")
{
global $lang;
$title = addslashes($_POST['title']);
$title = strip_tags($title);
$text = addslashes($_POST['text']);
$text = strip_tags($text);
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$shour = $_POST['start_hour'];
$sminute = $_POST['start_min'];
$s_ampm = $_POST['start_am_pm'];
$ehour = $_POST['end_hour'];
$eminute = $_POST['end_min'];
$e_ampm = $_POST['end_am_pm'];
$a1 = $_POST['1'];
$a2 = $_POST['2'];
$a3 = $_POST['3'];
$a4 = $_POST['4'];
$a5 = $_POST['5'];
$a6 = $_POST['6'];
$a7 = $_POST['7'];
$a8 = $_POST['8'];
$a9 = $_POST['9'];
$a10 = $_POST['10'];
$a11 = $_POST['11'];
$a12 = $_POST['12'];
$a13 = $_POST['13'];
$a14 = $_POST['14'];
$a15 = $_POST['15'];
$a16 = $_POST['16'];
$a17 = $_POST['17'];
$a18 = $_POST['18'];
$a19 = $_POST['19'];
$a20 = $_POST['20'];
$a21 = $_POST['21'];
$a22 = $_POST['22'];
$a23 = $_POST['23'];
$a24 = $_POST['24'];
$a25 = $_POST['25'];
$a26 = $_POST['26'];
$a27 = $_POST['27'];
$a28 = $_POST['28'];
$a29 = $_POST['29'];
$a30 = $_POST['30'];
$a31 = $_POST['31'];
//$reoccurevent = $HTTP_POST_VARS['reoccurevent'];
if ($shour == 0 && $sminute == 0 && $s_ampm == 0) {
$starttime = "55:55:55";
} else {
if ($s_ampm == 1 && $shour != 12) $shour = $shour + 12;
if ($s_ampm == 0 && $shour == 12) $shour = 0;
$starttime = "$shour:$sminute:00";
}
if ($ehour == 0 && $eminute == 0 && $e_ampm == 0) {
$endtime = "55:55:55";
} else {
if ($e_ampm == 1 && $ehour != 12) $ehour = $ehour + 12;
if ($e_ampm == 0 && $ehour == 12) $ehour = 0;
$endtime = "$ehour:$eminute:00";
}
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
if ($id) {
$sql = "UPDATE " . DB_TABLE_PREFIX . "mssgs SET m='$month', d='$day', y='$year', ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text' ";
$sql .= "WHERE id=$id";
$result = $lang['updated'];
mysql_query($sql) or die(mysql_error());
} else {
// If any of the reoccuring check boxes are checked then add all of them
// or else just add a one day event
$reoccur = array($a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$a11,$a12,$a13,$a14,$a15,$a16,$a17,$a18,$a19,$a20,$a21,$a22,$a23,$a24,$a25,$a26,$a27,$a28,$a29,$a30,$a31);
for($count = 0; $count <= count($reoccur); $count++)
{
if ($reoccur[$count] == '1') {$reoccurevent = 1;}
}
// Add Reoccuring event
if ($reoccurevent == '1')
{
for($count = 0; $count <= count($reoccur); $count++)
{
if ($reoccur[$count] == '1')
{
$count++;
$sql = "INSERT INTO " . DB_TABLE_PREFIX . "mssgs SET m=$month, d=$count, y=$year, ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text'";
$count--;
mysql_query($sql) or die(mysql_error());
}
}
}
// Add one day event
else
{
$sql = "INSERT INTO " . DB_TABLE_PREFIX . "mssgs SET m=$month, d=$day, y=$year, ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text'";
mysql_query($sql) or die(mysql_error());
}
$result = $lang['added'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/popwin.css">
<script language="JavaScript">
opener.location =
"index.php?month=<?php echo $month ?>&year=<?php echo $year ?>";
window.setTimeout('window.close()', 1000);
</script>
</head>
<body>
<div align=\"center\" class=\"display_txt\">
<?php echo stripslashes($title) ?> <?php echo $result ?></div>
</body>
</html>
<?php
}
function deleteEvent($id, $m, $y)
{
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "DELETE FROM " . DB_TABLE_PREFIX . "mssgs WHERE id = $id";
$result = mysql_query($sql) or die(mysql_error());
header("Location: index.php?month=$m&year=$y");
}
?>
Make a small change to functions.php (window sizing issue)
In functions.php, find function postMessage(day, month, year) {
and you will see about 4 lines down
width=340,height=400
(or some other numbers)
change it to
width=540,height=600'
Remember to change the include file paths for integration in MESU/MEMU package'