Location: PHPKode > scripts > LuxCal Web Based Event Calendar > upgrade232.php
<?php
/*
!!!!!!! THIS SCRIPT MUST BE RUN WHEN UPGRADING FROM A PREVIOUS TO A NEWER LUXCAL VERSION !!!!!!!

© Copyright 2010 LuxSoft - Luxembourg - www.LuxSoft.eu
*/

if (!$link) { echo "No database connection"; exit; }

if (!isset($dbPrefix)) { $dbPrefix =""; }

/* ===== As of LuxCal 1.6 ===== */

//Update MySQL database structure and give administrator full rights
//Test for column 'post' - if found, rename it to 'privs' and drop column 'view'
$result = mysql_query("SELECT post FROM ".$dbPrefix."users");
if ($result) { // column 'post' present - rename 'post' to 'privs'
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."users CHANGE post privs TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'");
	if ($altered) { 
		$result = mysql_query("ALTER TABLE ".$dbPrefix."users DROP view");
		$result = mysql_query("UPDATE ".$dbPrefix."users SET privs = 3 WHERE user_id = 2");
	}
}

/* ===== As of LuxCal 2.0 ===== */

//Update database structure for advanced repeat capability
//Add to dates table: a_date (date added), m_date (date modified) and status (<0: deleted)
$result = mysql_query("SELECT r_type FROM ".$dbPrefix."dates");
if (!$result) { // column 'r_type' not present, create 'repeat' fields
	//add columns for enhanced repeat + deleted field
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."dates 
		ADD r_type TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER e_time,
		ADD r_interval TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER r_type,
		CHANGE recur r_period TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
		ADD r_until DATE NOT NULL DEFAULT '9999-00-00' AFTER r_period,
		ADD a_date DATE NOT NULL DEFAULT '9999-00-00',
		ADD m_date DATE NOT NULL DEFAULT '9999-00-00',
		ADD status TINYINT(1) NOT NULL DEFAULT '0'
		");
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."events
		MODIFY not_mail VARCHAR(256) DEFAULT NULL
		");
	//copy previous repeat values
	$result = mysql_query("UPDATE ".$dbPrefix."dates SET r_type = 1, r_interval = 1, r_until = e_date, e_date = '9999-00-00' WHERE r_period > 0");
}
//Add column to user table: language (user interface language)
$result = mysql_query("SELECT language FROM ".$dbPrefix."users");
if (!$result) { // column 'language' not present; create it
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."users
		ADD language VARCHAR(32) DEFAULT NULL
		");
}

/* ===== As of LuxCal 2.1 ===== */

//Add to dates table: Primary key to optimize speed
$result = mysql_query("SELECT event_id FROM ".$dbPrefix."dates");
$flags = mysql_field_flags($result, 0);
if (strpos($flags, "primary_key") === false) {
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."dates
		ADD PRIMARY KEY (event_id)
		");
}

/* ===== As of LuxCal 2.3 ===== */

