Issues (1798)

public/main/admin/settings.php (2 issues)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * @deprecated This file is very likely completely deprecated
7
 */
8
9
use ChamiloSession as Session;
10
11
/**
12
 * With this tool you can easily adjust non-critical configuration settings.
13
 * Non-critical means that changing them will not result in a broken campus.
14
 *
15
 * @author Patrick Cool
16
 * @author Julio Montoya - Multiple URL site
17
 */
18
19
// Resetting the course id.
20
$cidReset = true;
21
22
require_once __DIR__.'/../inc/global.inc.php';
23
require_once 'settings.lib.php';
24
25
// Setting the section (for the tabs).
26
$this_section = SECTION_PLATFORM_ADMIN;
27
$_SESSION['this_section'] = $this_section;
28
29
// Access restrictions.
30
api_protect_admin_script();
31
32
// Database table definitions.
33
$table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS);
34
35
// Setting breadcrumbs.
36
$interbreadcrumb[] = ['url' => api_get_path(WEB_PATH).'admin', 'name' => get_lang('Administration')];
37
38
// Setting the name of the tool.
39
$tool_name = get_lang('Configuration settings');
40
if (empty($_GET['category'])) {
41
    $_GET['category'] = 'Platform';
42
}
43
$watermark_deleted = false;
44
if (isset($_GET['delete_watermark'])) {
45
    $watermark_deleted = PDF::delete_watermark();
46
    Display::addFlash(Display::return_message(get_lang('File deleted')));
47
}
48
49
if (isset($_GET['action']) && 'delete_grading' == $_GET['action']) {
50
    $id = intval($_GET['id']);
51
    api_delete_setting_option($id);
52
}
53
54
$url_id = api_get_current_access_url_id();
55
56
$settings = null;
57
58
// Build the form.
59
if (!empty($_GET['category']) &&
60
    !in_array($_GET['category'], ['Plugins', 'Search'])
61
) {
62
    $my_category = isset($_GET['category']) ? $_GET['category'] : null;
63
    $settings_array = getCategorySettings($my_category);
64
    $settings = $settings_array['settings'];
65
    $settings_by_access_list = $settings_array['settings_by_access_list'];
66
    $form = generateSettingsForm($settings, $settings_by_access_list);
67
68
    if ($form->validate()) {
69
        $values = $form->exportValues();
70
71
        $mark_all = false;
72
        $un_mark_all = false;
73
74
        if (api_is_multiple_url_enabled()) {
0 ignored issues
show
Deprecated Code introduced by
The function api_is_multiple_url_enabled() has been deprecated: Use AccessUrlHelper::isMultiple ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

74
        if (/** @scrutinizer ignore-deprecated */ api_is_multiple_url_enabled()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
75
            if (isset($values['buttons_in_action_right']) &&
76
                isset($values['buttons_in_action_right']['mark_all'])
77
            ) {
78
                $mark_all = true;
79
            }
80
81
            if (isset($values['buttons_in_action_right']) &&
82
                isset($values['buttons_in_action_right']['unmark_all'])
83
            ) {
84
                $un_mark_all = true;
85
            }
86
        }
87
88
        if ($mark_all || $un_mark_all) {
89
            if (api_is_global_platform_admin()) {
90
                $locked_settings = api_get_locked_settings();
91
                foreach ($values as $key => $value) {
92
                    if (!in_array($key, $locked_settings)) {
93
                        $changeable = 0;
94
                        if ($mark_all) {
95
                            $changeable = 1;
96
                        }
97
98
                        $params = ['variable = ?' => [$key]];
99
                        $data = api_get_settings_params($params);
100
101
                        if (!empty($data)) {
102
                            foreach ($data as $item) {
103
                                $params = [
104
                                    'id' => $item['id'],
105
                                    'access_url_changeable' => $changeable,
106
                                ];
107
                                api_set_setting_simple($params);
108
                            }
109
                        }
110
                    }
111
                }
112
                // Reload settings
113
                $settings_array = getCategorySettings($my_category);
114
                $settings = $settings_array['settings'];
115
                $settings_by_access_list = $settings_array['settings_by_access_list'];
116
                $form = generateSettingsForm(
117
                    $settings,
118
                    $settings_by_access_list
119
                );
120
            }
121
        }
122
        if (!empty($_FILES['pdf_export_watermark_path'])) {
123
            $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
124
        }
125
126
        if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
127
            $pdf_export_watermark_path_result = PDF::upload_watermark(
128
                $pdf_export_watermark_path['name'],
129
                $pdf_export_watermark_path['tmp_name']
130
            );
131
            if ($pdf_export_watermark_path_result) {
132
                Display::addFlash(Display::return_message(get_lang('File upload succeeded!')));
133
            } else {
134
                $message = get_lang('The uploaded file could not be saved (perhaps a permission problem?)').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
135
                Display::addFlash(Display::return_message($message), 'warning');
136
            }
137
            unset($update_values['pdf_export_watermark_path']);
138
        }
139
140
        if (isset($values['allow_social_tool']) && 'true' == $values['allow_social_tool']) {
141
            $values['allow_message_tool'] = 'true';
142
        }
143
144
        foreach ($settings as $item) {
145
            $key = $item['variable'];
146
            if ('prevent_multiple_simultaneous_login' === $key) {
147
                Session::write('first_user_login', 1);
148
            }
149
            if ('search_field' == $key || 'submit_fixed_in_bottom' == $key) {
150
                continue;
151
            }
152
            $key = Database::escape_string($key);
153
            $sql = "UPDATE $table_settings_current
154
                    SET selected_value = 'false'
155
                    WHERE
156
                        variable = '".$key."' AND
157
                        access_url = ".intval($url_id)." AND
158
                        type IN ('checkbox', 'radio') ";
159
            $res = Database::query($sql);
160
        }
161
162
        // Save the settings.
163
        $keys = [];
164
165
        foreach ($values as $key => $value) {
166
            if (0 === strcmp($key, 'MAX_FILE_SIZE')) {
167
                continue;
168
            }
169
            // Avoid form elements which have nothing to do with settings
170
            if ('search_field' == $key || 'submit_fixed_in_bottom' == $key) {
171
                continue;
172
            }
173
174
            // Treat gradebook values in separate function.
175
            //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
176
            if (!is_array($value)) {
177
                $old_value = api_get_setting($key);
178
                switch ($key) {
179
                    case 'header_extra_content':
180
                        file_put_contents(api_get_home_path().'header_extra_content.txt', $value);
0 ignored issues
show
The function api_get_home_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
                        file_put_contents(/** @scrutinizer ignore-call */ api_get_home_path().'header_extra_content.txt', $value);
Loading history...
181
                        $value = api_get_home_path().'header_extra_content.txt';
182
                        break;
183
                    case 'footer_extra_content':
184
                        file_put_contents(api_get_home_path().'footer_extra_content.txt', $value);
185
                        $value = api_get_home_path().'footer_extra_content.txt';
186
                        break;
187
                    case 'InstitutionUrl':
188
                    case 'course_validation_terms_and_conditions_url':
189
                        // URL validation for some settings.
190
                        $value = trim(Security::remove_XSS($value));
191
                        if ('' != $value) {
192
                            // Here we accept absolute URLs only.
193
                            if (false === strpos($value, '://')) {
194
                                $value = 'http://'.$value;
195
                            }
196
                            if (!api_valid_url($value, true)) {
197
                                // If the new (non-empty) URL value is invalid, then the old URL value stays.
198
                                $value = $old_value;
199
                            }
200
                        }
201
                        // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
202
                        break;
203
                    case 'emailAdministrator':
204
                        // Validation against e-mail address for some settings.
205
                        $value = trim(Security::remove_XSS($value));
206
                        if ('' != $value && !api_valid_email($value)) {
207
                            // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
208
                            // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
209
                            $value = $old_value;
210
                        }
211
                        break;
212
                }
213
                if ($old_value != $value) {
214
                    $keys[] = $key;
215
                }
216
                $result = api_set_setting($key, $value, null, null, $url_id);
217
            } else {
218
                $sql = "SELECT subkey FROM $table_settings_current
219
                        WHERE variable = '$key'";
220
                $res = Database::query($sql);
221
222
                while ($row_subkeys = Database::fetch_array($res)) {
223
                    // If subkey is changed:
224
                    if ((isset($value[$row_subkeys['subkey']]) && 'false' == api_get_setting($key, $row_subkeys['subkey'])) ||
225
                        (!isset($value[$row_subkeys['subkey']]) && 'true' == api_get_setting($key, $row_subkeys['subkey']))
226
                    ) {
227
                        $keys[] = $key;
228
                        break;
229
                    }
230
                }
231
232
                foreach ($value as $subkey => $subvalue) {
233
                    $result = api_set_setting($key, 'true', $subkey, null, $url_id);
234
                }
235
            }
236
        }
237
238
        // Add event configuration settings category to the system log.
239
        $user_id = api_get_user_id();
240
        $category = $_GET['category'];
241
        Event::addEvent(
242
            LOG_CONFIGURATION_SETTINGS_CHANGE,
243
            LOG_CONFIGURATION_SETTINGS_CATEGORY,
244
            $category,
245
            api_get_utc_datetime(),
246
            $user_id
247
        );
248
249
        // Add event configuration settings variable to the system log.
250
        if (is_array($keys) && count($keys) > 0) {
251
            foreach ($keys as $variable) {
252
                Event::addEvent(
253
                    LOG_CONFIGURATION_SETTINGS_CHANGE,
254
                    LOG_CONFIGURATION_SETTINGS_VARIABLE,
255
                    $variable,
256
                    api_get_utc_datetime(),
257
                    $user_id
258
                );
259
            }
260
        }
261
262
        Display::addFlash(Display::return_message(get_lang('Update successful')));
263
264
        header('Location: '.api_get_self().'?category='.Security::remove_XSS($my_category));
265
        exit;
266
    }
267
}
268
$htmlHeadXtra[] = '<script>
269
    var hide_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting_na.png";
270
    var show_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting.png";
271
    var url       = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
272
273
    $(function() {
274
        $(".share_this_setting").on("click", function() {
275
            var my_img = $(this).find("img");
276
            var link = $(this);
277
            $.ajax({
278
                url: url,
279
                data: {
280
                    changeable: $(this).attr("data_status"),
281
                    id: $(this).attr("data_to_send")
282
                },
283
                success: function(data) {
284
                    if (data == 1) {
285
                        if (link.attr("data_status") == 1) {
286
                            my_img.attr("src", show_icon);
287
                            link.attr("data_status", 0);
288
                        } else {
289
                            my_img.attr("src", hide_icon);
290
                            link.attr("data_status", 1);
291
                        }
292
                    }
293
                }
294
            });
295
        });
296
    });
297
</script>';
298
299
ob_start();
300
if (!empty($_GET['category'])) {
301
    switch ($_GET['category']) {
302
        case 'Regions':
303
            handleRegions();
304
            break;
305
        case 'Plugins':
306
            echo '<div class="tab_wrapper">';
307
            echo '<ul class="nav nav-tabs" id="tabs" role="tablist">';
308
            echo '<li class="nav-item"><a id="plugin-tab-1" class="nav-link active" href="#tab1" aria-controls="tab1" aria-selected="true">'.get_lang('Plugins').'</a></li>';
309
            echo '</ul>';
310
311
            echo '<div class="tab-content" id="tabs-content">';
312
            echo '<div class="tab-pane fade show active" id="tab1" role="tabpanel" aria-labelledby="plugin-tab-1">';
313
            handlePlugins();
314
            echo '</div>';
315
            echo '</div>';
316
            echo '</div>';
317
            break;
318
        case 'Search':
319
            handleSearch();
320
            break;
321
        case 'Templates':
322
            handleTemplates();
323
            break;
324
        default:
325
            api_not_allowed(true);
326
            break;
327
    }
328
}
329
$content = ob_get_clean();
330
331
// Including the header (banner).
332
Display::display_header($tool_name);
333
334
echo $content;
335
336
Display::display_footer();
337