############################################################## 
## MOD Title: 	Calendar - EM Friendly
## MOD Author: 	WebSnail < Martin Smallridge > (WebSnail) http://www.snailsource.com/forum/ 
## Description: Add-on, plug-in Calendar for phpBB2 
## 
## MOD Version: 1.4.6
##
## Installation Level: moderate
## Installation Time: 10 Minutes 
## Files To Edit: 6
##		admin/admin_ug_auth.php
##		admin/admin_db_utilities.php
##		includes/page_header.php
##		includes/functions.php
##		templates/subSilver/admin/auth_ug_body.tpl
##		templates/subSilver/overall_header.tpl
##
## Included Files: 0 
##
##############################################################
## Author Notes:
##  	  Please read readme.txt
##
##	!! ATTENTION: CATEGORY HEIRACHY MOD USERS !!
##
##	Category Heirachy Users should not apply the modifications for:
##	- admin/admin_ug_auth.php
##	- templates/subSilver/admin/auth_ug_body.tpl
##
##	The mod is not directly compatible and instead 2 seperate Calendar
##	permission links are provided in the admin control panel.
##
##############################################################
## This MOD is released under the GPL License. 
## Intellectual Property is retained by the MOD Author(s) listed above 
############################################################## 
## Please note that this MOD is NOT listed on phpBB.com's main
## site and should under no circumstances be trusted as secure
## and genuine unless downloaded from the Snailsource.com web
## site.
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up ALL Files Related To This MOD 
############################################################## 
# 
#-----[ DIY INSTRUCTIONS ]------------------------------------------ 
#
After uploading the cal_install.php file and the cal_install folder and its contents
to the root of your forum folder, go ahead and run the cal_install.php from 
your browser.  The path to the file in your browser should look something like this:

http://yourdomain.com/phpBB2/cal_install.php

