Project

General

Profile

1 2 Manuela
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         captcha_control
6
 * @author          WebsiteBaker Project
7
 * @copyright       WebsiteBaker Org. e.V.
8
 * @link            http://websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.3
11
 * @requirements    PHP 5.3.6 and higher
12
 * @version         $Id$
13
 * @filesource      $HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17
18
// prevent this file from being accessed directly
19
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
if(defined('WB_PATH') == false) { die('Cannot access '.basename(__DIR__).'/'.basename(__FILE__).' directly'); }
22
/* -------------------------------------------------------- */
23
// check if module language file exists for the language set by the user (e.g. DE, EN)
24
$sAddonsPath = basename(__DIR__);
25
require(WB_PATH .'/modules/'.$sAddonsPath.'/languages/EN.php');
26
if(file_exists(WB_PATH .'/modules/'.$sAddonsPath.'/languages/'.LANGUAGE .'.php')) {
27
    require(WB_PATH .'/modules/'.$sAddonsPath.'/languages/'.LANGUAGE .'.php');
28
}
29
$sModulName = basename(__DIR__);
30
$js_back = ADMIN_URL.'/admintools/tool.php';
31
$ToolUrl = ADMIN_URL.'/admintools/tool.php?tool=captcha_control';
32
if( !$admin->get_permission($sModulName,'module' ) ) {
33
//      die($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES']);
34
    $admin->print_error($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'], $js_back);
35
}
36
37
$table = TABLE_PREFIX.'mod_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
    // get configuration settings
48
    $enabled_captcha = ($_POST['enabled_captcha'] == '1') ? '1' : '0';
49
    $enabled_asp = ($_POST['enabled_asp'] == '1') ? '1' : '0';
50
    $captcha_type = $admin->add_slashes($_POST['captcha_type']);
51
52
    // update database settings
53
    $sql_captcha = '';
54
55
    if($captcha_type == 'text') { // ct_text
56
        $text_qa = isset($_POST['text_qa']) ? $_POST['text_qa'] :'calc_text';
57
        if(!preg_match('/### .*? ###/isU', $text_qa)) {
58
            $sql_captcha = ', `ct_text` = \''.$database->escapeString($text_qa).'\' ';
59
        }
60
    }
61
62
        $sql  = 'UPDATE `'.TABLE_PREFIX.'mod_captcha_control` SET '
63
              .'`enabled_captcha` = '.$database->escapeString($enabled_captcha).', '
64
              .'`enabled_asp` = '.$database->escapeString($enabled_asp).', '
65
              .'`captcha_type` = \''.$database->escapeString($captcha_type).'\' '
66
              .$sql_captcha;
67
    $database->query($sql);
68
69
    // check if there is a database error, otherwise say successful
70
    if(!$admin_header) { $admin->print_header(); }
71
    if($database->is_error()) {
72
        $admin->print_error($database->get_error(), $ToolUrl);
73
    } else {
74
        $admin->print_success($MESSAGE['PAGES']['SAVED'], $ToolUrl);
75
    }
76
77
} else {
78
}
79
80
    // include captcha-file
81
    require_once(WB_PATH .'/include/captcha/captcha.php');
82
83
    // load text-captchas
84
    $text_qa='';
85
    if($query = $database->query("SELECT `ct_text` FROM `$table`")) {
86
        $data = $query->fetchRow(MYSQLI_ASSOC);
87
        $text_qa = $data['ct_text'];
88
    }
89
    if($text_qa == '')
90
        $text_qa = $MOD_CAPTCHA_CONTROL['CAPTCHA_TEXT_DESC'];
91
92
// script to load image
93
?>
94
<script type="text/javascript">
95
    var pics = new Array();
96
97
    pics["ttf_image"] = new Image();
