Translated using Weblate (Bulgarian)
[phpmyadmin.git] / error_report.php
blob98825691e4f47ef6b5fa2c0821c335cc43197abe
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handle error report submission
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\ErrorReport;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\UserPreferences;
14 use PhpMyAdmin\Utils\HttpRequest;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
20 require_once ROOT_PATH . 'libraries/common.inc.php';
22 if (! isset($_POST['exception_type'])
23 || ! in_array($_POST['exception_type'], ['js', 'php'])
24 ) {
25 die('Oops, something went wrong!!');
28 $response = Response::getInstance();
30 /** @var ErrorReport $errorReport */
31 $errorReport = $containerBuilder->get('error_report');
33 if (isset($_POST['send_error_report'])
34 && ($_POST['send_error_report'] == true
35 || $_POST['send_error_report'] == '1')
36 ) {
37 if ($_POST['exception_type'] == 'php') {
38 /**
39 * Prevent infinite error submission.
40 * Happens in case error submissions fails.
41 * If reporting is done in some time interval,
42 * just clear them & clear json data too.
44 if (isset($_SESSION['prev_error_subm_time'])
45 && isset($_SESSION['error_subm_count'])
46 && $_SESSION['error_subm_count'] >= 3
47 && ($_SESSION['prev_error_subm_time'] - time()) <= 3000
48 ) {
49 $_SESSION['error_subm_count'] = 0;
50 $_SESSION['prev_errors'] = '';
51 $response->addJSON('stopErrorReportLoop', '1');
52 } else {
53 $_SESSION['prev_error_subm_time'] = time();
54 $_SESSION['error_subm_count'] = (
55 isset($_SESSION['error_subm_count'])
56 ? ($_SESSION['error_subm_count'] + 1)
57 : 0
61 $reportData = $errorReport->getData($_POST['exception_type']);
62 // report if and only if there were 'actual' errors.
63 if (count($reportData) > 0) {
64 $server_response = $errorReport->send($reportData);
65 if (! is_string($server_response)) {
66 $success = false;
67 } else {
68 $decoded_response = json_decode($server_response, true);
69 $success = ! empty($decoded_response) ?
70 $decoded_response["success"] : false;
73 /* Message to show to the user */
74 if ($success) {
75 if ((isset($_POST['automatic'])
76 && $_POST['automatic'] === "true")
77 || $GLOBALS['cfg']['SendErrorReports'] == 'always'
78 ) {
79 $msg = __(
80 'An error has been detected and an error report has been '
81 . 'automatically submitted based on your settings.'
83 } else {
84 $msg = __('Thank you for submitting this report.');
86 } else {
87 $msg = __(
88 'An error has been detected and an error report has been '
89 . 'generated but failed to be sent.'
91 . ' '
92 . __(
93 'If you experience any '
94 . 'problems please submit a bug report manually.'
97 $msg .= ' ' . __('You may want to refresh the page.');
99 /* Create message object */
100 if ($success) {
101 $msg = Message::notice($msg);
102 } else {
103 $msg = Message::error($msg);
106 /* Add message to response */
107 if ($response->isAjax()) {
108 if ($_POST['exception_type'] == 'js') {
109 $response->addJSON('message', $msg);
110 } else {
111 $response->addJSON('errSubmitMsg', $msg);
113 } elseif ($_POST['exception_type'] == 'php') {
114 $jsCode = 'Functions.ajaxShowMessage("<div class=\"error\">'
115 . $msg
116 . '</div>", false);';
117 $response->getFooter()->getScripts()->addCode($jsCode);
120 if ($_POST['exception_type'] == 'php') {
121 // clear previous errors & save new ones.
122 $GLOBALS['error_handler']->savePreviousErrors();
125 /* Persist always send settings */
126 if (isset($_POST['always_send'])
127 && $_POST['always_send'] === "true"
129 $userPreferences = new UserPreferences();
130 $userPreferences->persistOption("SendErrorReports", "always", "ask");
133 } elseif (! empty($_POST['get_settings'])) {
134 $response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
135 } elseif ($_POST['exception_type'] == 'js') {
136 $response->addHTML($errorReport->getForm());
137 } else {
138 // clear previous errors & save new ones.
139 $GLOBALS['error_handler']->savePreviousErrors();