Project

General

Profile

1 596 thorn
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
// direct access prevention
27
defined('WB_PATH') OR die(header('Location: ../index.php'));
28
29
// check if module language file exists for the language set by the user (e.g. DE, EN)
30
if(!file_exists(WB_PATH .'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
31
	// no module language file exists for the language set by the user, include default module language file EN.php
32
	require_once(WB_PATH .'/modules/captcha_control/languages/EN.php');
33
} else {
34
	// a module language file exists for the language defined by the user, load it
35
	require_once(WB_PATH .'/modules/captcha_control/languages/'.LANGUAGE .'.php');
36
}
37
38
$table = TABLE_PREFIX.'mod_captcha_control';
39
40
// check if data was submitted
41
if(isset($_POST['save_settings'])) {
42
	// get configuration settings
43
	$enabled_captcha = ($_POST['enabled_captcha'] == '1') ? '1' : '0';
44
	$enabled_asp = ($_POST['enabled_asp'] == '1') ? '1' : '0';
45
	$captcha_type = $admin->add_slashes($_POST['captcha_type']);
46
47
	// update database settings
48
	$database->query("UPDATE $table SET
49
		enabled_captcha = '$enabled_captcha',
50
		enabled_asp = '$enabled_asp',
51
		captcha_type = '$captcha_type'
52
	");
53
54 624 thorn
	// save text-captchas
55 640 thorn
	if($_POST['captcha_type'] == 'text') { // ct_text
56 628 thorn
		$text_qa=$_POST['text_qa'];
57
		if(strpos($text_qa, '### example ###') === FALSE) {
58
			$text_qa=$admin->add_slashes($text_qa);
59 640 thorn
			$database->query("UPDATE $table SET ct_text = '$text_qa'");
60 624 thorn
		}
61
	}
62
63 596 thorn
	// check if there is a database error, otherwise say successful
64
	if($database->is_error()) {
65
		$admin->print_error($database->get_error(), $js_back);
66
	} else {
67
		$admin->print_success($MESSAGE['PAGES']['SAVED'], ADMIN_URL.'/admintools/tool.php?tool=captcha_control');
68
	}
69
70
} else {
71
72
	// include captcha-file
73
	require_once(WB_PATH .'/include/captcha/captcha.php');
74
75 624 thorn
	// load text-captchas
76
	$text_qa='';
77 640 thorn
	if($query = $database->query("SELECT ct_text FROM $table")) {
78
		$data = $query->fetchRow();
79
		$text_qa = $admin->strip_slashes($data['ct_text']);
80 624 thorn
	}
81 628 thorn
	if($text_qa == '')
82
		$text_qa = $MOD_CAPTCHA_CONTROL['CAPTCHA_TEXT_DESC'];
83 624 thorn
84 609 thorn
// script to load image
85
?>
86
<script type="text/javascript">
87
	var pics = new Array();
88
89
	pics["ttf_image"] = new Image();
90
	pics["ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/ttf_image.png'?>";
91
92
	pics["calc_image"] = new Image();
93
	pics["calc_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_image.png'?>";
94
95 615 thorn
	pics["calc_ttf_image"] = new Image();
96
	pics["calc_ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_ttf_image.png'?>";
97
98 609 thorn
	pics["old_image"] = new Image();
99
	pics["old_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/old_image.png'?>";
100
101
	pics["calc_text"] = new Image();
102
	pics["calc_text"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_text.png'?>";
103 615 thorn
104 624 thorn
	pics["text"] = new Image();
105
	pics["text"].src = "<?php echo WB_URL.'/include/captcha/captchas/text.png'?>";
106
107 615 thorn
	function load_captcha_image() {
108
		document.captcha_example.src = pics[document.store_settings.captcha_type.value].src;
109 624 thorn
		toggle_text_qa();
110 615 thorn
	}
111 624 thorn
112
	function toggle_text_qa() {
113
		if(document.store_settings.captcha_type.value == 'text' ) {
114
			document.getElementById('text_qa').style.display = '';
115
		} else {
116
			document.getElementById('text_qa').style.display = 'none';
117
		}
118
	}
119
120 609 thorn
</script>
121
<?php
122
123 596 thorn
	// connect to database and read out captcha settings
124
	if($query = $database->query("SELECT * FROM $table")) {
125
		$data = $query->fetchRow();
126
		$enabled_captcha = $data['enabled_captcha'];
127
		$enabled_asp = $data['enabled_asp'];
128
		$captcha_type = $admin->strip_slashes($data['captcha_type']);
129
	} else {
130
		// something went wrong, use dummy value
131
		$enabled_captcha = '1';
132
		$enabled_asp = '1';
133
		$captcha_type = 'calc_text';
134
	}
135
136
	// write out heading
137
	echo '<h2>' .$MOD_CAPTCHA_CONTROL['HEADING'] .'</h2>';
138
139
	// output the form with values from the database
140
	echo '<p>' .$MOD_CAPTCHA_CONTROL['HOWTO'] .'</p>';
141
?>
142
<form name="store_settings" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
143
	<table width="98%" cellspacing="0" cellpadding="5px" class="row_a">
144
	<tr><td colspan="2"><strong><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_CONF'];?>:</strong></td></tr>
145 609 thorn
	<tr><td>
146
		<table>
147
			<tr height="50px">
148
			<td><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_TYPE'];?>:</td>
149 615 thorn
			<td align="right" width="150px"><img name="captcha_example" id="captcha_example" src="<?php echo WB_URL.'/include/captcha/captchas/'.$captcha_type.'.png'?>" ></td>
150 609 thorn
			</tr>
151
		</table>
152 596 thorn
		<td>
153 609 thorn
			<select name="captcha_type" id="captcha_type" onchange="load_captcha_image()" style="width: 98%;">
154 596 thorn
			<?php foreach($useable_captchas AS $key=>$text) {
155
				echo "<option value=\"$key\" ".($captcha_type==$key?'selected':'').">$text</option>";
156
			} ?>
157
		</select>
158
		</td>
159
	</tr>
160 624 thorn
	<tr id="text_qa" style="display:<?php if($captcha_type=='text') echo ''; else echo 'none'; ;?>;">
161
		<td class="setting_name"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_ENTER_TEXT'];?>:</td>
162
		<td class="setting_value" colspan="2">
163
			<textarea name="text_qa" wrap="off" cols="50" rows="10"><?php echo $text_qa; ?></textarea>
164
		</td>
165
	</tr>
166 596 thorn
	<tr>
167
		<td><?php echo $MOD_CAPTCHA_CONTROL['USE_SIGNUP_CAPTCHA'];?>:</td>
168
		<td>
169
			<input type="radio" <?php echo ($enabled_captcha=='1') ?'checked="checked"' :'';?>
170
				name="enabled_captcha" value="1"><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
171
			<input type="radio" <?php echo ($enabled_captcha=='0') ?'checked="checked"' :'';?>
172
				name="enabled_captcha" value="0"><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
173
		</td>
174
	</tr>
175 615 thorn
	<tr><td>&nbsp;</td><td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_EXP'];?></td></tr>
176 596 thorn
	<tr><td colspan="2"><br /><strong><?php echo $MOD_CAPTCHA_CONTROL['ASP_CONF'];?>:</strong></td></tr>
177
	<tr>
178
		<td><?php echo $MOD_CAPTCHA_CONTROL['ASP_TEXT'];?>:</td>
179
		<td>
180
			<input type="radio" <?php echo ($enabled_asp=='1') ?'checked="checked"' :'';?>
181
				name="enabled_asp" value="1"><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
182
			<input type="radio" <?php echo ($enabled_asp=='0') ?'checked="checked"' :'';?>
183
				name="enabled_asp" value="0"><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
184
		</td>
185
	</tr>
186 615 thorn
	<tr><td>&nbsp;</td><td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['ASP_EXP'];?></td></tr>
187 596 thorn
	</table>
188
	<input type="submit" name="save_settings" style="margin-top:10px; width:140px;" value="<?php echo $TEXT['SAVE']; ?>" />
189
</form>
190
<?php
191
}
192
193 640 thorn
?>