98
    pics["ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/ttf_image.png'?>";
99
100
    pics["calc_image"] = new Image();
101
    pics["calc_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_image.png'?>";
102
103
    pics["calc_ttf_image"] = new Image();
104
    pics["calc_ttf_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_ttf_image.png'?>";
105
106
    pics["old_image"] = new Image();
107
    pics["old_image"].src = "<?php echo WB_URL.'/include/captcha/captchas/old_image.png'?>";
108
109
    pics["calc_text"] = new Image();
110
    pics["calc_text"].src = "<?php echo WB_URL.'/include/captcha/captchas/calc_text.png'?>";
111
112
    pics["text"] = new Image();
113
    pics["text"].src = "<?php echo WB_URL.'/include/captcha/captchas/text.png'?>";
114
115
    function load_captcha_image() {
116
        var captcha = document.store_settings.captcha_type.value,
117
            example = document.getElementById('captcha_example');
118
        example.src = pics[captcha].src;
119
        toggle_text_qa();
120
    }
121
122
    function toggle_text_qa() {
123
        if(document.store_settings.captcha_type.value == 'text' ) {
124
            document.getElementById('text_qa').style.display = '';
125
        } else {
126
            document.getElementById('text_qa').style.display = 'none';
127
        }
128
    }
129
130
</script>
131
<?php
132
133
    // connect to database and read out captcha settings
134
    if($query = $database->query("SELECT * FROM $table")) {
135
        $data = $query->fetchRow();
136
        $enabled_captcha = $data['enabled_captcha'];
137
        $enabled_asp = $data['enabled_asp'];
138
        $captcha_type = $data['captcha_type'];
139
    } else {
140
        // something went wrong, use dummy value
141
        $enabled_captcha = '1';
142
        $enabled_asp = '1';
143
        $captcha_type = 'calc_text';
144
    }
145
146
    // write out heading
147
    echo '<h2>' .$MOD_CAPTCHA_CONTROL['HEADING'] .'</h2>';
148
149
    // output the form with values from the database
150
    echo '<p>' .$MOD_CAPTCHA_CONTROL['HOWTO'] .'</p>';
151
?>
152
<form name="store_settings" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
153
    <?php echo $admin->getFTAN(); ?>
154
    <table class="row_a" style="width: 98%;">
155
    <tr>
156
      <td colspan="2"><strong><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_CONF'];?>:</strong></td>
157
    </tr>
158
    <tr>
159
        <td style="width: 30%;"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_TYPE'];?>:</td>
160
        <td>
161
        <select name="captcha_type" id="captcha_type" onchange="load_captcha_image()" style="width: 98%;">
162
            <?php foreach($useable_captchas AS $key=>$text) {
163
            echo '<option value="'.$key.'" '.($captcha_type==$key ? ' selected="selected"' : '').">$text</option>";
164
            } ?>
165
        </select>
166
        </td>
167
    </tr>
168
    <tr>
169
        <td>&nbsp;</td>
170
        <td>
171
            <img alt="captcha_example" id="captcha_example" height="40" src="<?php echo WB_URL.'/include/captcha/captchas/'.$captcha_type.'.png'?>" />
172
        </td>
173
    </tr>
174
    <tr id="text_qa" style="display:<?php if($captcha_type=='text') echo ''; else echo 'none'; ;?>;">
175
        <td  style="vertical-align: top;" class="setting_name"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_ENTER_TEXT'];?>:</td>
176
        <td class="setting_value" >
177
            <textarea name="text_qa" cols="60" rows="10"><?php echo $text_qa; ?></textarea>
178
        </td>
179
    </tr>
180
    <tr>
181
        <td><?php echo $MOD_CAPTCHA_CONTROL['USE_SIGNUP_CAPTCHA'];?>:</td>
182
        <td>
183
            <input type="radio" <?php echo ($enabled_captcha=='1') ?'checked="checked"' :'';?>
184
                name="enabled_captcha" value="1" /><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
185
            <input type="radio" <?php echo ($enabled_captcha=='0') ?'checked="checked"' :'';?>
186
                name="enabled_captcha" value="0" /><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
187
        </td>
188
    </tr>
189
    <tr><td>&nbsp;</td><td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['CAPTCHA_EXP'];?></td></tr>
190
    <tr><td colspan="2"><br /><strong><?php echo $MOD_CAPTCHA_CONTROL['ASP_CONF'];?>:</strong></td></tr>
191
    <tr>
192
        <td><?php echo $MOD_CAPTCHA_CONTROL['ASP_TEXT'];?>:</td>
193
        <td>
194
            <input type="radio" <?php echo ($enabled_asp=='1') ?'checked="checked"' :'';?>
195
                name="enabled_asp" value="1" /><?php echo $MOD_CAPTCHA_CONTROL['ENABLED'];?>
196
            <input type="radio" <?php echo ($enabled_asp=='0') ?'checked="checked"' :'';?>
197
                name="enabled_asp" value="0" /><?php echo $MOD_CAPTCHA_CONTROL['DISABLED'];?>
198
        </td>
199
    </tr>
200
    <tr>
201
        <td>&nbsp;</td>
202
        <td style="font-size:smaller;"><?php echo $MOD_CAPTCHA_CONTROL['ASP_EXP'];?></td>
203
    </tr>
204
    </table>
205
    <input type="submit" name="save_settings" style="margin-top:10px; width:140px;" value="<?php echo $TEXT['SAVE']; ?>" />
206
</form>