php calendar??

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I have looked around for ages for a free php calendar with reasonable interface.

The trouble is, the good ones tend to have user functions and back end database already set up.

I already have an event db table and all I need is a bit of Javascript to produce a dynamic event calendar showing these events.

Something like Supercali

It has to be relatively simple to alter the db references and customise the .css to integrate it to my site.

Anyone got any ideas?
 

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
sorry i couldn't be more helpful.
good luck finding a script. ;)
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Any help on this would be appreciated and I will offer credits to someone who can point me in the right direction.

ALL my credits for someone who fancies writing the script for me! ;) (although I would prefer to understand and create it myself).
 

mattura

Member
Messages
570
Reaction score
2
Points
18
wow, all your credits...
Well I don't have time to script one I'm afraid. What you are looking for is potentially pretty complicated (if anything like supercal).
What do you have in your table? What views are required? It would save a lot of work if, say only a monthly view was needed. Is it necessary to have the seven-day layout? Or would a simple date-organised list of events do?
Are you sure you want javascript? If so, will you need AJAX, or download the whole database into javascript when the page first loads?
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Thanks for the response Matt.

All I'm after are two views - Month view and day view. (with navigation) or even just month, but a simple list is not what I'm after (I could do this fairly simply). Each cell would have the event title (EVTITLE) with a link carrying the EVID in the URL.

JS isn't critical although I'm not aware of a php system that can create calendar views.

I don't know much about AJAX so couldn't comment.

The .css should be relatively easy to alter to suit my colour scheme

http://www.freecrm.x10hosting.com/csstest.php

Each page would have user authentication (easy to add by referencing table:CONTACTS)

The table I am referencing is [EVENTS]

with the following field definitions

Code:
EVID (int,20 autoincrement, primary)
EVCONTIDL (varchar,20, null:yes) relational link
EVOPIDL (varchar,20, null:yes) relational link
EVGROUPCODE (varchar, 50,  null:no) workgroup id to seperate groups
EVCREATEDBY (varchar, 50, null:no)
EVCREATEDWHEN (varchar,30, null:no) epoch created with time()
EVEDITEDBY (varchar, 50, null:yes) 
EVEDITEDWHEN (varchar, 30, null:yes) epoch created with time()
EVTYPE (varchar, 30, null:yes) meeting, phone, todo etc.
EVTITLE (varchar, 50, null:yes) title.. duh
EVDESCRIPTION (longtext, null:yes)
EVMANAGER (varchar, 50, null:no) associated to a user
EVPRIORITY (varchar, 2, null:no) self-explanatory
EVSTART (varchar, 30, null:no) when the event starts in epoch format
EVDURATION (varchar, 30, null:no) how long is the event
EVCOMPLETED (varchar, 1, null:no, default "N") checkbox

All recordsets will use EVGROUPCODE to only see those records that match a session variable loaded on login.

The only filters I need are by EVMANAGER (drop-down list), EVCOMPLETED (Y or N) and EVTYPE (only about 5 options here from drop-down menu)

Don't want much do I? :lol:

I'm prepared to do the ground work but I do need quite a bit of guidance on this as my knowledge of JS is like... zero!
Edit:
OK Credit offer has now increased to 500
 
Last edited:

mattura

Member
Messages
570
Reaction score
2
Points
18
Ok, if nobody else does it in the meantime, I might look into this at the weekend. Unfortunately I'm working long hours these days... (on damned complicated c++ code)
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Ok, if nobody else does it in the meantime, I might look into this at the weekend. Unfortunately I'm working long hours these days... (on damned complicated c++ code)

c++ is scary!

Fortunately, I have done quite a bit of groundwork here and managed to get a month view created in php - but no dynamic links and no navigation yet...

The calendar page is at http://www.freecrm.x10hosting.com/crmcalendar/calendar_m.php

The code so far is

