Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         captcha_control
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker 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 1747 2012-09-09 17:01:33Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/captcha_control/tool.php $
14
 * @lastmodified    $Date: 2012-09-09 19:01:33 +0200 (Sun, 09 Sep 2012) $
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 database settings
63

    
64
    $sql  = 'UPDATE '.$table.' ';
65
    $sql .= 'SET `enabled_captcha` = \''.$enabled_captcha.'\', ';
66
    $sql .=     '`enabled_asp` = \''.$enabled_asp.'\', ';
67
    $sql .=     '`captcha_type` = \''.$captcha_type.'\', ';
68
    $sql .=     '`asp_session_min_age` = 20, ';
69
    $sql .=     '`asp_view_min_age` = 10, ';
70
    $sql .=     '`asp_input_min_age` = 5, ';
71
    $sql .=     '`ct_text` =\''.$ct_text.'\' ';
72

    
73
    if(!$database->query($sql)) {
74
    //    print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
75
    //    print_r( explode(',',$sql) ); print '</pre>'; // flush ();sleep(10); die();
76
    }
77

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

    
86
} else {
87
}
88

    
89
	// include captcha-file
90
	require_once(WB_PATH .'/include/captcha/captcha.php');
91

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

    
101
// script to load image
102
?>
103
<script type="text/javascript">
104
	var pics = new Array();
105

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

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

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

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

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

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

    
124
	function load_captcha_image() {
125
		document.captcha_example.src = pics[document.store_settings.captcha_type.value].src;
126
		toggle_text_qa();
127
	}
128

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

    
137
</script>
138
<?php
139

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

    
153
	// write out heading
154
	echo '<h2>' .$MOD_CAPTCHA_CONTROL['HEADING'] .'</h2>';
155

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