Index: trunk/wb/include/captcha.php
===================================================================
--- trunk/wb/include/captcha.php	(revision 226)
+++ trunk/wb/include/captcha.php	(revision 227)
@@ -32,40 +32,37 @@
 
 */
 
-$image = imagecreate(120, 30);
+require_once("../config.php");
 
-$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
-$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
-$darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
-
-srand((double)microtime()*1000000);
-
-for ($i = 0; $i < 30; $i++) {
-  $x1 = rand(0,120);
-  $y1 = rand(0,30);
-  $x2 = rand(0,120);
-  $y2 = rand(0,30);
-  imageline($image, $x1, $y1, $x2, $y2 , $gray);  
+if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg') AND isset($_SESSION['captcha'])) {
+	
+	$image = imagecreate(120, 30);
+	
+	$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
+	$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
+	$darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
+	
+	srand((double)microtime()*1000000);
+	
+	for($i = 0; $i < 30; $i++) {
+		$x1 = rand(0,120);
+		$y1 = rand(0,30);
+		$x2 = rand(0,120);
+		$y2 = rand(0,30);
+		imageline($image, $x1, $y1, $x2, $y2 , $gray);  
+	}
+	
+	for ($i = 0; $i < 5; $i++) {
+		$fnt = rand(3,5);
+		$x = $x + rand(12 , 20);
+		$y = rand(7 , 12); 
+		imagestring($image, $fnt, $x, $y, substr($_SESSION['captcha'], $i, 1), $darkgray); 
+	}
+	
+	header('Content-type: image/png');
+	imagepng($image);
+	imagedestroy($image);
+	
 }
 
-for ($i = 0; $i < 5; $i++) {
-$cnum[$i] = rand(0,9);
-}
-
-for ($i = 0; $i < 5; $i++) {
- $fnt = rand(3,5);
- $x = $x + rand(12 , 20);
- $y = rand(7 , 12); 
- imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray); 
-}
-
-$digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
-
-session_start();
-$_SESSION['captcha'] = $digit;
-
-header('Content-type: image/png');
-imagepng($image);
-imagedestroy($image);
-
 ?>
\ No newline at end of file
Index: trunk/wb/languages/EN.php
===================================================================
--- trunk/wb/languages/EN.php	(revision 226)
+++ trunk/wb/languages/EN.php	(revision 227)
@@ -387,6 +387,7 @@
 $TEXT['BACKUP_MEDIA'] = 'Backup Media';
 $TEXT['RESTORE_MEDIA'] = 'Restore Media';
 $TEXT['ADMINISTRATION_TOOL'] = 'Administration tool';
+$TEXT['CAPTCHA_VERIFICATION'] = 'Captcha Verification';
 
 
 // Success/error messages
@@ -524,4 +525,4 @@
 $MESSAGE['MOD_RELOAD']['TEMPLATES_RELOADED'] = 'Templates reloaded successfully';
 $MESSAGE['MOD_RELOAD']['LANGUAGES_RELOADED'] = 'Languages reloaded successfully';
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/form/install.php
===================================================================
--- trunk/wb/modules/form/install.php	(revision 226)
+++ trunk/wb/modules/form/install.php	(revision 227)
@@ -56,7 +56,8 @@
 	                 . ' `email_subject` VARCHAR(255) NOT NULL ,'
 	                 . ' `success_message` TEXT NOT NULL ,'
 					 . ' `stored_submissions` INT NOT NULL,'
-					 . ' `max_submissions` INT NOT NULL,'
+					 . ' `max_submissions` INT NOT NULL,'
+					 . ' `use_captcha` INT NOT NULL,'
 	                 . ' PRIMARY KEY ( `section_id` ) )'
 	                 . ' ';
 	$database->query($mod_form);
Index: trunk/wb/modules/form/modify_settings.php
===================================================================
--- trunk/wb/modules/form/modify_settings.php	(revision 226)
+++ trunk/wb/modules/form/modify_settings.php	(revision 227)
@@ -124,7 +124,18 @@
 	<td class="setting_name">
 		<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" />
 	</td>
-</tr>
+</tr>
+<?php if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */ ?>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['CAPTCHA_VERIFICATION']; ?>:</td>
+	<td>
+		<input type="radio" name="use_captcha" id="use_captcha_true" value="1"<?php if($setting['use_captcha'] == true) { echo ' checked'; } ?> />
+		<label for="use_captcha_true"><?php echo $TEXT['ENABLED']; ?></label>
+		<input type="radio" name="use_captcha" id="use_captcha_false" value="0"<?php if($setting['use_captcha'] == false) { echo ' checked'; } ?> />
+		<label for="use_captcha_false"><?php echo $TEXT['DISABLED']; ?></label>
+	</td>
+</tr>
+<?php } ?>
 </table>
 <table cellpadding="0" cellspacing="0" border="0" width="100%">
 <tr>
