{{monthscheduler}}
/actions/monthscheduler.php
<?php
// Month Scheduler Version 1.0c - Jan 7, 2005 - bad word function call
// The original parts of this script were developed by G. Michael Bowen And Mark Kasper for a SSHRC research project using wikka wiki.
// As far as it is possible to tell (because the code exists all over the web), we provide credit for the original calendar code
// to Marcus Kazmierczak which was released at www.blazonry.com, although this script builds considerably on that code.
// Code additions copyright GMBowen & Mark Kasper, 2004. Released to public domain under GPL. Modify, improve, change as you wish.
// There are two complementary actions. dayschedule.php allows anyone to designate an owner & date to see their schedule (see line 140)
// and it should be placed on a page named "DaySchedule". The other action, scheduler.php, is a small version of the calendar action
// which allows easy and fast entering of data on different days.
function BadWordFunction($RemoveBadWordText) {
$RemoveBadWordText = eregi_replace("fuc?k|[kc]unt|motherfucker|cocksucker|bitch|son of a bitch|asshole|shit|fag|wank|dick|pu[zs]?[zs][yi]|bastard|s[kc]rew|mole[zs]ter|mole[sz]t|coc?k", "", $RemoveBadWordText);
return $RemoveBadWordText;
}
//no double-click function in calendar-action
//it would be nice to make the calendar entries editable with double-click
echo '
<script language="JavaScript" type="text/javascript">
var edit = false;
</script>
';
?>
<div align="center">
<P><TABLE BORDER=0 width=100%>
<TR>
<TD>
<P>
<?php
$month = (!isset($_GET['month'])) ? date("n",mktime()) : $_GET['month'];
$year = (!isset($_GET['year'])) ? date("Y",mktime()) : $_GET['year'];
$today = (!isset($_GET['day'])) ? date("d",mktime()) : $_GET['day'];
$site_base = $this->GetConfigValue("base_url");
$thispage=$this->GetPageTag();
$username = $this->GetUserName();
// badword array for replacing badwords (not initialized as currently using added function in wakka.php)
//$badwords = Array ('/motherfucker/i', '/cunt/i', '/fuck/i', '/cocksucker/i', '/bitch/i', '/son of a bitch/i', '/asshole/i', '/shit/i', '/fag/i', '/wank/i', '/dick/i', '/pussy/i', '/bastard/i', '/molester/i', '/molezter/i', '/cock/i');
//$changeto = '****';
// gets username
$username = $this->GetUserName();
// kasper
// NOTE VERY IMPORTANT, if the table is totally empty the function will not work, you
// must add one in maually for this function to work.
// I could add it in the code but very messy, will come up with better way.
$dayschedule = $_POST['dayscheduleX'];
$dayschedule = BadWordFunction($dayschedule);
$dayschedule = addslashes($dayschedule); // for single quotes to work
// replace above function call with line below if wakka.php doesn't have a bad word function code in it
//$dayschedule = preg_replace($badwords, $changeto, $dayschedule);
$query = "select * from ".$this->config['table_prefix']."scheduler";
$result = mysql_query($query);
if ($_POST['save']){
// Kasper added to delete the empty schedule
$del = "delete from ".$this->config['table_prefix']."scheduler where dayschedule = ''";
$delresult = mysql_query($del);
$up = 0;
while ($row = mysql_fetch_object($result))
{
if($row->user == $username && $row->month == $month && $row->day == $today && $row->year == $year)
{
$up = 1;
$ro = $row->id;
}
}
if($up == 1)
{
$query = "UPDATE ".$this->config['table_prefix']."scheduler SET dayschedule='$dayschedule' WHERE user='$username' AND id='$ro'";
$result = mysql_query($query);
}else{
$query = "INSERT into ".$this->config['table_prefix']."scheduler (user,dayschedule,month,day,year) VALUES ('$username','$dayschedule','$month','$today','$year')";
$result = mysql_query($query);
}
}
// end kasper
?>
<table>
<tr>
<td valign="top">
<?php
/*== get what weekday the first is on ==*/
$tmpd = getdate(mktime(0,0,0,$month,1,$year));
$monthnamesgerman = array("", "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
//$monthname = $tmpd["month"];
$monthname = $monthnamesgerman[$month];
$firstwday = $tmpd["wday"];
$lastday = mk_getLastDayofMonth($month,$year);
?>
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td colspan="7">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="20"><a href="<?php echo $this->href("", "", "month="); echo (($month-1)<1) ? 12 : $month-1 ; ?>&year=<?php echo (($month-1)<1) ? $year-1 : $year ; ?>"><<<</a></td>
<td align="center"><font size="2"><strong><? echo ucfirst(strtolower($username)); ?>s Kalender für <?php echo "$monthname $year"; ?></strong></font></td>
<td width="20"><a href="<?php echo $this->href("", "", "month="); echo (($month+1)>12) ? 1 : $month+1 ; ?>&year=<?php echo (($month+1)>12) ? $year+1 : $year ; ?>">>>></a></td>
</tr>
</table>
</td>
</tr>
<tr BGCOLOR="#DDccbb">
<?//jweis: starting at Monday?>
<td>Montag</td>
<td>Dienstag</td>
<td>Mittwoch</td>
<td>Donnerstag</td>
<td>Freitag</td>
<td>Samstag</td>
<td>Sonntag</td>
</tr>
<?php
$day = 1;
//shift one left circular, now we calculate with 1..7
if ($firstwday == 0) $firstwday = 7;
//$firstwday = (($firstwday+7)%7);
$wday = $firstwday;
$firstweek = true;
/*== loop through all the days of the month ==*/
while ($day <= $lastday) {
/*== set up blank days for first week ==*/
if ($firstweek) {
print " <tr>";
//firstwday contains the starting day of the current month
for ($i=1; $i<$firstwday; $i++) {
print " <td VALIGN=top ALIGN=left HEIGHT=70><font size=\"2\"> </font></td>";
}
$firstweek = false;
}
//On Monday start a new row
if ($wday==1) {
print " <tr>\n";
}
/*== check for event ==*/
print " <td VALIGN=top ALIGN=left WIDTH=150 HEIGHT=70>";
if($day<10) {
if($month<10) {
$tag = "$year:0$month:0$day";
} else {
$tag = "$year:$month:0$day";
}
} else {
if($month<10) {
$tag = "$year:0$month:$day";
} else {
$tag = "$year:$month:$day";
}
}
$todaydate = date("Y:m:d",mktime());
if($tag==$todaydate) {
$font1 = "<font color=\"#FF0000\"><b>";
$font2 = "</b></font>";
$token="yes";
}
else {
$font1 = "";
$font2 = "";
$token="no";
}
// code to determine what data should be entered into each cell
$thisdayschedule = $this->LoadSingle("SELECT dayschedule FROM ".$this->config["table_prefix"]."scheduler WHERE user='".$username."' AND day='".$day."' AND month='".$month."' AND year='".$year."'");
$dayoutput = $thisdayschedule['dayschedule'];
//replace <some text>@...\n with <some text> \n
$dayoutput = preg_replace("/(.*?\w+?.*?)@(.*?)\n+?/", "$1\n", $dayoutput);
//replace @...\n with nothing
$dayoutput = preg_replace("/(.*?)@(.*?)\n/", "", $dayoutput);
$dayoutput = preg_replace("/(.*?)@(.*)/", "$1", $dayoutput);
//replace <newline> with <br>
$dayoutput = str_replace("\n", "<br>", $dayoutput);
if ($token=="yes") {
//jweis $printme="<a href=".$site_base."DaySchedule&month=".$month."&day=".$today."&year=".$year."><small>[Print Day]</small></a>";
}
else {
$printme="";
}
print "<table width=\"100%\"><TR BGCOLOR=\"#E4DFDA\"><td><a href=".$site_base.$thispage."&day=$day&month=$month&year=$year#EntryBox> $font1$day$font2</a> $printme</td</tr><tr><td><small>$dayoutput</small></td></tr></table>";
print "</td>\n";
//jweis: Sunday -> next row
if ($wday==7) { print " </tr>\n"; }
//$wday++;
$wday = ($wday % 7) + 1;
$day++;
}
?>
</tr>
</table>
</td>
</tr>
</table>
<?php
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year) {
for ($tday=28; $tday <= 31; $tday++) {
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon) break;
}
$tday--;
return $tday;
}
?>
<!-- Comment below 3 lines out if you don't want to link to the formatted schedule page & scheduler page.
<center><a href=<? echo $site_base; ?>DaySchedule&<? echo "month=".$month."&day=".$today."&year=".$year; ?>><small>Formatted Day Page</small></a>
|
<a href=<? echo $site_base; ?>Scheduler&<? echo "month=".$month."&day=".$today."&year=".$year; ?>><small>Small Monthly Calendar</small></a></center>-->
</TD>
</tr><tr>
<TD WIDTH=500>
<P>
<?
if ($user = $this->GetUser()) {
//title over textarea box
$dayschedule = $this->LoadSingle("SELECT dayschedule FROM ".$this->config["table_prefix"]."scheduler WHERE user='".$username."' AND day='".$today."' AND month='".$month."' AND year='".$year."'");
$dayschedule = $dayschedule['dayschedule'];
?>
<center><A NAME=EntryBox></A>
<a href="<?php echo $this->href("", "", "day="); echo (($today-1)<1) ? $lastday : $today-1 ; ?>&year=<?php echo $year; ?>&month=<?php echo $month; ?>"><<</a>
<b><? echo ucfirst(strtolower($username))."s Eintrag für den ".$today.". ".$monthname." ".$year.":"; ?></b>
<a href="<?php echo $this->href("", "", "day="); echo (($today+1)>$lastday) ? 1 : $today+1 ; ?>&year=<?php echo $year; ?>&month=<?php echo $month; ?>">>></a>
<? echo "<br><i><small>Kommentare mit @ einleiten.</small></i>";?>
<center><form action="" method="post">
<textarea cols="90" rows="10" name="dayscheduleX"><?php echo $dayschedule; ?></textarea><br>
<input type="submit" value="Senden" />
<input type="hidden" name="save" value="true" />
</form></center>
</center>
<?
}
else
{
echo "<em>Der Kalender funktioniert nur bei angemeldeten Nutzern.</em>";
}
?>
</P>
</TD>
</TR>
</TABLE>
</div>
create extra table:
CREATE TABLE `yourwiki_scheduler` (
`id` int(10) NOT NULL auto_increment,
`user` varchar(80) NOT NULL default '',
`day` tinyint(2) NOT NULL default '0',
`month` tinyint(2) NOT NULL default '0',
`year` mediumint(4) NOT NULL default '0',
`dayschedule` text,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=15 ;