Translated using Weblate (Dutch)
[phpmyadmin.git] / error_report.php
blob4510f1ad514da1666ee24bd47dab636795f0b62b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handle error report submission
6 * @package PhpMyAdmin
7 */
8 require_once 'libraries/common.inc.php';
9 require_once 'libraries/error_report.lib.php';
10 require_once 'libraries/user_preferences.lib.php';
12 if (!isset($_REQUEST['exception_type'])
13 ||!in_array($_REQUEST['exception_type'], array('js', 'php'))
14 ) {
15 die('Oops, something went wrong!!');
18 $response = PMA_Response::getInstance();
20 if (isset($_REQUEST['send_error_report'])
21 && ($_REQUEST['send_error_report'] == true
22 || $_REQUEST['send_error_report'] == '1')
23 ) {
24 if ($_REQUEST['exception_type'] == 'php') {
25 /**
26 * Prevent infinite error submission.
27 * Happens in case error submissions fails.
28 * If reporting is done in some time interval,
29 * just clear them & clear json data too.
31 if (isset($_SESSION['prev_error_subm_time'])
32 && isset($_SESSION['error_subm_count'])
33 && $_SESSION['error_subm_count'] >= 3
34 && ($_SESSION['prev_error_subm_time']-time()) <= 3000
35 ) {
36 $_SESSION['error_subm_count'] = 0;
37 $_SESSION['prev_errors'] = '';
38 $response = PMA_Response::getInstance();
39 $response->addJSON('_stopErrorReportLoop', '1');
40 } else {
41 $_SESSION['prev_error_subm_time'] = time();
42 $_SESSION['error_subm_count'] = (
43 (isset($_SESSION['error_subm_count']))
44 ? ($_SESSION['error_subm_count']+1)
45 : (0)
49 $reportData = PMA_getReportData($_REQUEST['exception_type']);
50 // report if and only if there were 'actual' errors.
51 if (count($reportData) > 0) {
52 $server_response = PMA_sendErrorReport($reportData);
53 if ($server_response === false) {
54 $success = false;
55 } else {
56 $decoded_response = json_decode($server_response, true);
57 $success = !empty($decoded_response) ?
58 $decoded_response["success"] : false;
61 /* Message to show to the user */
62 if ($success) {
63 if ((isset($_REQUEST['automatic'])
64 && $_REQUEST['automatic'] === "true")
65 || $GLOBALS['cfg']['SendErrorReports'] == 'always'
66 ) {
67 $msg = __(
68 'An error has been detected and an error report has been '
69 . 'automatically submitted based on your settings.'
71 } else {
72 $msg = __('Thank you for submitting this report.');
74 } else {
75 $msg = __(
76 'An error has been detected and an error report has been '
77 . 'generated but failed to be sent.'
79 . ' '
80 . __(
81 'If you experience any '
82 . 'problems please submit a bug report manually.'
85 $msg .= ' ' . __('You may want to refresh the page.');
87 /* Create message object */
88 if ($success) {
89 $msg = PMA_Message::notice($msg);
90 } else {
91 $msg = PMA_Message::error($msg);
94 /* Add message to response */
95 if ($response->isAjax()) {
96 if ($_REQUEST['exception_type'] == 'js') {
97 $response->addJSON('message', $msg);
98 } else {
99 $response->addJSON('_errSubmitMsg', $msg);
101 } elseif ($_REQUEST['exception_type'] == 'php') {
102 $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
103 . $msg
104 . '</div>", false);';
105 $response->getFooter()->getScripts()->addCode($jsCode);
108 if ($_REQUEST['exception_type'] == 'php') {
109 // clear previous errors & save new ones.
110 $GLOBALS['error_handler']->savePreviousErrors();
113 /* Persist always send settings */
114 if (isset($_REQUEST['always_send'])
115 && $_REQUEST['always_send'] === "true"
117 PMA_persistOption("SendErrorReports", "always", "ask");
120 } elseif (! empty($_REQUEST['get_settings'])) {
121 $response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
122 } else {
123 if ($_REQUEST['exception_type'] == 'js') {
124 $response->addHTML(PMA_getErrorReportForm());
125 } else {
126 // clear previous errors & save new ones.
127 $GLOBALS['error_handler']->savePreviousErrors();