<?
include('../init.php');
require_once('../libs/functions.php');

$upload_dir = "/tmp/vrss";

if (checklogin($userID, "../index.php")) {

	$sql = 'Select html from tb_content where page_id = 2';
	$rs = $db->Execute($sql) or die ("<br>SQL failed");	//die ("<br>$sql <br>SQL failed");
	
	$content_2 = $rs->fields('html');

	print_header();
?>	

	<script>
		function check_form() {
			var errs=0;
      var maxUpload = 1000000 * 100; //Change second number for megabytes
			var filename="";
			var input = document.getElementById('file');

      filename = document.forms.validate.file.value;
      if (filename == '') {alert('Please choose a file to validate'); errs=1;}
      var filestring = filename.split("\\");
      filename = filestring[filestring.length -1];

      if (filename.length > 40) 
        {alert('The file name exceeds 40 characters'); errs=1;}
          
      var browser = navigator.appName;
      if (browser == 'Microsoft Internet Explorer') {
        var myFSO = new ActiveXObject("Scripting.FileSystemObject");
        var filepath = document.forms.validate.file.value;
        var thefile = myFSO.getFile(filepath);
        var size = thefile.size;
        if (size > maxUpload) {
          alert("File exceeds maximum upload size of " + maxUpload / 1000000 + " megabytes");
          errs=1;
        }
      } 
      else {
        if (!window.FileReader) {
          alert("The file API isn't supported on this browser yet.  Please use a supported browser.");
          errs=1;
        }

        if (!input) {
          alert("Couldn't find the fileinput element.");
          errs=1;
        }
        else if (!input.files) {
          alert("This browser doesn't seem to support the `files` property of file inputs.");
          errs=1;
        }
        else {
          file = input.files[0];
          if ( file.size > maxUpload ) {
            alert("File exceeds maximum upload size of " + maxUpload / 1000000 + " megabytes");
            errs=1;
          }
        }
      }
				
			return (errs==0);
		}
	</script>
	
	<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>

	<script language = "Javascript">
	var cal = new CalendarPopup();
	// Declaring valid date character, minimum year and maximum year
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	
	function isInteger(s){
		var i;
	    for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	    }
	    // All characters are numbers.
	    return true;
	}
	
	function stripCharsInBag(s, bag){
		var i;
	    var returnString = "";
	    // Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
	    for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}
	
	function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			alert("The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter a valid date")
			return false
		}
	return true
	}
	
	</script>

<?if ($status == 1) {?>
<h1 align="center">CF/CS Main Menu</h1>
<?} else if ($status == 2) {?>
<h1 align="center">CF/CS Main Menu</h1>
<?}?>

<?php
	$sql = "SELECT fname, lname, email, phone, ext, account_type, cs_id FROM tb_user WHERE user_id=$userID";
	$rs = $db->Execute($sql);
	$fname = $rs->fields('fname');
	$lname = $rs->fields('lname');		
	$account_type = $rs->fields('account_type');
	$u_csid = $rs->fields('cs_id');
?>

<HR><BR><BR>

<div id="body" style="margin-left: auto; margin-right: auto; width: 755px;">
	<div id="leftcolumn" style="float: left; width: 200px; ">
		<div id="menu" style="width: 180px; border: thin solid; padding: 10px 10px 10px 10px;">
			
		<h2>User Options</h2>
			<UL>
			<!--- <LI><A HREF="/apps/index.php">Upload CSV</A> -->
			<LI><A HREF="../myaccount.php">My Account</A>

		<? if (($account_type == 'CF') AND ($u_csid <> 0)) {?>
			<LI><A HREF="../upload_history.php">Upload History</A>
		<? } elseif (($account_type == 'CF') AND ($u_csid == 0)) {?>
			<LI><A HREF="../upload_history_other.php">Upload History</A>
		<? } else {?>
			<LI><A HREF="../upload_history.php">Upload History</A>
		<? } ?>

			<LI><A HREF="./file_history.php">View/Download Reports</A>
			<LI><A HREF="../support.php">Support</A>
			<LI><A HREF="../logout.php">Logout</A>
			</UL>
		
		</div>
	</div>
	
	<div id="rightcolumn" style="width: 500px; float: right;">
	
		<div id="message" style="width: 475px;">
		 <?//=$content_2?> 
		</div>

		
<div id="body" style="margin-left: auto; margin-right: auto; width: 755px;">
<p><b>Announcements:</p></b>
<p>Welcome: <?echo $fname;?>&nbsp;<?echo $lname;?></p>


<?
$sql = "SELECT html FROM tb_content WHERE page_id=4";
$rs = $db->Execute($sql);
$record_count = $rs->RecordCount();
if ($record_count == 1) {
$html = $rs->fields('html');
echo $html;
}
else {print "no content";}
?>


</div>
</p>		
		
		
		<BR><HR><BR>
		
	<div id="convertFile" style="width: 475px;">
		<center><h1>Instructions</h1></center>
		<center><b>Convert XLS documents to CSV</b></center>
		<p>1. Open the XLS file in Microsoft Excel. </p>
		<p>2. Click the "File" menu and choose "Save As". If you are using Microsoft Excel 2007, 
		click the Microsoft Office "Button" and choose "Save As". </p>
		<p>3. Choose one of the CSV formats listed in the "Save as type" drop-down box. 
		If you are using Windows, choose "CVS(MS-DOS)". If you are using Mac OS, you should choose "CSV(Macintosh)".</p>
		<p>4. Choose a filename and a location to save the file.</p>
		<p>5. Click "Save".<p>
	</div>
	
	<BR><HR><BR>
	
	
	<div id="programs" style="width: 475px;">
			<h2>CSV Data Upload Form</h2>
			<form name="validate" enctype="multipart/form-data" action="file_uploader.php"  method="POST" onSubmit="return check_form();">
		<table align="left" cellspacing="1" class="auto-style1" style="width: 100%; float: left">
				
				<input type="hidden" NAME="dataset_id" id="dataset_id" value='1' tabindex="2">
				<tr>
					<td style="width: 175px"><label for="file">Choose a file:</label></td>
					<td><input name="file" type="file" tabindex="5" id="file"/> </td>
				</tr>
				<tr>
					<td style="width: 175px"><input type="submit" value="  Validate  File  " tabindex="6" /></td>
					<td></td>
				</tr>
			</table>

			</form>
		</div>
			
	</div>
	
	<div style="clear:both;"></div>

</div>



<?

print_footer();

} // end check login

?>