Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         captcha_control
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: tool.php 1891 2013-03-19 11:09:05Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/captcha_control/tool.php $
14
 * @lastmodified    $Date: 2013-03-19 12:09:05 +0100 (Tue, 19 Mar 2013) $
15
 *
16
 */
17

    
18
// prevent this file from being accessed directly
19
/* -------------------------------------------------------- */
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24
}
25
/* -------------------------------------------------------- */
26

    
27
// check if module language file exists for the language set by the user (e.g. DE, EN)
28
if(!file_exists(WB_PATH .'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
29
	// no module language file exists for the language set by the user, include default module language file EN.php
30
	require_once(WB_PATH .'/modules/captcha_control/languages/EN.php');
31
} else {
32
	// a module language file exists for the language defined by the user, load it
33
	require_once(WB_PATH .'/modules/captcha_control/languages/'.LANGUAGE .'.php');
34
}
35

    
36
$table = TABLE_PREFIX.'mod_captcha_control';
37
$js_back = ADMIN_URL.'/admintools/tool.php?tool=captcha_control';
38

    
39
// check if data was submitted
40
if(isset($_POST['save_settings'])) {
41
	if (!$admin->checkFTAN())
42
	{
43
		if(!$admin_header) { $admin->print_header(); }
44
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
45
	}
46

    
47
    $ct_text = '';
48
    $captcha_type = 'calc_text';
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
	// save text-captchas
54
	if($captcha_type == 'text') { // ct_text
55
		$text_qa=$admin->add_slashes($_POST['text_qa']);
56
		if(!preg_match('/### .*? ###/', $text_qa)) {
57
            $ct_text = $text_qa;
58
		}
59
	}
60

    
61

    
62
// update/insert database settings
63
	$sql  = 'UPDATE `'.$table.'` ';
64
    $sql .= 'SET `enabled_captcha` = \''.$enabled_captcha.'\', ';
65
    $sql .=     '`enabled_asp` = \''.$enabled_asp.'\', ';
66
    $sql .=     '`captcha_type` = \''.$captcha_type.'\', ';
67
    $sql .=     '`asp_session_min_age` = 20, ';
68
    $sql .=     '`asp_view_min_age` = 10, ';
69
    $sql .=     '`asp_input_min_age` = 5, ';
70
    $sql .=     '`ct_text` =\''.$ct_text.'\' ';
71

    
72
    if(!$database->query($sql)) {
73
    }
74

    
75
	// check if there is a database error, otherwise say successful
76
	if(!$admin_header) { $admin->print_header(); }
77
	if($database->is_error()) {
78
		$admin->print_error($database->get_error(), $js_back);
79
	} else {
80
		$admin->print_success($MESSAGE['PAGES']['SAVED'], $js_back);
81
	}
82

    
83
} else {
84
}
85

    
86
	// include captcha-file
87
	require_once(WB_PATH .'/include/captcha/captcha.php');
88

    
89
	// load text-captchas
90
	$text_qa='';
91
	if($query = $database->query("SELECT ct_text FROM $table")) {
92
		$data = $query->fetchRow();
93
		$text_qa = $data['ct_text'];
94
	}
95
	if($text_qa == '')
96
		$text_qa = $MOD_CAPTCHA_CONTROL['CAPTCHA_TEXT_DESC'];
97

    
98
// script to load image
99
?>
100
<script type="text/javascript">
101
	var pics = new Array();
102

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

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

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

    
112
	pics["old_image"] = new Image();
113
	pics["old_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/old_image.png'?>";
114

    
115
	pics["calc_text"] = new Image();
116
	pics["calc_text"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_text.png'?>";
117

    
118
	pics["text"] = new Image();
119
	pics["text"].src = "<?php echo WB_URL.'/include/captcha/captchas/text.png'?>";
120

    
121
	function load_captcha_image() {
122
		document.captcha_example.src = pics[document.store_settings.captcha_type.value].src;
123
		toggle_text_qa();
124
	}
125

    
126
	function toggle_text_qa() {
127
		if(document.store_settings.captcha_type.value == 'text' ) {
128
			document.getElementById('text_qa').style.display = '';
129
		} else {
130
			document.getElementById('text_qa').style.display = 'none';
131
		}
132
	}
133

    
134
</script>
135
<?php
136

    
137
	// connect to database and read out captcha settings
138
	if($query = $database->query("SELECT * FROM $table")) {
139
		$data = $query->fetchRow();
140
		$enabled_captcha = $data['enabled_captcha'];
141
		$enabled_asp = $data['enabled_asp'];
142
		$captcha_type = $data['captcha_type'];
143
	} else {
144
		// something went wrong, use dummy value
145
		$enabled_captcha = '1';
146
		$enabled_asp = '1';
147
		$captcha_type = 'calc_text';
148
	}
149

    
150
	// write out heading
151
	echo '<h2>' .$MOD_CAPTCHA_CONTROL['HEADING'] .'</h2>';
152

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