PHP:
<?php 
session_start();
//set page timezone
if ($_SESSION['MM_UTZ'] == NULL){
$_SESSION['MM_UTZ']="UTC";}
putenv ("TZ=".$_SESSION['MM_UTZ']);
//set page timeformat
if ($_SESSION['MM_UTF'] == NULL){
$_SESSION['MM_UTF']="Y-m-d H:i:s";
}
?>
<!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"><!-- InstanceBegin template="/Templates/fullpagetemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="EditRegionhead" -->
<title>Welcome to Free CRM</title>
<meta name="Description" content="Free CRM (Customer Relations Management) provides an unlimited fully functional online multi user CRM system." />
<meta name="Keywords" content="CRM, Customer Relations Management, PRM, Contact Management, Contact Database, Online, Opportunity, Tasks, Calendar, To Do, Reports" />
<style type="text/css">
.calday 
{
font-family: Arial;
border: 1px solid #006666;
background-color:#E3E9F1;
padding: 2px;
border-collapse: collapse;
empty-cells:show;
}
.caltoday {
font-family: Arial;
color:#FF3300;
border: 3px solid #006666;
background-color:#E3E9F1;
padding: 2px;
border-collapse: collapse;
empty-cells:show;
}
</style>
<?php
class Calendar
{ 
 function generate_calendar($year, $month, $day_func = NULL, $day_heading_length = 3)
 {
  $first_of_month = mktime (0,0,0, $month, 1, $year);
  static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  $maxdays   = date('t', $first_of_month); #number of days in the month
  $date_info = getdate($first_of_month);   #get info about the first day of the month
  $month     = $date_info['mon'];
  $year      = $date_info['year'];
  $calendar  = "<br /><table width='100%' class='datatable'>";
  $calendar .= "<tr><td colspan='7' class='databox'>$date_info[month] $year</td></tr>";
  $calendar .= "
   <tr class='dataheading'>
    <td class='databox'>Sun</td>
    <td class='databox'>Mon</td>
    <td class='databox'>Tue</td>
    <td class='databox'>Wed</td>
    <td class='databox'>Thu</td>
    <td class='databox'>Fri</td>
    <td class='databox'>Sat</td>
   </tr>"; 
   $calendar .= "<tr>";
   $class  = "";
   $weekday = $date_info['wday']; #weekday (zero based) of the first day of the month
   $day = 1; #starting day of the month
   #take care of the first "empty" days of the month
   if($weekday > 0)
   {
    $calendar .= "<td colspan='$weekday'> </td>";
   } #print the days of the month
   while ($day <= $maxdays)
   {
             if($weekday == 7)
    { #start a new week
     $calendar .= "</tr><tr>";
     $weekday = 0;
    }
    $linkDate =  mktime (0,0,0, $month, $day, $year);
    if((($day<10 AND "0$day"==date('d')) OR ($day>=10 AND "$day"==date('d'))) AND (($month<10 AND "0$month"==date('m')) OR ($month>=10 AND "$month"==date('m'))) AND $year==date('Y'))
    {
     $class="caltoday";
    } 
    else
    {
     $d = date('m/d/Y', $linkDate);
     $class = "calday";            
    }            
     $link = "dates.php?date=$linkDate";
     $calendar .= "<td class='$class'>$day</td>";            
     $day++;            
     $weekday++;        
    }        
    if($weekday != 7)
    {            
     $calendar .= "<td colspan='" . (7 - $weekday) . "'> </td>";        
    }        
    return $calendar . "</tr></table>";   
 }
}
?>
<!-- InstanceEndEditable -->
<link href="../css/page.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<?php include ("../includes/googleanalytics.php");?>
<body class="oneColFixCtr">
<div id="container">
<td>
<?php include ("../includes/header.php");?>
</td>
 <div id="mainContent">
 <!-- InstanceBeginEditable name="EditRegionmaincontent" -->
   <h1>Calendar</h1>
   <p>
      <?php 
 $MCal = new Calendar;
 echo $MCal -> generate_calendar(date('Y'), date('m'), $day_func = NULL, $day_heading_length = 3);
 ?>
    </p>
        
   <!-- InstanceEndEditable -->
   <!-- end #mainContent -->
</div>
<td>
<?php include("../includes/footer.php");?>
</td>
<!-- end #container -->
</div>
</body>
<!-- InstanceEnd --></html>
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
_____

This has come a long way since the beginning!

The whole calendar is now php driven with no JS!

PHP:
<?php require_once('../Connections/freecrm.php');?>

<?php //include ("../includes/setprefs.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"><!-- InstanceBegin template="/Templates/fullpagetemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="EditRegionhead" -->
<title>Welcome to Free CRM</title>
<meta name="Description" content="Free CRM (Customer Relations Management) provides an unlimited fully functional online multi user CRM system." />
<meta name="Keywords" content="CRM, Customer Relations Management, PRM, Contact Management, Contact Database, Online, Opportunity, Tasks, Calendar, To Do, Reports" />

<style type="text/css">
/*all of the table*/
.caltable 
{
font-family: Arial;
empty-cells: hide;
border: none;
}
/*month and year header*/
.calheading
{
font-size: 14px;
font-weight: bold;
border: 1px solid #006666;
background-color:#99CCCC;
padding: 2px;
empty-cells:show;
}

/*days of the week cells*/
.calday
{
font-size: 11px;
font-style: italic;
border: 1px solid #006666;
background-color:#ccc;
padding: 2px;
empty-cells:show;
}
/*date cells that are not today*/
.caldate 
{
font-size: 11px;
border: 1px solid #006666;
background-color:#E3E9F1;
padding: 2px;
empty-cells:show;
vertical-align: text-top;
}
/*date cells that are today*/
.caldatetoday {
font-size: 11px;
font-weight: bold;
color:#FF3300;
border: 3px solid #006666;
background-color:#FCEBC2;
padding: 2px;
empty-cells:show;
}
</style>

<?php mysql_select_db($database_freecrm, $freecrm);?>

<?php
class Calendar
{ 
	function generate_calendar($year, $month, $day_func = NULL, $day_heading_length = 3)
	{
		$first_of_month = mktime (0,0,0, $month, 1, $year);//first of the month
		static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		$maxdays   = date('t', $first_of_month); //number of days in the month
        $date_info = getdate($first_of_month);   //get info about the first day of the month
        $month = $date_info['mon']; //get name of month
        $year = $date_info['year']; // get year
        $calendar = "<br /><table width='100%' class='caltable'>"; //create table
        $calendar .= "<tr><td colspan='7' class='calheading'>$date_info[month] $year</td></tr>"; //create header with Month & Year
         //create days of week header
		$calendar .= "
        	<tr>
            	<td class='calday'>Sun</td>
            	<td class='calday'>Mon</td>
            	<td class='calday'>Tue</td>
            	<td class='calday'>Wed</td>
            	<td class='calday'>Thu</td>
            	<td class='calday'>Fri</td>
            	<td class='calday'>Sat</td>
         	</tr>
		"; 
		//start of main repeating date cells
        $calendar .= "<tr>";
        $class  = "";
        $weekday = $date_info['wday']; //weekday (zero based) of the first day of the month
        $day = 1; //starting day of the month
        //take care of the first "empty" days of the month
        if($weekday > 0)
        {
			$calendar .= "<td colspan='$weekday'> </td>";
		} //print the days of the month
        while ($day <= $maxdays)
        {
        	if($weekday == 7)
            { //start a new week
            	$calendar .= "</tr><tr>";
            	$weekday = 0;
			}
            $linkDate =  mktime (0,0,0, $month, $day, $year);
			if((($day<10 AND "0$day"==date('d')) OR ($day>=10 AND "$day"==date('d'))) AND (($month<10 AND "0$month"==date('m')) OR ($month>=10 AND "$month"==date('m'))) AND $year==date('Y'))
			{
				$class="caldatetoday";
			} 
			else
			{
				$d = date('m/d/Y', $linkDate);
				$class = "caldate";
			} 
			//output date    
			$link = "dates.php?date=$linkDate";
			$query_RS_Events = "SELECT EVID, EVGROUPCODE, EVCOMPLETED, EVSTART, EVDURATION, EVMANAGER, EVTITLE FROM EVENTS WHERE EVSTART LIKE '$linkDate' ";
			$RS_Events = mysql_query($query_RS_Events) or die(mysql_error());
			$totalRows_RS_Events = mysql_num_rows($RS_Events);
			$calendar .= "<td class='$class'>
			".$day."<br>";
			do
			{
				$calendar .= $linkDate."
				<a href='../crmevents/updateevent.php?evid=".$row_RS_Events['EVID']."' target='_blank'>".$row_RS_Events['EVTITLE']."</a><br/>
				";
			}
       		while ($row_RS_Events = mysql_fetch_assoc($RS_Events));
   			mysql_free_result($RS_Events);
			$calendar .= "
  			</td>
  			";  
			//finish output
			//increase day and weekday by 1          
            $day++;            
            $weekday++;        
		}        
		if($weekday != 7)
		{            
			$calendar .= "<td colspan='" . (7 - $weekday) . "'> </td>";        
		}        
		return $calendar . "</tr></table>";   
	}
}
?>

<?php
//define month and year to view
//if post value is empty, fill with now
if (!isset($_POST['selectyear']))
{
     $yeartoview = date('Y');
}
else //or filled with value from form
{
	$yeartoview = $_POST['selectyear'];
}

if (!isset($_POST['selectmonth']))
{
     $monthtoview = date('m');
}
else
{
	$monthtoview = $_POST['selectmonth'];
}
?>


<!-- InstanceEndEditable -->
<link href="../css/page.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

</head>
<?php include ("../includes/googleanalytics.php");?>

<body class="oneColFixCtr">

<div id="container">
<td>
<?php include ("../includes/header.php");?>
</td>
 <div id="mainContent">
 <!-- InstanceBeginEditable name="EditRegionmaincontent" -->
   <h1>Calendar</h1>
   
   <form name="form1" method="post" action="">
	Month:
	<select name="selectmonth" id="selectmonth">
	<option value="<?php echo $monthtoview;?>" selected><?php echo $monthtoview;?></option>
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="03">03</option>
	<option value="04">04</option>
	<option value="05">05</option>
	<option value="06">06</option>
	<option value="07">07</option>
	<option value="08">08</option>
	<option value="09">09</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	</select>
	Year: 
    <select name="selectyear" id="selectyear">
	<option value="<?php echo $yeartoview;?>" selected><?php echo $yeartoview;?></option>
    <option value="2001">2001</option>
    <option value="2002">2002</option>
	<option value="2003">2003</option>
	<option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
	<option value="2007">2007</option>
	<option value="2008">2008</option>
	<option value="2009">2009</option>
	<option value="2010">2010</option>
	<option value="2011">2011</option>
	<option value="2012">2012</option>
	<option value="2013">2013</option>
	<option value="2014">2014</option>
	<option value="2015">2015</option>
	<option value="2016">2016</option>
	<option value="2017">2017</option>
	<option value="2018">2018</option>
	<option value="2019">2019</option>
	<option value="2020">2020</option>
	</select>
	User:
	
	<label>
	<select name="selectuser2" id="selectuser2">
	  </select>
	</label>
	<input type="submit" name="Submit" value="Submit">
	</form>

   
   	<p>
    <?php 
	$cal_m = new Calendar;
	echo $cal_m -> generate_calendar($yeartoview, $monthtoview, $day_func = NULL, $day_heading_length = 3);
	?>
    </p>
        
   <!-- InstanceEndEditable -->
   <!-- end #mainContent -->
</div>
<td>
<?php include("../includes/footer.php");?>
</td>
<!-- end #container -->
</div>
</body>
<!-- InstanceEnd --></html>

This is the whole page (excluding includes) and the page works well - ish (link to page above)

The only problem I have is the the $linkDate variable created on each do..while is an epoch number based just on year month and date which generates a number with a double zero at the end.

I need to reference this variable in the sql but the values in the db are complete timestamps, including time.

As a result, the two values do not match exactly and I get no recordset returned.

How do I shorten or amend either value so I can get a like comparison?

i.e. WHERE EVSTART(full timestamp) LIKE $linkDate (partial timestamp)

When this is cracked, I think I'm pretty much done....
 

mattura

Member
Messages
570
Reaction score
2
Points
18
That's a nice start, I'm liking the style.
You could have used thead (for the Sun,Mon...) and tbody for the cells, styling them appropriately, but not essential.

It seems to me you have two options with javascript. But before that, its would be a great idea to code it all in php (same effect, but with page refreshing). You have made a great start.

When it's working in php, you can add the javascript, your options being:
Use AJAX, which basically can retrieve data by means of another php file without refreshing the page, placing it in some container (eg div).
OR use javascript only, downloading ALL your calendar events with the page load, storing them in arrays, and displaying only what is needed.
The latter solution will take a long time to download if your calendar database is large., but be quicker when loaded.
Let me know.

yeah c++ can be a pain, especially when someone else's code that you have to figure out (what were they thinking with a function name like "PositionLeftFromToOfFromBottomFrom()"?!! I kid you not...), but I have to work with it now!
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
That's a nice start, I'm liking the style.
You could have used thead (for the Sun,Mon...) and tbody for the cells, styling them appropriately, but not essential.

It seems to me you have two options with javascript. But before that, its would be a great idea to code it all in php (same effect, but with page refreshing). You have made a great start.

When it's working in php, you can add the javascript, your options being:
Use AJAX, which basically can retrieve data by means of another php file without refreshing the page, placing it in some container (eg div).
OR use javascript only, downloading ALL your calendar events with the page load, storing them in arrays, and displaying only what is needed.
The latter solution will take a long time to download if your calendar database is large., but be quicker when loaded.
Let me know.

yeah c++ can be a pain, especially when someone else's code that you have to figure out (what were they thinking with a function name like "PositionLeftFromToOfFromBottomFrom()"?!! I kid you not...), but I have to work with it now!

I'm not sure I even need any JS now.

The only thing I need to sort is the comparison with these two variables.

When thats done, the recordset within the do..while will return the right values and echo the titles and links dynamically within the box with the right links.

Almost there - so veeeery close....
 

mattura

Member
Messages
570
Reaction score
2
Points
18
well took me a while to figure out what you meant!

You can get the bounds $linkdate1=day x @ 00:00:00 and $linkdate2=day x @23:59:59
and have:
WHERE EVSTART>$linkdate1 AND EVSTART<$linkdate2

There are problems with using timestamps in calendars - eg that they are only in the range 1970-2037. It might be better to store a date field, and a time field separately (then you don't need to SELECT the time when not necessary, and have no timestamp issues)
Edit:
Good luck mate, I'm off to bed (early start and all), I'll check back tomo
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
You can get the bounds $linkdate1=day x @ 00:00:00 and $linkdate2=day x @23:59:59
and have:
WHERE EVSTART>$linkdate1 AND EVSTART<$linkdate2

Matt - thanks but... not working yet.

I'll try again tomorrow - getting more problems with additional functions...
 

mattura

Member
Messages
570
Reaction score
2
Points
18
do you have something like this:
PHP:
 $linkDate =  mktime (0,0,0, $month, $day, $year); 
 $linkDateEnd = mktime(23,59,59, $month, $day, $year);
 ...
 $query_RS_Events = "SELECT EVID, EVGROUPCODE, EVCOMPLETED, EVSTART, EVDURATION, EVMANAGER, EVTITLE FROM EVENTS WHERE EVSTART > '$linkDate' AND EVSTART < '$linkDateEnd' ";
?
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
LOL - should have thought of that!!!

Works a treat and finally, all the values are now coming through correctly and it looks awesome.

This is now a very powerful script and one that is not easy to achieve without Javascript!

I only have one problem now.

At the top of the script is a recordset created of users (RS_Users). I have a form with 3 fields (drop-down) which calls this recordset and it isn't calling results from the recordset!

I have butchered this script so many times now, there's probably a simple error but I can't find it!

Ideally, I would have alist drop-down with multiple selections but I haven't got a clue how to do this.

Matt I'm giving you 100 cres for the fact that you've stuck with it!

Current Code attached
 

Attachments

  • calendar_m.php.txt
    9.5 KB · Views: 65

exemption

New Member
Messages
66
Reaction score
0
Points
0
I could create something like this for you for a measly 600 or 900 credits..
I will message you once I have a small sample finished...
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Hey thanks for the credits, glad I was able to help.
I may be able to take a look at it tomorrow, as you know I don't have a lot of time these days!

exemption - he's already done pretty much all of the work!
 
Top