//Add columns to users table: login_0 (first login), login_1 (last login) and login_cnt (number of logins)
$result = mysql_query("SELECT login_0 FROM ".$dbPrefix."users");
if (!$result) { // column 'login_0' not present; create login_0 and login_1
	$altered = mysql_query("ALTER TABLE ".$dbPrefix."users
		ADD login_0 DATE NOT NULL DEFAULT '9999-00-00' AFTER privs,
		ADD login_1 DATE NOT NULL DEFAULT '9999-00-00' AFTER login_0,
		ADD login_cnt INT(8) NOT NULL DEFAULT '0' AFTER login_1
		");
}

//Validate / set config parameter values
if (!isset($calendarTitle)) { $calendarTitle = "LuxCal Calendar"; }
if (!isset($calendarUrl)) { $calendarUrl = $_SERVER['SERVER_NAME'].preg_replace("%upgrade\d{2,3}\.php$%","",$_SERVER["PHP_SELF"]); }
if (!isset($calendarEmail)) { $calendarEmail = "hide@address.com"; }
if (!isset($timeZone)) { $timeZone = "Europe/Amsterdam"; }
if (!isset($defaultView) or $defaultView < 1 or $defaultView > 5) { $defaultView = 2; }
if (!isset($language)) { $language = "English"; }
if (!isset($langMenu) or $langMenu < 0 or $langMenu > 1) { $langMenu = 0; }
if (!isset($chgEmailList)) { $chgEmailList = ""; }
if (!isset($chgNofDays) or $chgNofDays < 0 or $chgNofDays > 30) { $chgNofDays = 1; }
if (!isset($selfReg) or $selfReg < 0 or $selfReg > 1) { $selfReg = 0; }
if (!isset($selfRegPrivs) or $selfRegPrivs < 0 or $selfRegPrivs > 3) { $selfRegPrivs = 1; }
if (!isset($maxNoLogin) or $maxNoLogin < 0 or $maxNoLogin > 365) { $maxNoLogin = 0; }
if (!isset($colsToShow) or $colsToShow < 1 or $colsToShow > 6) { $colsToShow = 3; }
if (!isset($rowsToShow) or $rowsToShow < 1 or $rowsToShow > 10) { $rowsToShow = 4; }
if (!isset($weeksToShow) or $weeksToShow < 1 or $weeksToShow > 20) { $weeksToShow = 10; }
if (!isset($upcomingDays) or $upcomingDays < 1 or $upcomingDays > 30) { $upcomingDays = 14; }
if (!isset($startHour) or $startHour < 0 or $startHour > 10) { $startHour = 6; }
if (!isset($showOwner) or $showOwner < 0 or $showowner > 1) { $showOwner = 1; }
if (!isset($dateFormat) or $dateFormat < 1 or $dateFormat > 3) { $dateFormat = 1; }
if (!isset($dateUSorEU) or $dateUSorEU < 0 or $dateUSorEU > 1) { $dateUSorEU = 1; }
if (!isset($dateSep) or strlen($dateSep) != 1 or strpos(".-/", $dateSep) === false) { $dateSep = "."; }
if (!isset($time24) or $time24 < 0 or $time24 > 1) { $time24 = 1; }
if (!isset($weekStart) or $weekStart < 0 or $weekStart > 1) { $weekStart = 1; }

//Generate config.php content
$config = "<?php\n".
"/*\n= LuxCal event calendar configuration file =\nThe LuxCal event calendar is a LuxSoft product\n*/\n\n".
'//LuxCal config file version'."\n".
'define("LCC","2.3.2");'."\n\n".
'//Database credentials'."\n".
'$hn = "'.$hn.'";'."\n".
'$db = "'.$db.'";'."\n".
'$un = "'.$un.'";'."\n".
'$pw = "'.$pw.'";'."\n\n".
'$dbPrefix = "'.$dbPrefix.'"; //prefix for database table names'."\n\n".
'$calendarTitle = "'.$calendarTitle.'"; //Calendar title displayed in the top bar'."\n\n".
'$calendarUrl = "'.$calendarUrl.'"; //Calendar location (URL)'."\n\n".
'$calendarEmail = "'.$calendarEmail.'"; //Sender in email notifications'."\n\n".
'$timeZone = "'.$timeZone.'"; //Calendar time zone'."\n\n".
'$defaultView = '.$defaultView.'; //Calendar view at start-up (1: year, 2: month, 3: week 4: day, 5: upcoming, 6: changes)'."\n\n".
'$language = "'.$language.'"; //User interface language'."\n\n".
'$langMenu = '.$langMenu.'; //Display ui-language selection menu'."\n\n".
'$chgEmailList = "'.$chgEmailList.'"; //Destin. email addresses for calendar changes'."\n\n".
'$chgNofDays = '.$chgNofDays.'; //Number of days to look back for calendar changes'."\n\n".
'$selfReg = '.$selfReg.'; //Self-registration (1: enabled 0: disabled)'."\n\n".
'$selfRegPrivs = '.$selfRegPrivs.'; //Self-reg rights (1: view, 2: post self, 3: post all)'."\n\n".
'$maxNoLogin = '.$maxNoLogin.'; //Number of days not logged in, before deleting user account (0: never delete)'."\n\n".
'$colsToShow = '.$colsToShow.'; //Number of months to show per row in year view'."\n\n".
'$rowsToShow = '.$rowsToShow.'; //Number of rows to show in year view'."\n\n".
'$weeksToShow = '.$weeksToShow.'; //Number of weeks to show in month view'."\n\n".
'$upcomingDays = '.$upcomingDays.'; //Number of days to look ahead in upcoming view'."\n\n".
'$startHour = '.$startHour.'; //Day/week view start hour'."\n\n".
'$showOwner = '.$showOwner.'; //Show owner of events in views and email messages'."\n\n".
'$dateFormat = '.$dateFormat.'; //Event date format (1: dd-mm-yyyy, 2: mm-dd-yyyy, 3: yyyy-mm-dd)'."\n\n".
'$dateUSorEU = '.$dateUSorEU.'; //Calendar date format (0: Monday, May 12, 2010, 1: Monday 12 May 2010)'."\n\n".
'$dateSep = "'.$dateSep.'"; //Date separator (. - or /)'."\n\n".
'$time24 = '.$time24.'; //Time format (0: 12-hour am/pm, 1: 24-hour)'."\n\n".
'$weekStart = '.$weekStart.'; // Week starts on Sunday(0) or Monday(1)'."\n\n".
"?>\n";

//Save config.php
file_put_contents("config.php", $config);
?>
Return current item: LuxCal Web Based Event Calendar