Script adapting: evenc

From phpCMS

Jump to: navigation, search

This article needs to be revisited! Integration of evenc 0.96 doesn't completely work following these instructions!

This tutorial shows how to integrate the free, PHP-based calendar "evenc" into a phpCMS-based website. For a short overview of evenc's functions, visit the evenc website.

Contents

[edit] Introduction

Evenc is a small, light-weight calendar script, which is still under development. The current version is 0.96. It requires two MySQL-tables and, of course, PHP support on your webserver. Main features are:

  • Calendar (monthly overview)
  • Agenda (ability to add events)
  • Comments (users can create comments to events)
  • Multilingualism (comes with german and english language files, other languages can be added easily)
  • Flexibility (easy integration into existing website designs)

However, the current version has some disadvantages, but most of them can be eliminated by some small modifications:

  • no user management (every website visitor is able to add events, workaround available)
  • editing/deleting of events and comments via admin website is not possible (you have to do this in the appropriate tables atm, workaround in progress)

[edit] Installation

Assumed that you have a website running phpCMS (only tested in 1.2.1pl2, but should work in previous versions, too) you just need to grab evenc from the evenc website (download link (41kb)) and follow these instructions:

  • create a directory "calendar" in your phpCMS-root-directory
  • extract the evenc-archive into that directory
  • follow the instructions in evenc's readme.txt (make "config.php" writeable, run install.php, delete install.php)

You should now be able to access the calendar-mainpage by calling "/calendar/index.php". If everything is working correctly, we can continue and integrate evenc into your phpCMS-website. I for myself wanted to show the monthly overview on every of my content-files and the event-list only when a user clicks on a day in that overview, so I'll describe how to do that. If you want to do something different, my description should give you enough hints to succeed. So what I did was I took the index.php and grabbed the parts that I needed.

[edit] Overview Table

The easiest way to show the overview on every content file is to include it as a plugin in a template file. To do so, follow these steps:

  • open config.php and add
$CONFIG["script_path"] = "/calendar"; //correct the path if necessary
  • create a file called "calendar_overview.php" (or accordingly) in your "calendar"-directory and copy&paste this code:
<?
require_once("./calendar/config.php"); //correct the path if necessary!!
require_once(".".$CONFIG["script_path"]."/php/dmts_functions.php");
//vars
$content      = array();
$lang         = array();
$error_level  = 0;

//load lang file
if(!is_file(".".$CONFIG["script_path"]."/lang/".$CONFIG["language"].".lang"))
  $CONFIG["language"] = "en"; //fall back to english
$lang = parse_ini_file(".".$CONFIG["script_path"]."/lang/".$CONFIG["language"].".lang", TRUE);

//set static content
$content["DATE"]                  = date("Y-m-d");  

$content["CONTENT"]               = "";

// connect DB
$db = mysql_connect($CONFIG["db_host"], $CONFIG["db_user"] ,$CONFIG["db_password"]) or die(mysql_error());;
mysql_select_db($CONFIG["db_name"]);

include(".".$CONFIG["script_path"]."/php/calendar.php");

dmts_echo(".".$CONFIG["script_path"]."/html/overview.html", $content);   

mysql_close($db);
?>

After that, create a file called "overview.html" in "calendar/html/":

<div class='evenc_calendar_box'>
  [_CALENDAR_]
</div>                

The "overview.html" is the second calendar-template file, which specifies the calendar's HTML-representation. The other one is called "calendar.html".

Now you're ready to include the calendar into your website. Place the following lines at the desired position in your phpCMS-template-file (e.g. header.tpl):

<phpcms:nofollow><phpcms:noindex>
{PLUGIN FILE="$home/calendar/calendar_overview.php" TYPE="DYNAMIC"}
</phpcms:noindex></phpcms:nofollow>

Don't forget to also include the calendar-stylesheet ("calender/design.css"), either by setting a link to it in your header-template or by adding these styles to your main stylesheet. Feel free to adapt the styles to your personal needs.

Now, if everything is working correctly, you should be able to see the overview table on every of your content pages. But there is one problem remaining: The calendar navigation (change of years/months) always returns you to your index-page. The fix for this is easy:

  • modify "calendar/php/calendar.php":
//init vars
$calendar = array();
$calendar["CURRENT_FILE"] = $_SERVER["REDIRECT_URL"]; // <-- add this line
$calendar["CALENDAR_DAYS"] = "";
  • open "calendar/html/calendar.html" and correct all four anchor-tags like this:
<a href='[_CURRENT_FILE_]?[_CALENDAR_LINK_YEAR_PREV_]...

[edit] Event List

We'll implement the event list in a content file: Create a new content file and call it "calendar.htm" or similiar. Set everything as needed ({PROJECT}, {MENU}, ...) and add a phpCMS-script-definition, which points to the following script (see How_to_include_third_party_php_scripts):

./calendar/calendar_event.php

After that, you need to add another line to the "calendar/config.php":

$CONFIG["calendar_file"]  = "calender.htm"; //name of the previously created content file

and create the file "calendar/calendar_event.php":

<?
require_once("./calendar/config.php"); //correct the path if necessary!!
require_once(".".$CONFIG["script_path"]."/php/dmts_functions.php");

//vars
$content      = array();
$lang         = array();
$error_level  = 0;

//load lang file
if(!is_file(".".$CONFIG["script_path"]."/lang/".$CONFIG["language"].".lang"))
  $CONFIG["language"] = "en"; //fall back to english
$lang = parse_ini_file(".".$CONFIG["script_path"]."/lang/".$CONFIG["language"].".lang", TRUE);

//set static content
$content["EVENC_VERSION"]         = "0.96";
$content["DATE"]                  = date("Y-m-d");  

$content["STRING_INPUT_NOTE"]     = &$lang["strings"]["input_note"];

$content["STRING_SEARCH_DEFAULT"] = &$lang["strings"]["search_default"];

$content["STRING_ADD_COMMENT"]    = &$lang["strings"]["add_comment"];
$content["STRING_COMMENT_NAME"]   = &$lang["strings"]["comment_name"];
$content["STRING_COMMENT_TEXT"]   = &$lang["strings"]["comment_text"];
$content["STRING_COMMENT_WROTE"]  = &$lang["strings"]["comment_wrote"];

$content["STRING_ADD_EVENT"]      = &$lang["strings"]["add_event"];
$content["STRING_EVENT_NAME"]     = &$lang["strings"]["event_name"];
$content["STRING_EVENT_LOCATION"] = &$lang["strings"]["event_location"];
$content["STRING_EVENT_TIME"]     = &$lang["strings"]["event_time"];
$content["STRING_EVENT_DESCRIPTION"]  = &$lang["strings"]["event_description"];
$content["STRING_EVENT_MORE"]     = &$lang["strings"]["event_more"];

$content["CONTENT"]               = "";

// connect DB
$db = mysql_connect($CONFIG["db_host"], $CONFIG["db_user"] ,$CONFIG["db_password"]) or die(mysql_error());;
mysql_select_db($CONFIG["db_name"]);

include(".".$CONFIG["script_path"]."/php/calendar.php");

if((isset($_GET["date"])) && (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $_GET["date"])))
    $content["DATE"] = $_GET["date"];
  else
    $content["DATE"] = date("Y-m-d"); //show today
    
$res = mysql_query("SELECT * FROM `".$CONFIG["db_table_prefix"]."event_list` WHERE `date` = '".$content["DATE"]."' ORDER BY `time`") or die(mysql_error());
$num = mysql_num_rows($res);  

    
$content["CONTENT"] .= "<h2>".$content["DATE"]."</h2><br />"; //$_GET["month"].$_GET["year"]."<br />";
if($num > 0)
{  
  for($i=0; $i < $num; $i++)
  {
	$event = array();
	$event["EVENT_NAME"]        = stripslashes(mysql_result($res, $i,"name"));
	$event["EVENT_TIME"]        = substr(mysql_result($res, $i,"time"),0,5);
	$event["EVENT_LOCATION"]    = stripslashes(mysql_result($res, $i,"location"));
	$event["EVENT_DESCRIPTION"] = dmts_parse_bbcode(stripslashes(mysql_result($res, $i,"description")));
	$event["EVENT_LINK"]        = "./".$CONFIG["calendar_file"]."?event=".mysql_result($res, $i,"id");
	$event["STRING_EVENT_MORE"] = &$content["STRING_EVENT_MORE"];
	$event["STRING_EVENT_TIME"] = &$content["STRING_EVENT_TIME"];
	
	//add calendar date to link
	if((isset($_GET["month"])) && (is_numeric($_GET["month"])))
	  $event["EVENT_LINK"]      .= "&month=".$_GET["month"];
	if((isset($_GET["year"])) && (is_numeric($_GET["year"])))
	  $event["EVENT_LINK"]      .= "&year=".$_GET["year"];          
	
	$content["CONTENT"] .= dmts_echos(".".$CONFIG["script_path"]."/html/event_box.html", $event);
	
	//wrap after every 2nd event
	if((($i+1)%2)==0)
	  $content["CONTENT"] .="<div class='evenc_event_wrap'></div>\n";
			
  }
  // finaly add wrap
  $content["CONTENT"] .="<div class='evenc_event_wrap'></div>\n";
}
else  // no event found
{
  $content["CONTENT"] .= dmts_echoss($lang["strings"]["no_event"], $content);
}

dmts_echo(".".$CONFIG["script_path"]."/html/event.html", $content);   

mysql_close($db);
?>

Finally, create another template-file for the calendar, "calendar/html/event.html":

[_CONTENT_] 

Please notice that I didn't want that every user has the ability to add events, so I cutted that part out in my solution. The easiest way to manage the events with this solution is to create a second calendar-directory, e.g. "calendar_admin", copy the original evenc-files in there and overwrite the config.php with the modified one from the "calendar"-directory. I'm going to integrate the original evenc-calendar with it's full functionality for this tutorial in the near future and then update the appropriate code segments. Until then, you'll need to be satisfied with the solution I use...

Main Page: Main Page | Top Page: Tutorials MainPage

Personal tools