Of course yourdomain.com would be replaced with your domain name and if your 
forum folder is named something other than phpBB2, change it to whatever you 
use.  Once you have completed the DB Update file, you should delete the cal_install.php 
file and the cal_install folder and its contents from the root of your forum folder...
# 
#-----[ COPY ]------------------------------------------ 
#
copy cal_install.php to cal_install.php
copy cal_lite.php to cal_lite.php
copy cal_lite_functions.php to cal_lite_functions.php
copy cal_lite_settings.php to cal_lite_settings.php
copy calendar.php to calendar.php
copy admin/*.php to admin/*.php
copy cal_install/*.php to cal_install/*.php
copy cal_install/schema/*.sql to cal_install/schema/*.sql
copy language/lang_english/lang_calendar.php to language/lang_english/lang_calendar.php
copy language/lang_english/email/cal_event_notify.tpl to language/lang_english/email/cal_event_notify.tpl
copy templates/subSilver/*.tpl to templates/subSilver/*.tpl
copy templates/subSilver/admin/*.tpl to templates/subSilver/admin/*.tpl
copy templates/subSilver/images/icon_mini_calendar.gif to templates/subSilver/images/icon_mini_calendar.gif
# 
#-----[ OPEN ]------------------------------------------ 
#
admin/admin_ug_auth.php
# 
#-----[ FIND ]------------------------------------------ 
# 
$user_id = intval($user_id);
# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
// MOD update... Because of the way that phpBB2 checks for some vars as empty we need to split the 2 up
$params = array('callevel' => 'callevel', 'gallerylevel' => 'gallerylevel', 'linkzlevel' => 'linkzlevel');
while( list($var, $param) = @each($params) )
{
	if ( isset($HTTP_POST_VARS[$param]) || isset($HTTP_GET_VARS[$param]) )
	{
		$$var = ( isset($HTTP_POST_VARS[$param]) ) ? $HTTP_POST_VARS[$param] : $HTTP_GET_VARS[$param];
	}
	else
	{
		$$var = "";
	}
}
# 
#-----[ FIND ]------------------------------------------ 
# 
//
// Carry out requests
# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
	// 
	// MOD Calendar
	// Carry out update request for calendar
	if ( $mode == 'user' && ($callevel || $callevel == '0')) {
		$sql = "UPDATE ". USERS_TABLE ." SET user_calendar_perm = ". $callevel
			." WHERE user_id = $user_id";
		}
	if ( $mode == 'group' && ($callevel || $callevel == '0')) {
		$sql = "UPDATE ". GROUPS_TABLE ." SET group_calendar_perm = ". $callevel
			." WHERE group_id = $group_id";
		}
	if ( !($result = $db->sql_query($sql)) ) {
		message_die(GENERAL_ERROR, 'Could not update Calendar level', '', __LINE__, __FILE__, $sql);
		}
	// END Mod Calendar

# 
#-----[ FIND ]------------------------------------------ 
# 
$name = array();
# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
	// MOD Calendar
	// Query the appropriate table database re: group or user permissions.

	if ( $mode == 'user' )
	{
		// Check the Users record
		$sql = "SELECT user_calendar_perm FROM ". USERS_TABLE ." WHERE user_id = $user_id";
	}
	else {
		// Check Group
		$sql = "SELECT group_calendar_perm FROM ". GROUPS_TABLE ." WHERE group_id = $group_id";
	}
	$result = $db->sql_query($sql);
	if (!$result) { 
	   message_die(GENERAL_MESSAGE, 'Could not access the Calendar Permission for User', "", __LINE__, __FILE__, $sql); 
	} 
	$user_temp = $db->sql_fetchrow($result);
	if ($mode == 'user') {
		$cal_perm = $user_temp['user_calendar_perm'];
		}
	else {
		$cal_perm = $user_temp['group_calendar_perm'];
		}
	if (!$cal_perm && $cal_perm !='0')	{
		message_die(GENERAL_MESSAGE, 'Calendar Permissions Unavailable (ERR: ug_auth)', "", __LINE__, __FILE__, $sql);
		}
	$cal_levels[0] = $lang['no_public']; 
	$cal_levels[1] = $lang['view_only']; 
	$cal_levels[2] = $lang['view_suggest']; 
	$cal_levels[3] = $lang['view_add']; 
	$cal_levels[4] = $lang['view_edit_own']; 
	$cal_levels[5] = $lang['cal_admin']; 
	$s_cal_type = "<select name='callevel'>";
	for ($i=0; $i<=5; $i++) {
		$s_cal_type .="<option value='". $i;
		if ($i == $cal_perm) {
			$s_cal_type .="' selected='selected'>";
			}
		else {
			$s_cal_type .="'>";
			}
		$s_cal_type .= $cal_levels[$i] ."</option>";
		}
	$s_cal_type .="</select>";
	// End MOD Calendar

# 
#-----[ FIND ]------------------------------------------ 
# 
'USER_LEVEL' => $lang['User_Level'] . " : " . $s_user_type,
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
			'USER_CAL_LEVEL' => "Calendar Level : " . $s_cal_type,
# 
#-----[ FIND ]------------------------------------------ 
# 
		$template->assign_vars(array(
# 
#-----[ FIND ]------------------------------------------ 
# 
'USERNAME' => $t_groupname,
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
			'GROUP_CAL_LEVEL' => "Calendar Level : " . $s_cal_type,
# 
#-----[ OPEN ]------------------------------------------ 
#
admin/admin_db_utilities.php
# 
#-----[ FIND ]----------------------------------------------------------------------
# 
$tables = array('auth_access', 'banlist', 
# 
#-----[ IN-LINE FIND ]----------------------------------------------------------------------
# 
$tables = array('auth_access', 'banlist', 
# 
#-----[ IN-LINE AFTER, ADD]------------------------------------------ 
# 
'cal_config', 'calendar',
# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/admin/auth_ug_body.tpl
# 
#-----[ FIND ]------------------------------------------ 
# 
<!-- BEGIN switch_user_auth -->
# 
#-----[ FIND ]------------------------------------------ 
# 
<p>{USER_LEVEL}</p>
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
<p>{USER_CAL_LEVEL}</p>	<!-- MOD Calendar -->
# 
#-----[ FIND ]------------------------------------------ 
# 
<!-- BEGIN switch_group_auth -->
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
<p>{GROUP_CAL_LEVEL}</p>	<!-- MOD Calendar -->
# 
#-----[ OPEN ]------------------------------------------ 
#
includes/functions.php
# 
#-----[ FIND ]------------------------------------------ 
# 
if ( defined('IN_ADMIN') )
# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
//
// MOD Load Calendar Language File
//
	if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_calendar.'.$phpEx)) ) 
	{ 
		$board_config['default_lang'] = 'english'; 
	} 

	include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_calendar.' . $phpEx);

// End MOD

# 
#-----[ OPEN ]------------------------------------------ 
#
includes/page_header.php
# 
#-----[ FIND ]------------------------------------------ 
# 
else
{
	$u_login_logout = 'login.'.$phpEx;
	$l_login_logout = $lang['Login'];
}
# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 
else
{
	// Mod Calendar
	if (isset($caluser)) {
		$u_login_logout = 'login.'.$phpEx.'?redirect=cal_lite.'.$phpEx;
		}
	else {
		$u_login_logout = 'login.'.$phpEx;
		}
	// End Mod for Calendar
	$l_login_logout = $lang['Login'];
}
# 
#-----[ FIND ]------------------------------------------ 
# 
'L_WHOSONLINE_MOD' => 
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
	'L_CALENDAR' => $lang['Calendar'],
# 
#-----[ FIND ]------------------------------------------ 
# 
'U_GROUP_CP' =>
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
	'U_CALENDAR' => append_sid('cal_lite.'.$phpEx),
# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/overall_header.tpl
# 
#-----[ FIND ]------------------------------------------ 
# 
{L_USERGROUPS}
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
							<a href="{U_CALENDAR}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_calendar.gif" width="12" height="13" border="0" alt="{L_CALENDAR}" hspace="3" />{L_CALENDAR}</a>&nbsp; &nbsp;
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM