<?

	LogIt("DEBUG","ParseReport","Loading ParseReport...");
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#----------------------------------------------------------------------
	# $Id: reputils.php3,v 1.12 2000/12/14 19:13:58 shevett Exp $
	#----------------------------------------------------------------------
	
	Function ParseReport($repfile) {
								
		$reptags = array();
		$reptags['vcounter'] = 0;
		$reptags['ccounter'] = 0;
		
		$fh = fopen("$repfile","r");
		while ($iline = fgets($fh,255)) {
			$line = chop($iline);
			if (! ereg('[[:blank:]]*#.*',$line) ) {

				if (ereg('^DATASET[[:blank:]]*:[[:blank:]]*(.*)',$line,$tmparray) && ! ($reptags['dataset'])) {
					$reptags['dataset'] = $tmparray[1];
				}
			
				if (ereg('^TITLE[[:blank:]]*:[[:blank:]]*(.*)',$line,$tmparray) && ! ($reptags[title])) {
					$reptags['title'] = $tmparray[1];
				}

				if (ereg('^VERSION[[:blank:]]*:[[:blank:]]*(.*)',$line,$tmparray) && ! ($reptags['version'])) {
					$reptags['version'] = $tmparray[1];
				}

				if (ereg('^VAR(.*):',$line,$tmparray)) {
					$def="";
					$prompt="";
					$dtype="";
					while (! (ereg('^\}.*',$line))) {
						if (! ereg('[[:blank:]]*#.*',$line) ) {
							$prompt = (ereg('.*text[[:blank:]]*=[[:blank:]]*(.*)',$line,$parray)) ? $parray[1] : $prompt;
							$def = (ereg('.*default[[:blank:]]*=[[:blank:]]*(.*)',$line,$darray)) ? $darray[1] : $def;
							$dtype = (ereg('.*dtype[[:blank:]]*=[[:blank:]]*(.*)',$line,$xyzzyarray)) ? $xyzzyarray[1] : $dtype;
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
					$in = $tmparray[1];
					$reptags['prompt'][$in] = $prompt;
					$reptags['vdtype'][$in] = $dtype;
					$reptags['vcounter']++;
#					if (($dtype == "date") && ($def == "today")) {
#						$reptags[def][$in] = time();
					if ($dtype == "date") {
						if ($def == "today") {
							$reptags['def'][$in] = time();
						} else {
							$reptags['def'][$in] = (ereg('([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})', $def, $tmparray)) ? mktime(0,0,0,$tmparray[1],$tmparray[2],$tmparray[3]) : $def;
						}
					} else {
						$reptags['def'][$in] = $def;
					}
				}
				
				if (ereg('^COL(.*):',$line,$tmparray)) {
					$display="";
					$label="";
					$dtype="";
					while (! (ereg('^\}.*',$line))) {
						if (! ereg('[[:blank:]]*#.*',$line) ) {
							$line = chop($line);
							$display = (ereg('.*display[[:blank:]]*=[[:blank:]]*(.*)',$line,$darray)) ? $darray[1] : $display;
							$label = (ereg('.*label[[:blank:]]*=[[:blank:]]*(.*)',$line,$larray)) ? $larray[1] : $label;
							$dtype = (ereg('.*dtype[[:blank:]]*=[[:blank:]]*(.*)',$line,$tarray)) ? $tarray[1] : $dtype;
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
					$in = $tmparray[1];
					$reptags['display'][$in] = $display;
					$reptags['label'][$in] = $label;
					$reptags['cdtype'][$in] = $dtype;
					$reptags['ccounter']++;
				}
			
				if (ereg('^SQL:',$line,$tmparray)) {
					$reptags['sql']='';
					while (! (ereg('^\}.*',$line))) {
						if (! ereg('^(SQL|\{|[[:blank:]]*#)',$line)) {
							ereg('[[:blank:]]*(.*)',$line,$sarray);
							$reptags['sql'] = $reptags['sql'] . $sarray[1] . " ";
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
				}

				if (ereg('^PHPHEAD:',$line,$tmparray)) {
					LogIt("DEBUG","ParseReport","Found PHPHEAD header");
					$reptags['phphead']='';
					while (! (ereg('^\PHPHEAD}.*',$line))) {
						LogIt("DEBUG","ParseReport","Parsing: $line");
						if (! ereg('^(PHPHEAD|\{|[[:blank:]]*#)',$line)) {
							ereg('[[:blank:]]*(.*)',$line,$sarray);
							$reptags['phphead'] = $reptags['phphead'] . $sarray[1] . " ";
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
#					LogIt("DEBUG","ParseReport","After processing PHPHEAD, reptags['phphead'] is $reptags['phphead']");
				}

				if (ereg('^PHPSTART:',$line,$tmparray)) {
					LogIt("DEBUG","ParseReport","Found PHPSTART header");
					$reptags['phpstart']='';
					while (! (ereg('^\PHPSTART}.*',$line))) {
						LogIt("DEBUG","ParseReport","Parsing: $line");
						if (! ereg('^(PHPSTART|\{|[[:blank:]]*#)',$line)) {
							ereg('[[:blank:]]*(.*)',$line,$sarray);
							$reptags['phpstart'] = $reptags['phpstart'] . $sarray[1] . " ";
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
#					LogIt("DEBUG","ParseReport","After processing PHPSTART, reptags['phpstart'] is $reptags['phpstart']");
				}

				if (ereg('^PHPITERATE:',$line,$tmparray)) {
					LogIt("DEBUG","ParseReport","Found PHPITERATE ");
					$reptags['phpiterate']='';
					while (! (ereg('^\PHPITERATE}.*',$line))) {
						LogIt("DEBUG","ParseReport","Parsing: $line");
						if (! ereg('^(PHPITERATE|\{|[[:blank:]]*#)',$line)) {
							ereg('[[:blank:]]*(.*)',$line,$sarray);
							$reptags['phpiterate'] = $reptags['phpiterate'] . $sarray[1] . " ";
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
				}

				if (ereg('^PHPBODY:',$line,$tmparray)) {
					LogIt("DEBUG","ParseReport","Found PHPBODY ");
					$reptags['phpbody']='';
					while (! (ereg('^\PHPBODY}.*',$line))) {
						LogIt("DEBUG","ParseReport","Parsing: $line");
						if (! ereg('^(PHPBODY|\{|[[:blank:]]*#)',$line)) {
							ereg('[[:blank:]]*(.*)',$line,$sarray);
							$reptags['phpbody'] = $reptags['phpbody'] . $sarray[1] . " ";
						}
						$iline=fgets($fh,255);
						$line = chop($iline);
					}
				}
			}
		}
		return $reptags ;
	}
?>
