Cal Addevent.php:
<?php
##########################################################################
# Please refer to the README file for licensing and contact information.
#
# This file has been updated for version 0.6.20050215
#
# If you like this application, do support me in its development
# by sending any contributions at www.calendarix.com.
#
#
# Copyright © 2002-2005 Vincent Hor
##########################################################################
include ("cal_header.inc.php");
include ("cal_utils.php") ;
if (!isset($_GET['add_day']))
$add_day = '';
else
$add_day = $_GET['add_day'];
if (!isset($_GET['add_month']))
$add_month = '';
else
$add_month = $_GET['add_month'];
if (!isset($_GET['add_year']))
$add_year = '';
else
$add_year = $_GET['add_year'];
if (!isset($_GET['id']))
$id = '';
else
$id = $_GET['id'];
if (!isset($_GET['catview']))
$catview = 0;
else
$catview = $_GET['catview'];
if (!isset($_GET['copyevent']))
$copyevent = 0;
else
$copyevent = $_GET['copyevent'];
if ($op == "eventform"){
eventform($add_day, $add_month, $add_year, $id) ;
}
/*****************/
/* back function */
/*****************/
function back(){
echo "<div class=normalfont align=center><a class=normalfont href=javascript:history.back()>".translate("Back")."</a></div>\n";
}
/**********************/
/* add event: the form */
/**********************/
function eventform($add_day, $add_month, $add_year, $id){
global $EVENTS_TB, $CAT_TB, $language, $addeventok, $mth, $add_day, $add_month, $add_year, $calstartyear, $caladvanceyear, $week, $notimeentry, $time12hour, $catview;
if ($addeventok==1){
// Check if it is a copy event
$copyevent = false ;
if ($id!='') {
$copyevent = true ;
$query = "select id, title, cat_name, description, starttime, endtime, day, month, year, approved, url, email from ".$EVENTS_TB." left join ".$CAT_TB." on ".$EVENTS_TB.".cat=".$CAT_TB.".cat_id where id='$id'";
$result = mysql_query($query);
$copyrow = mysql_fetch_object($result);
}
echo "<div class=titlefont>".translate("Add event")."</div><br/>";
echo "<form action=cal_addevent.php?op=addevent" ;
if ($copyevent) echo "©event=1 method=post><div class=normalfont>\n";
else echo "©event=0 method=post><div class=normalfont>\n";
echo translate("Event Title")."<br/>\n";
echo "<input type=text name=title size=30" ;
if ($copyevent) echo " value='".stripslashes($copyrow->title)."' " ;
echo "><br/>\n";
echo translate("Event Description")."<br/>\n";
echo "<textarea name=description cols=50 rows=7>" ;
if ($copyevent) echo stripslashes(str_replace("<br />", "", $copyrow->description));
echo "</textarea><br/>\n";
echo translate("Email")." (".translate("Optional").") <br/>\n";
echo "<input type=text name=email" ;
if ($copyevent) echo " value='".$copyrow->email."' " ;
echo "><br/>\n";
echo "URL"." (".translate("Optional").") "."<br/>\n" ;
echo "<input type=text name=url" ;
if ($copyevent) {
// for compatibility with up to 0.5 version
if ((trim($copyrow->url)<>"")&&(strtolower(substr($copyrow->url, 0, 4))<>"http"))
echo " value='http://".$copyrow->url."' ";
else echo " value='".$copyrow->url."' ";
}
echo "><br/>\n";
// get the categories
echo translate("Event Category")."<br/>\n";
echo "<select name=cat>\n\t<option value=0>".translate("Choose Category")."\n";
$query = "select cat_id, cat_name from ".$CAT_TB." order by cat_name" ;
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)){
echo "\t<option value=".$row->cat_id ;
if ($copyevent) { if (stripslashes($copyrow->cat_name)==stripslashes($row->cat_name)) echo " selected " ; }
else if ($row->cat_id==$catview) echo " selected " ;
echo ">".stripslashes($row->cat_name)."\n";
}
echo "</select>\n<br/>\n";
if ($notimeentry==0) {
// get start time
echo translate("Start Time")." (hh:mm) <br/>\n";
echo " <select name=starttimehr>\n\t<option value='--'>--\n";
$thour = 24 ;
$sthour = 0 ;
$midnight=false;
if ($time12hour==1) { $thour = 13 ; $sthour = 1 ; }
if (($copyevent)&&($time12hour==1)&&(substr($copyrow->starttime, 0, 2)=="00")) $midnight=true ;
for ($i = $sthour;$i<$thour;$i++){
if ($i<10) {
echo "\t<option value='0$i'" ;
if ($copyevent) {
if (substr($copyrow->starttime, 0, 2)=="0$i") echo " selected " ;
if ($time12hour==1) {
if ((intval(substr($copyrow->starttime, 0, 2)) - 12) == $i) echo " selected " ;
}
}
echo ">0$i\n" ;
}
else {
echo "\t<option value=$i" ;
if ($copyevent) {
if (substr($copyrow->starttime, 0, 2)=="$i") echo " selected " ;
if (($midnight)&&($i==12)) echo " selected " ;
if ($time12hour==1) {
if ((intval(substr($copyrow->starttime, 0, 2)) - 12) == $i) echo " selected " ;
}
}
echo ">$i\n";
}
}
echo "</select> <b>:</b> \n";
echo "<select name=starttimemin>\n";
for ($i=0;$i<60;$i=$i+5){
if ($i<10) {
echo "\t<option value='0$i'" ;
if ($copyevent) { if (substr($copyrow->starttime, 3, 2)=="0$i") echo " selected " ; }
echo ">0$i\n" ;
}
else {
echo "\t<option value=$i" ;
if ($copyevent) { if (substr($copyrow->starttime, 3, 2)=="$i") echo " selected " ; }
echo ">$i\n";
}
}
echo "</select>\n";
if ($time12hour==1) {
echo " <select name='startperiod'>\n";
echo "\t<option value='am'" ;
if ($copyevent) { if (intval(substr($copyrow->starttime, 0, 2)) < 12) echo " selected " ; }
echo ">am" ;
echo "\t<option value='pm'" ;
if ($copyevent) { if (intval(substr($copyrow->starttime, 0, 2)) >= 12) echo " selected " ; }
echo ">pm" ;
echo "</select><br/>\n";
}
else echo "<input type='hidden' name='startperiod' value=''><br/>\n" ;
// get end time
echo translate("End Time")." (hh:mm) <br/>\n";
echo " <select name=endtimehr>\n\t<option value='--'>--\n";
$thour = 24 ;
$sthour = 0 ;
$midnight=false;
if ($time12hour==1) { $thour = 13 ; $sthour = 1 ; }
if (($copyevent)&&($time12hour==1)&&(substr($copyrow->endtime, 0, 2)=="00")) $midnight=true ;
for ($i = $sthour;$i<$thour;$i++){
if ($i<10) {
echo "\t<option value='0$i'" ;
if ($copyevent) {
if (substr($copyrow->endtime, 0, 2)=="0$i") echo " selected " ;
if ($time12hour==1) {
if ((intval(substr($copyrow->endtime, 0, 2)) - 12) == $i) echo " selected " ;
}
}
echo ">0$i\n" ;
}
else {
echo "\t<option value=$i" ;
if ($copyevent) {
if (substr($copyrow->endtime, 0, 2)=="$i") echo " selected " ;
if (($midnight)&&($i==12)) echo " selected " ;
if ($time12hour==1) {
if ((intval(substr($copyrow->endtime, 0, 2)) - 12) == $i) echo " selected " ;
}
}
echo ">$i\n";
}
}
echo "</select> <b>:</b> \n";
echo "<select name=endtimemin>\n";
for ($i=0;$i<60;$i=$i+5){
if ($i<10) {
echo "\t<option value='0$i'" ;
if ($copyevent) { if (substr($copyrow->endtime, 3, 2)=="0$i") echo " selected " ; }
echo ">0$i\n" ;
}
else {
echo "\t<option value=$i" ;
if ($copyevent) { if (substr($copyrow->endtime, 3, 2)=="$i") echo " selected " ; }
echo ">$i\n";
}
}
echo "</select>\n";
if ($time12hour==1) {
echo " <select name='endperiod'>\n";
echo "\t<option value='am'" ;
if ($copyevent) { if (intval(substr($copyrow->endtime, 0, 2)) < 12) echo " selected " ; }
echo ">am" ;
echo "\t<option value='pm'" ;
if ($copyevent) { if (intval(substr($copyrow->endtime, 0, 2)) >= 12) echo " selected " ; }
echo ">pm" ;
echo "</select><br/>\n";
}
else echo "<input type='hidden' name='endperiod' value=''><br/>\n" ;
}
// get days
echo translate("Date")."<br/>\n";
echo "<select name=bday>\n\t<option value=0>".translate("Day")."\n";
for ($i = 1;$i<=31;$i++){
echo "\t<option value=$i" ;
if ($copyevent) {
$tday = $copyrow->day ;
if (substr("$tday", 0, 1) == "0") $tday = str_replace("0", "", $tday);
if ($i==$tday) echo " selected " ;
}
else if ($add_day==$i) echo " selected " ;
echo ">$i\n";
}
echo "</select> \n";
// get months
echo "<select name=bmonth>\n\t<option value=0>".translate("Month")."\n";
for($i=1;$i<13;$i++){
echo "\t<option value=".$i ;
if ($copyevent) {
$tmonth = $copyrow->month ;
if (substr("$tmonth", 0, 1) == "0") $tmonth = str_replace("0", "", $tmonth);
if ($i==$tmonth) echo " selected " ;
}
else if ($add_month==$i) echo " selected " ;
echo ">".ucfirst($mth[$i])."\n";
}
echo "</select> \n";
// get year from "calstartyear" and give "caladvanceyear" years more to select
echo "<select name=byear>\n\t<option value=0>".translate("Year")."\n";
$year = date("Y");
for ($i=$calstartyear;$i<=($year+$caladvanceyear);$i++){
echo "\t<option value=$i" ;
if ($copyevent) {
if ($i==$copyrow->year) echo " selected " ;
}
else if ($add_year==$i) echo " selected " ;
echo ">$i\n";
}
echo "</select><br/>\n";
echo "<input type=radio value=one name=repeat checked> ".translate("No Repeat")." <input type=radio value=more name=repeat>".translate("Repeat")."\n";
echo " <select name=rtimes>\n";
for ($i = 1;$i<=30;$i++){
echo "\t<option value=$i" ;
if ($i==1) echo " selected " ;
echo ">$i\n";
}
echo "</select> " ;
echo translate("times every");
echo " <select name=rday>\n\t<option value=0 selected>".translate("Day")."\n";
for ($i = 1;$i<=7;$i++){
echo "\t<option value=$i" ;
echo ">$week[$i]\n";
}
echo "\t<option value=8>" ;
echo ucfirst(translate("Two weeks"))."\n";
echo "\t<option value=9>" ;
echo translate("Month")."\n";
echo "\t<option value=10>" ;
echo translate("Year")."\n";
echo "</select> " ;
echo "<br/>\n";
echo "<br/><input type=submit value=\"".translate("Add event")."\">\n";
echo " <input type=button value=\"".translate("Close")."\" onclick='Javascript:window.close();'>\n<br/>\n";
echo "</div><form>\n";
}
else {
echo translate("disabled");
}
}
/*************/
/* add event */
/*************/
// revalidate to prevent posting of events when addevent window is open and user is logout
if ($userlogin==1) {
if (!isset($_SESSION["login"])) { header ("location: cal_login.php"); exit(); }
}
if ($op == "addevent"){
$title = $_POST['title'];
$description = $_POST['description'];
$email = $_POST['email'];
$url = $_POST['url'];
$cat = $_POST['cat'];
$bday = $_POST['bday'];
$bmonth = $_POST['bmonth'];
$byear = $_POST['byear'];
$repeat = $_POST['repeat'];
$rtimes = $_POST['rtimes'];
$rday = $_POST['rday'];
if ($notimeentry==0) {
$starttimehr = $_POST['starttimehr'];
$starttimemin = $_POST['starttimemin'];
$endtimehr = $_POST['endtimehr'];
$endtimemin = $_POST['endtimemin'];
if ($time12hour==1) {
$startperiod = $_POST['startperiod'] ;
$endperiod = $_POST['endperiod'] ;
}
}
if ($notimeentry==0) {
if ($time12hour==1) {
addevent($title, $description, $email, $url, $cat, $repeat, $bday, $bmonth, $byear, $rday, $rtimes,
$starttimehr, $starttimemin, $endtimehr, $endtimemin, $startperiod, $endperiod); }
else {
addevent($title, $description, $email, $url, $cat, $repeat, $bday, $bmonth, $byear, $rday, $rtimes,
$starttimehr, $starttimemin, $endtimehr, $endtimemin, "--", "--"); }
}
else {
addevent($title, $description, $email, $url, $cat, $repeat, $bday, $bmonth, $byear, $rday, $rtimes,
"--", "--", "--", "--", "am", "am");
}
}
function addevent($title, $description, $email, $url, $cat, $repeat, $bday, $bmonth, $byear, $rday, $rtimes,
$starttimehr, $starttimemin, $endtimehr, $endtimemin, $startperiod, $endperiod){
global $EVENTS_TB, $CAT_TB, $caleventapprove, $userlogin, $timezone, $mailevent,
$emailrcpt, $mth, $week, $notimeentry, $calstartyear, $caladvanceyear, $copyevent, $time12hour, $id;
if (!$title) { echo "<div class=normalfont align=center>".translate("notitle")."</div><br/>" ; back(); }
elseif (!$description) { echo "<div class=normalfont align=center>".translate("nodescription")."</div><br/>" ; back(); }
elseif (!$cat) { echo "<div class=normalfont align=center>".translate("nocat")."</div><br/>" ; back(); }
elseif (!$bday) { echo "<div class=normalfont align=center>".translate("noday")."</div><br/>" ; back(); }
elseif (!$bmonth) { echo "<div class=normalfont align=center>".translate("nomonth")."</div><br/>"; back(); }
elseif (!$byear) { echo "<div class=normalfont align=center>".translate("noyear")."</div><br/>"; back(); }
else {
$title = addslashes($title);
$description = addslashes(nl2br($description));
//$url = str_replace("http://", "", $url);
$approve = $caleventapprove;
$nobody = '' ;
if ($userlogin==1) {
if (isset($_SESSION["login"])) {
$nobody = $_SESSION["login"] ;
}
}
echo $stime = '' ;
echo $etime = '' ;
if ($notimeentry==0) {
if ($starttimehr!="--") {
if ($time12hour==1) {
$stime = convert12to24($starttimehr, $startperiod).":".$starttimemin ;
}
else
$stime = $starttimehr.":".$starttimemin ;
}
if ($endtimehr!="--") {
if ($time12hour==1) {
$etime = convert12to24($endtimehr, $endperiod).":".$endtimemin ;
}
else
$etime = $endtimehr.":".$endtimemin ;
}
}
// get the correct timezone offset for timestamping of event entries
$timestamp = date("YmdHis", mktime(date("G")+$timezone, date("i"), date("s"), date("n"), date("j"), date("Y"))) ;
if ((date("G")+$timezone)>24) $timestamp = date("YmdHis", mktime(date("G")+$timezone-24, date("i"), date("s"), date("n"), date("j")+1, date("Y"))) ;
if ((date("G")+$timezone)<0) $timestamp = date("YmdHis", mktime(date("G")+$timezone+24, date("i"), date("s"), date("n"), date("j")-1, date("Y"))) ;
$timestamp = strval($timestamp) ;
$query = "insert into ".$EVENTS_TB." values
('', '$timestamp', '$title', '$description', '$url', '$email', '$cat', '$stime', '$etime', '$bday', '$bmonth', '$byear', '$approve', '0', '$nobody', '')";
$result = mysql_query($query);
// Mail portion
if ($mailevent==1) {
$catquery = "select cat_name from ".$CAT_TB." where cat_id=$cat" ;
$catresult = mysql_query($catquery);
$catrow = mysql_fetch_object($catresult) ;
$mailhead = translate("Date").": ".$bday." ".$mth[$bmonth]." ".$byear ;
$mailhead = $mailhead."\r\n".translate("From").": " ;
if ($time12hour==1) $mailhead = $mailhead.show12hour($stime) ;
else $mailhead = $mailhead.$stime ;
$mailhead = $mailhead." ".translate("To").": " ;
if ($time12hour==1) $mailhead = $mailhead.show12hour($etime) ;
else $mailhead = $mailhead.$etime ;
$mailhead = $mailhead."\r\n".translate("Category").": ".stripslashes($catrow->cat_name) ;
$mailhead = $mailhead."\r\n".translate("Event Title").": ".stripslashes(stripslashes($title)) ;
$mailhead = $mailhead."\r\n".translate("Event Description").": \r\n\r\n" ;
$maildesc = "\r\n\r\n".translate("Email").": ".$email ;
$maildesc = $maildesc."\r\n".translate("More info").": ".$url ;
if ($repeat=="more") {
$maildesc = "\r\n\r\n ".translate("Event repeated")." ".$rtimes." ".translate("times every")." " ;
if ($rday==0) { $maildesc = $maildesc.translate("Day")." \r\n" ; }
else if ($rday==8) { $maildesc = $maildesc.translate("Two weeks")." \r\n" ; }
else if ($rday==9) { $maildesc = $maildesc.translate("Month")." \r\n" ; }
else if ($rday==10) { $maildesc = $maildesc.translate("Year")." \r\n" ; }
else { $maildesc = $maildesc.$week[$rday]." \r\n" ; }
}
mail($emailrcpt, "Event added - ".stripslashes(stripslashes($title))." (".$bday." ".$mth[$bmonth]." ".$byear.") ", $mailhead.stripslashes(stripslashes(str_replace("<br />", "", $description))).$maildesc,
"From: ".$nobody."\r\n"
."Reply-To: ".$nobody."\r\n");
}
$year = date("Y");
$repeatadd = 0 ;
if ($repeat == "more"){
$repeatset = false ;
if ($rday<8) {
while ($repeatadd<$rtimes) {
// run through a day at a time until correct day found then flag to set with repeatset
$mdate = date("d-m-Y", mktime(0, 0, 0, $bmonth, ++$bday, $byear)) ;
if ($rday==0) $repeatset = true ;
else if ($rday==(intval(date("w", mktime(0, 0, 0, $bmonth, $bday, $byear)))+1)){
$repeatset = true ;
}
if ($repeatset) {
$bday = substr("$mdate", 0, 2);
if (substr("$bday", 0, 1) == "0"){
$bday = str_replace("0", "", $bday);
}
$bmonth = substr("$mdate", 3, 2);
if (substr("$bmonth", 0, 1) == "0"){
$bmonth = str_replace("0", "", $bmonth);
}
$byear = substr("$mdate", 6, 4);
$query = "insert into ".$EVENTS_TB." values
('', '$timestamp', '$title', '$description', '$url', '$email', '$cat', '$stime', '$etime', '$bday', '$bmonth', '$byear', '$approve', '0', '$nobody', '')";
$result = mysql_query($query);
$repeatadd++ ;
$repeatset = false ;
}
}
}
else if ($rday==8) {
while ($repeatadd<$rtimes) {
// add 14 days each time to be every 2 weeks
$bday = $bday + 14 ;
$mdate = date("d-m-Y", mktime(0, 0, 0, $bmonth, $bday, $byear)) ;
$bday = substr("$mdate", 0, 2);
if (substr("$bday", 0, 1) == "0"){
$bday = str_replace("0", "", $bday);
}
$bmonth = substr("$mdate", 3, 2);
if (substr("$bmonth", 0, 1) == "0"){
$bmonth = str_replace("0", "", $bmonth);
}
$byear = substr("$mdate", 6, 4);
if (($year+$caladvanceyear)<(intval($byear))) break ;
$query = "insert into ".$EVENTS_TB." values
('', '$timestamp', '$title', '$description', '$url', '$email', '$cat', '$stime', '$etime', '$bday', '$bmonth', '$byear', '$approve', '0', '$nobody', '')";
$result = mysql_query($query);
$repeatadd++ ;
}
}
else if ($rday==9) {
while ($repeatadd<$rtimes) {
// add 1 month each time
$bmonth++ ;
if (date("t", mktime(0, 0, 0, $bmonth, 1, $byear))>=$bday) {
$mdate = date("d-m-Y", mktime(0, 0, 0, $bmonth, $bday, $byear)) ;
$bday = substr("$mdate", 0, 2);
if (substr("$bday", 0, 1) == "0"){
$bday = str_replace("0", "", $bday);
}
$bmonth = substr("$mdate", 3, 2);
if (substr("$bmonth", 0, 1) == "0"){
$bmonth = str_replace("0", "", $bmonth);
}
$byear = substr("$mdate", 6, 4);
if (($year+$caladvanceyear)<(intval($byear))) break ;
$query = "insert into ".$EVENTS_TB." values
('', '$timestamp', '$title', '$description', '$url', '$email', '$cat', '$stime', '$etime', '$bday', '$bmonth', '$byear', '$approve', '0', '$nobody', '')";
$result = mysql_query($query);
}
$repeatadd++ ;
}
}
else if ($rday==10) {
while ($repeatadd<$rtimes) {
// add 1 year each time
$byear++ ;
$mdate = date("d-m-Y", mktime(0, 0, 0, $bmonth, $bday, $byear)) ;
$bday = substr("$mdate", 0, 2);
if (substr("$bday", 0, 1) == "0"){
$bday = str_replace("0", "", $bday);
}
$bmonth = substr("$mdate", 3, 2);
if (substr("$bmonth", 0, 1) == "0"){
$bmonth = str_replace("0", "", $bmonth);
}
$byear = substr("$mdate", 6, 4);
if (($year+$caladvanceyear)<(intval($byear))) break ;
$query = "insert into ".$EVENTS_TB." values
('', '$timestamp', '$title', '$description', '$url', '$email', '$cat', '$stime', '$etime', '$bday', '$bmonth', '$byear', '$approve', '0', '$nobody', '')";
$result = mysql_query($query);
$repeatadd++ ;
}
}
}
if ($caleventapprove == 0) {
echo "<div class=normalfont align=center>";
echo translate("thankyou")."<br/>";
if ($copyevent) {
echo "<br/>"."<a class=normalfont href=\"#\" onclick='Javascript:self.window.close();top.opener.window.location.href=\"cal_popup.php?reload=y&op=view&id=$id\";
'>".translate("Close")."</a>"."</div>\n" ;
}
else echo "<br/><a class=normalfont href=\"#\" onclick='Javascript:window.close();top.opener.window.location.reload();'>".translate("Close")."</a></div>\n" ;
}
else {
echo "<div class=normalfont align=center>";
echo translate("thankyoupost")."<br/>";
if ($copyevent) {
echo "<br/><a class=normalfont href=\"#\" onclick='Javascript:self.window.close();top.opener.window.location.href=\"cal_popup.php?reload=y&op=view&id=$id\";
'>".translate("Close")."</a></div>\n" ;
}
else echo "<br/><a class=normalfont href=\"#\" onclick='Javascript:window.close();top.opener.window.location.reload();'>".translate("Close")."</a></div>\n" ;
}
}
}
?>
</body>
</html>
Other Calendars Scripts: