Translated using Weblate (Slovenian)
[phpmyadmin.git] / error_report.php
bloba002c114f325397dee016be46cd85729a0c0b3d8
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 $errorReport = new ErrorReport(new HttpRequest());
32 if (isset($_POST['send_error_report'])
33 && ($_POST['send_error_report'] == true
34 || $_POST['send_error_report'] == '1')
35 ) {
36 if ($_POST['exception_type'] == 'php') {
37 /**
38 * Prevent infinite error submission.
39 * Happens in case error submissions fails.
40 * If reporting is done in some time interval,
41 * just clear them & clear json data too.
43 if (isset($_SESSION['prev_error_subm_time'])
44 && isset($_SESSION['error_subm_count'])
45 && $_SESSION['error_subm_count'] >= 3
46 && ($_SESSION['prev_error_subm_time'] - time()) <= 3000
47 ) {
48 $_SESSION['error_subm_count'] = 0;
49 $_SESSION['prev_errors'] = '';
50 $response->addJSON('_stopErrorReportLoop', '1');
51 } else {
52 $_SESSION['prev_error_subm_time'] = time();
53 $_SESSION['error_subm_count'] = (
54 isset($_SESSION['error_subm_count'])
55 ? ($_SESSION['error_subm_count'] + 1)
56 : 0
60 $reportData = $errorReport->getData($_POST['exception_type']);
61 // report if and only if there were 'actual' errors.
62 if (count($reportData) > 0) {
63 $server_response = $errorReport->send($reportData);
64 if ($server_response === false) {
65 $success = false;
66 } else {
67 $decoded_response = json_decode($server_response, true);
68 $success = ! empty($decoded_response) ?
69 $decoded_response["success"] : false;
72 /* Message to show to the user */
73 if ($success) {
74 if ((isset($_POST['automatic'])
75 && $_POST['automatic'] === "true")
76 || $GLOBALS['cfg']['SendErrorReports'] == 'always'
77 ) {
78 $msg = __(
79 'An error has been detected and an error report has been '
80 . 'automatically submitted based on your settings.'
82 } else {
83 $msg = __('Thank you for submitting this report.');
85 } else {
86 $msg = __(
87 'An error has been detected and an error report has been '
88 . 'generated but failed to be sent.'
90 . ' '
91 . __(
92 'If you experience any '
93 . 'problems please submit a bug report manually.'
96 $msg .= ' ' . __('You may want to refresh the page.');
98 /* Create message object */
99 if ($success) {
100 $msg = Message::notice($msg);
101 } else {
102 $msg = Message::error($msg);
105 /* Add message to response */
106 if ($response->isAjax()) {
107 if ($_POST['exception_type'] == 'js') {
108 $response->addJSON('message', $msg);
109 } else {
110 $response->addJSON('_errSubmitMsg', $msg);
112 } elseif ($_POST['exception_type'] == 'php') {
113 $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
114 . $msg
115 . '</div>", false);';
116 $response->getFooter()->getScripts()->addCode($jsCode);
119 if ($_POST['exception_type'] == 'php') {
120 // clear previous errors & save new ones.
121 $GLOBALS['error_handler']->savePreviousErrors();
124 /* Persist always send settings */
125 if (isset($_POST['always_send'])
126 && $_POST['always_send'] === "true"
128 $userPreferences = new UserPreferences();
129 $userPreferences->persistOption("SendErrorReports", "always", "ask");
132 } elseif (! empty($_POST['get_settings'])) {
133 $response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
134 } elseif ($_POST['exception_type'] == 'js') {
135 $response->addHTML($errorReport->getForm());
136 } else {
137 // clear previous errors & save new ones.
138 $GLOBALS['error_handler']->savePreviousErrors();