Project

General

Profile

1
<?php
2

    
3
// $Id: tool.php 1457 2011-06-25 17:18:50Z Luisehahne $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, 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
// Must include code to stop this file being access directly
26
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
27

    
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
$js_back = ADMIN_URL.'/admintools/tool.php?tool=captcha_control';
40

    
41
// check if data was submitted
42
if(isset($_POST['save_settings'])) {
43
	if (!$admin->checkFTAN())
44
	{
45
		$admin->print_header();
46
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
47
	}
48
	
49
	// get configuration settings
50
	$enabled_captcha = ($_POST['enabled_captcha'] == '1') ? '1' : '0';
51
	$enabled_asp = ($_POST['enabled_asp'] == '1') ? '1' : '0';
52
	$captcha_type = $admin->add_slashes($_POST['captcha_type']);
53
	
54
	// update database settings
55
	$database->query("UPDATE $table SET
56
		enabled_captcha = '$enabled_captcha',
57
		enabled_asp = '$enabled_asp',
58
		captcha_type = '$captcha_type'
59
	");
60

    
61
	// save text-captchas
62
	if($captcha_type == 'text') { // ct_text
63
		$text_qa=$admin->add_slashes($_POST['text_qa']);
64
		if(!preg_match('/### .*? ###/', $text_qa)) {
65
			$database->query("UPDATE $table SET ct_text = '$text_qa'");
66
		}
67
	}
68
	
69
	// check if there is a database error, otherwise say successful
70
	$admin->print_header();
71
	if($database->is_error()) {
72
		$admin->print_error($database->get_error(), $js_back);
73
	} else {
74
		$admin->print_success($MESSAGE['PAGES']['SAVED'], $js_back);
75
	}
76

    
77
} else {
78
	
79
	// include captcha-file
80
	require_once(WB_PATH .'/include/captcha/captcha.php');
81

    
82
	// load text-captchas
83
	$text_qa='';
84
	if($query = $database->query("SELECT ct_text FROM $table")) {
85
		$data = $query->fetchRow();
86
		$text_qa = $data['ct_text'];
87
	}
88
	if($text_qa == '')
89
		$text_qa = $MOD_CAPTCHA_CONTROL['CAPTCHA_TEXT_DESC'];
90

    
91
// script to load image
92
?>
93
<script type="text/javascript">
94
	var pics = new Array();
95

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

    
99
	pics["calc_image"] = new Image();
100
	pics["calc_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_image.png'?>";
101

    
102
	pics["calc_ttf_image"] = new Image();
103
	pics["calc_ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_ttf_image.png'?>";
104

    
105
	pics["old_image"] = new Image();
106
	pics["old_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/old_image.png'?>";
107
	
108
	pics["calc_text"] = new Image();
109
	pics["calc_text"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_text.png'?>";
110
	
111
	pics["text"] = new Image();
112
	pics["text"].src = "<?php echo WB_URL.'/include/captcha/captchas/text.png'?>";
113

    
114
	function load_captcha_image() {
115
		document.captcha_example.src = pics[document.store_settings.captcha_type.value].src;
116
		toggle_text_qa();
117
	}
118
	
119
	function toggle_text_qa() {
120
		if(document.store_settings.captcha_type.value == 'text' ) {
121
			document.getElementById('text_qa').style.display = '';
122
		} else {
123
			document.getElementById('text_qa').style.display = 'none';
124
		}
125
	}
126

    
127
</script>
128
<?php
129

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

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

    
205
?>
(4-4/5)