Index: trunk/wb/modules/form/view.php
===================================================================
--- trunk/wb/modules/form/view.php	(revision 226)
+++ trunk/wb/modules/form/view.php	(revision 227)
@@ -110,12 +110,13 @@
 <?php
 
 // Get settings
-$query_settings = $database->query("SELECT header,field_loop,footer FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
+$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
 if($query_settings->numRows() > 0) {
 	$fetch_settings = $query_settings->fetchRow();
 	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
 	$field_loop = $fetch_settings['field_loop'];
-	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
+	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
+	$use_captcha = $fetch_settings['use_captcha'];
 } else {
 	$header = '';
 	$field_loop = '';
@@ -182,6 +183,21 @@
 		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
 	}
 }
+
+// Captcha
+if($use_captcha) {
+	$_SESSION['captcha'] = '';
+	for($i = 0; $i < 5; $i++) {
+		$_SESSION['captcha'] .= rand(0,9);
+	}
+	?><tr><td class="field_title">Verification:</td><td>
+	<table cellpadding="2" cellspacing="0" border="0">
+	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php" alt="Captcha" /></td>
+	<td><input type="text" name="captcha" maxlength="5" /></td>
+	</tr></table>
+	</td></tr>
+	<?php
+}
 
 // Print footer
 echo $footer;
@@ -251,23 +267,16 @@
 	
 	// Captcha
 	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */
-		if(isset($_POST['captcha']) AND $_POST['CAPTCHA']!=''){
-			// User-supplied captcha
-			$user_captcha = $_POST['captcha'];
-			// Computer generated
-			if(isset($_SESSION['captcha'])) {
-				$system_captcha = $_SESSION['captcha'];
-			}
+		if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
 			// Check for a mismatch
-			if($user_captcha != $system_captcha) {
+			if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR !$_POST['captcha'] == $_SESSION['captcha']) {
 				$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
-			} else {
-				unset($_SESSION['captcha']);
 			}
 		} else {
 			$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
 		}
 	}
+	if(isset($_SESSION['catpcha'])) { unset($_SESSION['captcha']); }
 	
 	// Addslashes to email body - proposed by Icheb in topic=1170.0
 	// $email_body = $wb->add_slashes($email_body);
Index: trunk/wb/modules/form/save_settings.php
===================================================================
--- trunk/wb/modules/form/save_settings.php	(revision 226)
+++ trunk/wb/modules/form/save_settings.php	(revision 227)
@@ -41,6 +41,7 @@
 $field_loop = $admin->add_slashes($_POST['field_loop']);
 $footer = $admin->add_slashes($_POST['footer']);
 $email_to = $admin->add_slashes($_POST['email_to']);
+$use_captcha = $_POST['use_captcha'];
 if($_POST['email_from_field'] == '') {
 	$email_from = $admin->add_slashes($_POST['email_from']);
 } else {
@@ -64,7 +65,7 @@
 }
 
 // Update settings
-$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions' WHERE section_id = '$section_id'");
+$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");
 
 // Check if there is a db error, otherwise say successful
 if($database->is_error()) {
Index: trunk/wb/modules/form/add.php
===================================================================
--- trunk/wb/modules/form/add.php	(revision 226)
+++ trunk/wb/modules/form/add.php	(revision 227)
@@ -53,6 +53,7 @@
 $success_message = 'Thank-you.';
 $max_submissions = 50;
 $stored_submissions = 100;
-$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_settings (page_id,section_id,header,field_loop,footer,email_to,email_from,email_subject,success_message,max_submissions,stored_submissions) VALUES ('$page_id','$section_id','$header','$field_loop','$footer','$email_to','$email_from','$email_subject','$success_message','$max_submissions','$stored_submissions')");
+$use_captcha = true;
+$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_settings (page_id,section_id,header,field_loop,footer,email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha) VALUES ('$page_id','$section_id','$header','$field_loop','$footer','$email_to','$email_from','$email_subject','$success_message','$max_submissions','$stored_submissions','$use_captcha')");
 
 ?>
\ No newline at end of file
Index: trunk/wb/config.php
===================================================================
--- trunk/wb/config.php	(revision 226)
+++ trunk/wb/config.php	(revision 227)
@@ -1 +1,17 @@
-<?php ?>
\ No newline at end of file
+<?php
+
+define('DB_TYPE', 'mysql');
+define('DB_HOST', 'localhost');
+define('DB_USERNAME', 'root');
+define('DB_PASSWORD', 'password');
+define('DB_NAME', 'wb');
+define('TABLE_PREFIX', '');
+
+define('WB_PATH', dirname(__FILE__));
+define('WB_URL', 'http://localhost/workspace/websitebaker2/wb');
+define('ADMIN_PATH', WB_PATH.'/admin');
+define('ADMIN_URL', 'http://localhost/workspace/websitebaker2/wb/admin');
+
+require_once(WB_PATH.'/framework/initialize.php');
+
+?>
\ No newline at end of file
