[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-usability
Subject:    Re: [ACTION ITEM] getting usability reports on the web site
From:       Eric Ellsworth <whalesuit () softhome ! net>
Date:       2003-02-26 21:20:50
[Download RAW message or body]

Aaron,
	In the script that I gave to Jason there is a setting to allow the documents 
to be saved.   By default they are saved to two subfolders of the folder 
containing the script: "valid" and "invalid". 
	Here's the script with the option to save on.  If you save the script on 
u.k.o, turn this option back on, and make the directories "valid" and 
"invalid", voile there will be a place to put reports.  Note that any new 
report overwrites an old one of the same name.
	
	I've also included .htpasswd and .htaccess files you can drop in if you like.  
We can work out a more general system for setting passwords later.

Cheers,

Eric
[".htpasswd" (text/plain)]

reports:$apr1$g/8dB/..$K0x7H7C7HQJg5r1mk2eFr.

[".htaccess" (text/plain)]

AuthType Basic
AuthName "Usability Reports"
AuthUserFile .htpasswd
require user reports

["submit_report.php" (text/x-php)]

<?
// Form to submit usability reports
?>

<html>
<head>
<title>Submit a usability report to KDE</title>


<form enctype="multipart/form-data" action="validate_report.php" method="post">
<table><tr>
<td>
Upload a usability report as XML file
</td>
<td>
<input name="userfile" type="file">
<input type="submit" value="Send File">
</td>
</tr>
</table>
</form>

["validate_report.php" (text/x-php)]

<?        
/* Configuration options */
$save_files = TRUE;  // Should files be saved?
$valid_files_loc = "./valid/";  //Where to save files that validated OK?
$invalid_files_loc = "./invalid/";  //Where to save files that didn't validate?

$validator = "xmllint";  // Which program to use to validate
$validator_options = " --valid --noout ";  // options for this prog
$validation_base = trim(shell_exec("which ".$validator));  //full path to prog

/* End configuration */

print "<html>";
$orig_fname = $HTTP_POST_FILES['userfile']['name'];
$tmp_fname = $HTTP_POST_FILES['userfile']['tmp_name'];

if (!is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
{
	print "There was an error with the file you uploaded.";
	die;
}else{
	
	$fsize = filesize($tmp_fname);
	$fhandle = fopen($tmp_fname,"r+");
	$whole_file = fread($fhandle,$fsize);
	$doctype_pattern = '/<(!DOCTYPE\s+(.*)\s+SYSTEM\s+"([^"]*)"\s*)>/';
	$whole_file_arr = preg_split($doctype_pattern,$whole_file,-1, \
PREG_SPLIT_DELIM_CAPTURE);  
	// Check for XML correctness - does this file have a proper DOCTYPE
	if(count($whole_file_arr)==1){ // XML lacks DOCTYPE declaration
				
		print "This report is lacking a document type declaration.<br>";
		print 'Below your document\'s XML declaration:
		<p style="color:blue"><?xml version="1.0"?></p>
		Please add the following line:
		<p style="color:green">&lt;!DOCTYPE report SYSTEM \
"http://usability.kde.org/DTD/kde_usability_report.dtd"&gt;</p>  Then save your \
report and try resubmitting it.';  die;
	}elseif($whole_file_arr[2]!="report"){	// Has DOCTYPE, but type is not report
		print "This report's document type declaration is incorrect.<br>";
		print 'It is:<br><p style="color:red">&lt;'.$whole_file_arr[1].'&gt;</p><br>';
		print 'Below your document\'s XML declaration:
		<p style="color:blue">&lt;?xml version="1.0"?&gt;</p>
		Please change your document type declaration to the following:
		<p color="green">&lt;!DOCTYPE report SYSTEM \
"http://usability.kde.org/DTD/kde_usability_report.dtd"&gt;</p>  Then save your \
report and try resubmitting it.';  die;
	}
	
	// Replace the remote DOCTYPE declaration with the local one for faster validation
	$doctype_loc = "/home/webroot/html/kde_usability/reports/kde_usability_report.dtd";
	$local_doctype = '<!DOCTYPE report SYSTEM "'.$doctype_loc.'">';
	$old_doctype_loc = $whole_file_arr[2];
	$whole_file2 = $whole_file_arr[0].$local_doctype.$whole_file_arr[4];
	fclose($fhandle);
	
	// Update the file in /tmp with the local DOCTYPE declaration
	if($save_files){
		$fhandle = fopen($tmp_fname,"w");
		if (!fwrite($fhandle,$whole_file2)) {
			print "Cannot write to file ($tmp_fname)";
			die;
		}
		fclose($fhandle);
	}
}
// Now run the validator
$validation_cmd = $validation_base.$validator_options.$tmp_fname;
$validation_results = shell_exec($validation_cmd. " 2>&1");


print "The file you uploaded: <span \
style=\"color:blue;font-weight:bold\">$orig_fname</span><br>"; print "was validated \
using: <span style=\"color:green;font-weight:bold\">$validator $validator_options \
$orig_fname</span><p><p>"; if(empty($validation_results)){  //No output means the the \
file is valid  if($save_files){
		// Write the file into the valid files location
		$accepted_report_fhandle = fopen($valid_files_loc.$orig_fname,"w");
		if (!fwrite($accepted_report_fhandle,$whole_file)) {
			print "Cannot write to file ($valid_files_loc$orig_fname)";
			die;
		}
		fclose($accepted_report_fhandle);
		print "Success!  Your report has been saved as 
		<a href=\"$valid_files_loc$orig_fname\">$valid_files_loc$orig_fname</a>";
	}
}else{
	/* Hide location of temporary files - replace references to temporary	** 
	**  filename w/ original filename					*/
	$validation_results=str_replace($tmp_fname,$orig_fname,$validation_results);
	// Replace <,> in XML tags so the text can be rendered by browsers
	$validation_results=preg_replace("/<([^>]*)>/","&lt;\\1&gt;",$validation_results);
		
	print "Errors occurred in validating your document, listed below.<p>
	Please edit your document, or send your complaints about the XML file format to the 
	<a href=\"mailto:usability@lists.kde.org\">usability list</a><p><hr>
	XML Validation Errors:<p>";
	print "<font size=\"-1\"><PRE>$validation_results</PRE></font>"; 
	if($save_files){	
		$invalid_report_fhandle = fopen($invalid_files_loc.$orig_fname,"w");
		if (!fwrite($invalid_report_fhandle,$whole_file)) {
			print "Cannot write to file ($invalid_files_loc$orig_fname)";
			die;
		}
		fclose($invalid_report_fhandle);
		print "<hr>Your report has been saved as 
		<a href=\"$invalid_files_loc$orig_fname\">$invalid_files_loc$orig_fname</a>";
	}
}

print "</html>";
exit;

?> 


_______________________________________________
kde-usability mailing list
kde-usability@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-usability

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic