Translated using Weblate (Estonian)
[phpmyadmin.git] / error_report.php
blob3e9c9a6b1ca5ae131d9e4869582e0c2752d24d50
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handle error report submission
6 * @package PhpMyAdmin
7 */
8 use PhpMyAdmin\ErrorReport;
9 use PhpMyAdmin\Message;
10 use PhpMyAdmin\Response;
11 use PhpMyAdmin\UserPreferences;
12 use PhpMyAdmin\Utils\HttpRequest;
14 require_once 'libraries/common.inc.php';
16 if (!isset($_POST['exception_type'])
17 ||!in_array($_POST['exception_type'], array('js', 'php'))
18 ) {
19 die('Oops, something went wrong!!');
22 $response = Response::getInstance();
24 $errorReport = new ErrorReport(new HttpRequest());
26 if (isset($_POST['send_error_report'])
27 && ($_POST['send_error_report'] == true
28 || $_POST['send_error_report'] == '1')
29 ) {
30 if ($_POST['exception_type'] == 'php') {
31 /**
32 * Prevent infinite error submission.
33 * Happens in case error submissions fails.
34 * If reporting is done in some time interval,
35 * just clear them & clear json data too.
37 if (isset($_SESSION['prev_error_subm_time'])
38 && isset($_SESSION['error_subm_count'])
39 && $_SESSION['error_subm_count'] >= 3
40 && ($_SESSION['prev_error_subm_time']-time()) <= 3000
41 ) {
42 $_SESSION['error_subm_count'] = 0;
43 $_SESSION['prev_errors'] = '';
44 $response->addJSON('_stopErrorReportLoop', '1');
45 } else {
46 $_SESSION['prev_error_subm_time'] = time();
47 $_SESSION['error_subm_count'] = (
48 (isset($_SESSION['error_subm_count']))
49 ? ($_SESSION['error_subm_count']+1)
50 : (0)
54 $reportData = $errorReport->getData($_POST['exception_type']);
55 // report if and only if there were 'actual' errors.
56 if (count($reportData) > 0) {
57 $server_response = $errorReport->send($reportData);
58 if (! is_string($server_response)) {
59 $success = false;
60 } else {
61 $decoded_response = json_decode($server_response, true);
62 $success = !empty($decoded_response) ?
63 $decoded_response["success"] : false;
66 /* Message to show to the user */
67 if ($success) {
68 if ((isset($_POST['automatic'])
69 && $_POST['automatic'] === "true")
70 || $GLOBALS['cfg']['SendErrorReports'] == 'always'
71 ) {
72 $msg = __(
73 'An error has been detected and an error report has been '
74 . 'automatically submitted based on your settings.'
76 } else {
77 $msg = __('Thank you for submitting this report.');
79 } else {
80 $msg = __(
81 'An error has been detected and an error report has been '
82 . 'generated but failed to be sent.'
84 . ' '
85 . __(
86 'If you experience any '
87 . 'problems please submit a bug report manually.'
90 $msg .= ' ' . __('You may want to refresh the page.');
92 /* Create message object */
93 if ($success) {
94 $msg = Message::notice($msg);
95 } else {
96 $msg = Message::error($msg);
99 /* Add message to response */
100 if ($response->isAjax()) {
101 if ($_POST['exception_type'] == 'js') {
102 $response->addJSON('message', $msg);
103 } else {
104 $response->addJSON('_errSubmitMsg', $msg);
106 } elseif ($_POST['exception_type'] == 'php') {
107 $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
108 . $msg
109 . '</div>", false);';
110 $response->getFooter()->getScripts()->addCode($jsCode);
113 if ($_POST['exception_type'] == 'php') {
114 // clear previous errors & save new ones.
115 $GLOBALS['error_handler']->savePreviousErrors();
118 /* Persist always send settings */
119 if (isset($_POST['always_send'])
120 && $_POST['always_send'] === "true"
122 $userPreferences = new UserPreferences();
123 $userPreferences->persistOption("SendErrorReports", "always", "ask");
126 } elseif (! empty($_POST['get_settings'])) {
127 $response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
128 } else {
129 if ($_POST['exception_type'] == 'js') {
130 $response->addHTML($errorReport->getForm());
131 } else {
132 // clear previous errors & save new ones.
133 $GLOBALS['error_handler']->savePreviousErrors();