PHP Error - help needed


#1

Hey, I am very new to PHP and I got this code that I am trying to work through the kinks on…

The current error I get is “Cannot redeclare checkdate”… which is a function towards the bottom 1/3 … if anyone has ideas I would love the help.

The code is:

[code]<?php
// Dave Horn’s Team Exports Tracker - this simplified version tracks team exports and ST exports
// Visit www.hitforthecycle.com for the best OOTP League on the net
// dave@hitforthecycle.com

// Directions for use of this file
// Set the 5 (line #10-#14) variables below so they are appropriate to your league server set up
// Modify the getTeamName function (line #156) below so the program knows the name of each of your teams

$exportDir = '../www/lineups';   // this must point to the directory where team exports and FA/ST files are stored
$leagueFile = '';  // full path and name to your league file here
$numTeams = 20; // set this equal to the total number of your teams in your league
$L1 = 'Northern League';
$L2 = 'Southern League';


print("<HTML>");
print("<TITLE>Team Export List</TITLE>");
print("<BODY>");

$files = scandir($exportDir);
//print('<pre>');
//print_r($files);
//print('</pre>');



print('<table border="0" width="100%" cellpadding="2" cellspacing="0">');
print('<tr bgcolor="#0E3259">');
$curDate = date("n.d g:ia");
print("<th colspan="6"><font color="WHITE">NABA Team Export File Status - Current Time: $curDate (PST)</font></th>");
print('</tr>');
print('<tr bgcolor="#0E3259">');
print('<th colspan="3"><font color="WHITE">'.$L1.'</font></th>');
print('<th colspan="3"><font color="WHITE">'.$L2.'</font></th>');
print('</tr>');
print('<tr bgcolor="#5E658C">');
print('	<td width="25%"><font color="WHITE">Team</font></td>
				<td width="15%"><font color="WHITE">Export Date</font></td>
				<td width="10%"><font color="WHITE">ST&nbsp;</font></td>
				<td width="25%"><font color="WHITE">Team</font></td>
				<td width="15%"><font color="WHITE">Export Date</font></td>
				<td width="10%"><font color="WHITE">ST&nbsp;</font></td>');
print('</tr>');

$basedir = $exportDir;
$base = "Team";
$stbase = "Teamst";
$ext = ".exp";
$fabase = "fat";
$faext = ".dat";

for ($i = 1; $i <= 10; $i++) {
	$NL = $base.$i.$ext;
	$NLST = $stbase.$i.$ext;
	$j = $i + 10;
	$SL = $base.$j.$ext;
	$SLST = $stbase.$j.$ext;

	if (checkDate($NL, $basedir)) {
		print("<tr><td bgcolor="#EA947B">".getTeamName($NL)."</td><td bgcolor="#EA947B">".getFileDate($NL, $basedir)."</td>");
	} else {
		print("<tr><td bgcolor="#95D096">".getTeamName($NL)."</td><td bgcolor="#95D096">".getFileDate($NL, $basedir)."</td>");
	}

	if (file_exists($NLST)) {
		print("<td><img src="checkmark_red.jpg" border="0"></td>");
	} else {
		print("<td>&nbsp;</td>");
	}


	if (checkDate($SL, $basedir)) {
		print("<td bgcolor="#EA947B">".getTeamName($SL)."</td><td bgcolor="#EA947B">".getFileDate($SL, $basedir)."</td>");
	} else {
		print("<td bgcolor="#95D096">".getTeamName($SL)."</td><td bgcolor="#95D096">".getFileDate($SL, $basedir)."</td>");
	}

	if (file_exists($SLST)) {
		print("<td><img src="checkmark_red.jpg" border="0"></td>");
	} else {
		print("<td>&nbsp;</td>");
	}


	print("</tr>");

}





print("<tr></tr><tr></tr>");

print("<tr><td bgcolor="#EA947B">Team Export Old</td></tr>");
print("<tr><td bgcolor="#95D096">Team Export OK</td></tr>");
print("<tr><td><img src="checkmark_red.jpg" border="0"> File Submitted</td></tr>");
print("<tr><td>ST = Spring Training</td></tr>");




print('</table>');





print("</BODY>");
print("</HTML>");
return;

function checkDate($file, $basedir, $leaguefile) {
	//print(filemtime($leaguefile));

	$teamfile = $basedir.$file;
	if (!file_exists($teamfile)) {
		$teamfile = $basedir.strtoupper($file);
	}

	if (file_exists($teamfile) && file_exists($leaguefile)) {
		//print("here1");
		if (filemtime($leaguefile) > filemtime($teamfile)) {
			return true;
		} else {
			//print("here2");
			return false;
		}
	} else {
		//print("here3");
		return true;
	}
}



function getFileDate($file, $basedir) {
	$teamfile = $basedir.$file;
	//print "looking for $teamfile or ";
	if (file_exists($teamfile)) {
		return date("n.d g:ia", filemtime($teamfile));
	}

	$teamfile = $basedir.strtoupper($file);
	//print "$teamfile <br> ";
	if (file_exists($teamfile)) {
		return date("n.d g:ia", filemtime($teamfile));
	} else {
		return 'No File';
	}
}



function getTeamName($file) {
	$file = strtolower($file);
	switch ($file) {
		case 'team1.exp': return 'Philadelphia';
		case 'team2.exp': return 'Ottawa';
		case 'team3.exp': return 'Toronto';
		case 'team4.exp': return 'Montreal';
		case 'team5.exp': return 'New York';
		case 'team6.exp': return 'Seattle';
		case 'team7.exp': return 'Calgary';
		case 'team8.exp': return 'Chicago';
		case 'team9.exp': return 'Los Angeles';
		case 'team10.exp': return 'Vancouver';
		case 'team11.exp': return 'San Juan';
		case 'team12.exp': return 'Atlanta';
		case 'team13.exp': return 'Monterrey';
		case 'team14.exp': return 'Veracruz';
		case 'team15.exp': return 'Havana';
		case 'team16.exp': return 'Tijuana';
		case 'team17.exp': return 'Cancun';
		case 'team18.exp': return 'Mexico City';
		case 'team19.exp': return 'Houston';
		case 'team20.exp': return 'Tampico';
	}
}

function scandir($dirstr) {

// php.net/scandir (PHP5)
$files = array();
$fh = opendir($dirstr);
while (false !== ($filename = readdir($fh))) {
array_push($files, $filename);
}
closedir($fh);
return $files;
}

?>[/code]


#2

CheckDate is already a PHP function http://us2.php.net/checkdate You are trying to declare a function that already exists. Change the name of your function to something else (perhaps MyCheckDate) and adjust your code as appropriate.