Add a configuration option to specify the maximum number of words in the project summary (Default=100)

Add some fancy-smansy javascript/dhtml word-counter code to the project summary.
Make project status be incomplete if word count is too high
This commit is contained in:
james 2006-01-24 15:44:08 +00:00
parent 06dae78992
commit 36bee33066
3 changed files with 46 additions and 4 deletions

3
db/db.update.13.sql Normal file
View File

@ -0,0 +1,3 @@
INSERT INTO `config` ( `var` , `val` , `description` , `year` ) VALUES ( 'participant_project_summary_wordmax', '100', 'The maximum number of words acceptable in the project summary', '-1');
INSERT INTO `config` ( `var` , `val` , `description` , `year` ) VALUES ( 'participant_project_summary_wordmax', '100', 'The maximum number of words acceptable in the project summary', '2006');
ALTER TABLE `projects` ADD `summarycountok` TINYINT( 1 ) DEFAULT '1' NOT NULL AFTER `summary` ;

View File

@ -111,7 +111,7 @@ function emergencycontactStatus($reg_id="")
function projectStatus($reg_id="")
{
global $config;
$required_fields=array("title","projectcategories_id","projectdivisions_id","summary","language","req_table","req_electricity");
$required_fields=array("title","projectcategories_id","projectdivisions_id","summary","language","req_table","req_electricity","summarycountok");
if($reg_id) $rid=$reg_id;
else $rid=$_SESSION['registration_id'];

View File

@ -85,6 +85,13 @@ echo mysql_error();
$q=mysql_query("SELECT * FROM projects WHERE id='".$_POST['id']."' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q)==1)
{
$summarywords=preg_split("/[\s,]+/",$_POST['summary']);
$summarywordcount=count($summarywords);
if($summarywordcount>$config['participant_project_summary_wordmax'])
$summarycountok=0;
else
$summarycountok=1;
mysql_query("UPDATE projects SET ".
"title='".mysql_escape_string(stripslashes($_POST['title']))."', ".
"projectdivisions_id='".$_POST['projectdivisions_id']."', ".
@ -92,7 +99,8 @@ echo mysql_error();
"req_table='".mysql_escape_string(stripslashes($_POST['req_table']))."', ".
"req_electricity='".mysql_escape_string(stripslashes($_POST['req_electricity']))."', ".
"req_special='".mysql_escape_string(stripslashes($_POST['req_special']))."', ".
"summary='".mysql_escape_string(stripslashes($_POST['summary']))."' ".
"summary='".mysql_escape_string(stripslashes($_POST['summary']))."', ".
"summarycountok='$summarycountok'".
"WHERE id='".$_POST['id']."'");
echo mysql_error();
echo notice(i18n("Project information successfully updated"));
@ -154,8 +162,28 @@ else if($newstatus=="complete")
echo happy(i18n("Project Information Complete"));
}
?>
<script language="javascript" type="text/javascript">
function countwords()
{
var wordmax=<?=$config['participant_project_summary_wordmax'];?>;
var summaryobj=document.getElementById('summary');
var wordcountobj=document.getElementById('wordcount');
var wordcountmessageobj=document.getElementById('wordcountmessage');
var wordarray=summaryobj.value.replace(/\s+/g," ").split(" ");
var wordcount=wordarray.length;
if(wordcount>wordmax)
wordcountmessageobj.className="incomplete";
else
wordcountmessageobj.className="complete";
wordcountobj.innerHTML=wordcount;
}
</script>
<?
echo "<form name=\"projectform\" method=\"post\" action=\"register_participants_project.php\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
@ -242,8 +270,19 @@ else if($newstatus=="complete")
echo "</td></tr>";
echo "<tr><td>".i18n("Summary").": </td><td><textarea cols=\"60\" rows=\"12\" name=\"summary\">".htmlspecialchars($projectinfo->summary)."</textarea>".REQUIREDFIELD."<br />";
echo i18n("100 words maximum");
echo "<tr><td>".i18n("Summary").": </td><td><textarea onchange='countwords()' onkeypress='countwords()' cols=\"60\" rows=\"12\" id=\"summary\" name=\"summary\">".htmlspecialchars($projectinfo->summary)."</textarea>".REQUIREDFIELD."<br />";
$summarywords=preg_split("/[\s,]+/",$projectinfo->summary);
$summarywordcount=count($summarywords);
if($summarywordcount>$config['participant_project_summary_wordmax'])
echo "<div id=\"wordcountmessage\" class=\"incomplete\">";
else
echo "<div id=\"wordcountmessage\" class=\"complete\">";
echo "<span id=\"wordcount\">$summarywordcount</span>/";
echo i18n("%1 words maximum",array($config['participant_project_summary_wordmax']));
echo "</div>";
echo "</td></tr>";
echo "</table>";