<?php
session_start();
include("header.php");
?>
<!-- #include file="include\header.inc"-->
<!-- #include file="include\globalfunctions.inc"-->
<!-- #include file="include\ckSess.inc"-->
<!-- #include file="clsUpload.asp"-->
<?php
/*
set o = new clsUpload
bnsFile = o.FileNameOf("bnsFile") & ""
fsDesc = o.ValueOf("fsDesc") & ""
*/
if(trim($fsDesc)=="")
$fsDesc = 0;


if($_POST['cmdSubmit']=="UPLOAD")
{
	if(($fsDesc)== 0)
	{
		$errmsg = "Select School for file upload.<br/>";
	}
	elseif(trim($bnsFile) == "") 
	{
		$errmsg = "Menu Form file is required.<br/>";
	}
	else
	{
		$strInput = "";
		$strValue = "";
		if(trim($bnsFile)!="")
		{
			/*sFileSplit = split(bnsFile, "\")
			sFile = sFileSplit(Ubound(sFileSplit))
			fileVal = strRepInput(fsDesc &"_"& sFile)
			o.FileInputName = "bnsFile"
			o.FileFullPath = "D:\InetPub\vhosts\lunchpails.ca\httpdocs\menuSchools\" & fileVal
			o.save*/
			if ($Error == "")
			{
				$strSql = mysql_query("select * from tr_menuschool where school_id='".$fsDesc."'");
				$rsc=@mysql_num_rows($strSql);

				If($rsc>0)
				{
					$strSql1 =mysql_query("update tr_menuschool set msfile='".$fileVal."' where school_id='".$fsDesc."'");
				}
				else
				{
					$strSql1 = mysql_query("insert into tr_menuschool(school_id,msfile,status) values('".$fsDesc."','".$fileVal."','1');");
					
				}
				$errmsg = "Your Menu file is valid and successfully uploaded!";
			}
			else
			{
				$errmsg = "Failed to upload Menu file due to the following error: ".$Error;
			}
		}
	}
}

?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14"><u><b>MENU FORM FOR SCHOOLS</b></u></td></tr>
	<tr><td width="200" class="fs12" valign="top"><?php include("sidemenu.php");?></td>
		<td align="center" class="fs12">
		<form method="POST" action="menusforms.php" enctype="multipart/form-data" id="form1" name="form1">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr><td colspan="3" height="30"></td></tr>
				<tr><td></td><td colspan="2" class="errmsg"><?=$errmsg?></td></tr>
				<tr><td colspan="3" height="10"></td></tr>
				<tr class="fs14"><td width="40%" align="right">Menu Form File :&nbsp;</td><td colspan="2"><input size="18" type="File" name="bnsFile" value="" ></td></tr>
				<tr class="fs14"><td width="40%" align="right">Please Choose School :&nbsp;</td>
					<td width="28%">
					<select name="fsDesc" class="formsSchool">
						<?php
						echo "<option value='0'>&nbsp;&nbsp;&nbsp;&nbsp; -- &nbsp;Select&nbsp; -- </option>";
							$strSql = mysql_query("select school_id,school_name from tr_schools where status=1 order by school_name");
							$rcnt=@mysql_num_rows($strSql);
							if($rcnt>0)
							{								
								while($rs=@mysql_fetch_array($strSql))
								{
									if($fsDesc==$rs['school_id'])
										echo "<option value='".$rs['school_id']."'  selected >".$rs['school_name']."</option>";
									else
										echo "<option value='".$rs['school_id']."' >".$rs['school_name']."</option>";
								}
							}
							?>
							</select></td><input type="hidden" name="cmdSubmit" value="UPLOAD"/>
					<td width="32%">&nbsp;<input type="image" name="image1" id="image1" src="../images/upload.gif" title="UPLOAD" alt="UPLOAD" /></td></tr>
				<tr><td colspan="3" height="200">&nbsp;</td></tr>
			</table></form>
		</td></tr>
</table>
<?php
include("footer.php");
?>