From 36bee330663f60abc88688861b844e67c02fac54 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 24 Jan 2006 15:44:08 +0000 Subject: [PATCH] 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 --- db/db.update.13.sql | 3 +++ register_participants.inc.php | 2 +- register_participants_project.php | 45 ++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 db/db.update.13.sql diff --git a/db/db.update.13.sql b/db/db.update.13.sql new file mode 100644 index 0000000..f93840c --- /dev/null +++ b/db/db.update.13.sql @@ -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` ; diff --git a/register_participants.inc.php b/register_participants.inc.php index 9787040..396a5d6 100644 --- a/register_participants.inc.php +++ b/register_participants.inc.php @@ -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']; diff --git a/register_participants_project.php b/register_participants_project.php index fb908c4..d74713f 100644 --- a/register_participants_project.php +++ b/register_participants_project.php @@ -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")); } +?> + +\n"; echo "\n"; @@ -242,8 +270,19 @@ else if($newstatus=="complete") echo ""; - echo "".i18n("Summary").": ".REQUIREDFIELD."
"; - echo i18n("100 words maximum"); + echo "".i18n("Summary").": ".REQUIREDFIELD."
"; + + $summarywords=preg_split("/[\s,]+/",$projectinfo->summary); + $summarywordcount=count($summarywords); + if($summarywordcount>$config['participant_project_summary_wordmax']) + echo "
"; + else + echo "
"; + + echo "$summarywordcount/"; + echo i18n("%1 words maximum",array($config['participant_project_summary_wordmax'])); + echo "
"; + echo ""; echo "";