Project

General

Profile

1
<?php
2

    
3
// $Id: tool.php 624 2008-01-28 15:25:32Z thorn $
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
	// save text-captchas
55
	if($_POST['captcha_type'] == 'text') {
56
		$text_qa=$admin->add_slashes($_POST['text_qa']);
57
		if($fh = fopen(WB_PATH.'/temp/.captcha_text.txt', 'wb')) {
58
			fwrite($fh, $text_qa);
59
			fclose($fh);
60
		}
61
	}
62
	
63
	// 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
	// load text-captchas
76
	$text_qa='';
77
	if(file_exists(WB_PATH.'/include/captcha/captchas/text.php')) {
78
		if(file_exists(WB_PATH.'/temp/.captcha_text.txt')) {
79
			@$content = file(WB_PATH.'/temp/.captcha_text.txt');
80
			if($content!==FALSE) {
81
				$text_qa = $admin->strip_slashes(implode('', $content));
82
			}
83
		}
84
	}
85

    
86
// script to load image
87
?>
88
<script type="text/javascript">
89
	var pics = new Array();
90

    
91
	pics["ttf_image"] = new Image();
92
	pics["ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/ttf_image.png'?>";
93

    
94
	pics["calc_image"] = new Image();
95
	pics["calc_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_image.png'?>";
96
	
97
	pics["calc_ttf_image"] = new Image();
98
	pics["calc_ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_ttf_image.png'?>";
99

    
100
	pics["old_image"] = new Image();
101
	pics["old_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/old_image.png'?>";
102
	
103
	pics["calc_text"] = new Image();
104
	pics["calc_text"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_text.png'?>";
105
	
106
	pics["text"] = new Image();
107
	pics["text"].src = "<?php echo WB_URL.'/include/captcha/captchas/text.png'?>";
108

    
109
	function load_captcha_image() {
110
		document.captcha_example.src = pics[document.store_settings.captcha_type.value].src;
111
		toggle_text_qa();
112
	}
113
	
114
	function toggle_text_qa() {
115
		if(document.store_settings.captcha_type.value == 'text' ) {
116
			document.getElementById('text_qa').style.display = '';
117
		} else {
118
			document.getElementById('text_qa').style.display = 'none';
119
		}
120
	}
121

    
122
</script>
123
<?php
124

    
125
	// connect to database and read out captcha settings
126
	if($query = $database->query("SELECT * FROM $table")) {
127
		$data = $query->fetchRow();
128
		$enabled_captcha = $data['enabled_captcha'];
129
		$enabled_asp = $data['enabled_asp'];
130
		$captcha_type = $admin->strip_slashes($data['captcha_type']);
131
	} else {
132
		// something went wrong, use dummy value
133
		$enabled_captcha = '1';
134
		$enabled_asp = '1';
135
		$captcha_type = 'calc_text';
136
	}
137
		
138
	// write out heading
139
	echo '<h2>' .$MOD_CAPTCHA_CONTROL['HEADING'] .'</h2>';
140

    
141
	// output the form with values from the database
142
	echo '<p>' .$MOD_CAPTCHA_CONTROL['HOWTO'] .'</p>';
143
?>
144
<form name="store_settings" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
145
	<table width="98%" cellspacing="0" cellpadding="5px" class="row_a">
146
	<tr><td colspan="2"><strong><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_CONF'];?>:</strong></td></tr>
147
	<tr><td>
148
		<table>
149
			<tr height="50px">
150
			<td><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_TYPE'];?>:</td>
151
			<td align="right" width="150px"><img name="captcha_example" id="captcha_example" src="<?php echo WB_URL.'/include/captcha/captchas/'.$captcha_type.'.png'?>" ></td>
152
			</tr>
153
		</table>
154
		<td>
155
			<select name="captcha_type" id="captcha_type" onchange="load_captcha_image()" style="width: 98%;">
156
			<?php foreach($useable_captchas AS $key=>$text) {
157
				echo "<option value=\"$key\" ".($captcha_type==$key?'selected':'').">$text</option>";
158
			} ?>
159
		</select>
160
		</td>
161
	</tr>
162
	<tr id="text_qa" style="display:<?php if($captcha_type=='text') echo ''; else echo 'none'; ;?>;">
163
		<td class="setting_name"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_ENTER_TEXT'];?>:</td>
164
		<td class="setting_value" colspan="2">
165
			<textarea name="text_qa" wrap="off" cols="50" rows="10"><?php echo $text_qa; ?></textarea>
166
		</td>
167
	</tr>
168
	<tr>
169
		<td><?php echo $MOD_CAPTCHA_CONTROL['USE_SIGNUP_CAPTCHA'];?>:</td>
170
		<td>
171
			<input type="radio" <?php echo ($enabled_captcha=='1') ?'checked="checked"' :'';?>
172
				name="enabled_captcha" value="1"><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
173
			<input type="radio" <?php echo ($enabled_captcha=='0') ?'checked="checked"' :'';?>
174
				name="enabled_captcha" value="0"><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
175
		</td>
176
	</tr>
177
	<tr><td>&nbsp;</td><td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_EXP'];?></td></tr>
178
	<tr><td colspan="2"><br /><strong><?php echo $MOD_CAPTCHA_CONTROL['ASP_CONF'];?>:</strong></td></tr>
179
	<tr>
180
		<td><?php echo $MOD_CAPTCHA_CONTROL['ASP_TEXT'];?>:</td>
181
		<td>
182
			<input type="radio" <?php echo ($enabled_asp=='1') ?'checked="checked"' :'';?>
183
				name="enabled_asp" value="1"><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
184
			<input type="radio" <?php echo ($enabled_asp=='0') ?'checked="checked"' :'';?>
185
				name="enabled_asp" value="0"><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
186
		</td>
187
	</tr>
188
	<tr><td>&nbsp;</td><td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['ASP_EXP'];?></td></tr>
189
	</table>
190
	<input type="submit" name="save_settings" style="margin-top:10px; width:140px;" value="<?php echo $TEXT['SAVE']; ?>" />
191
</form>
192
<?php
193
}
194

    
195
?>
(4-4/5)