Translated using Weblate (Indonesian)
[phpmyadmin.git] / error_report.php
bloba984bf938b63e0bb0710f5d0ef25b5e656b6111e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handle error report submission
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Response;
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/error_report.lib.php';
11 require_once 'libraries/user_preferences.lib.php';
13 if (!isset($_REQUEST['exception_type'])
14 ||!in_array($_REQUEST['exception_type'], array('js', 'php'))
15 ) {
16 die('Oops, something went wrong!!');
19 $response = Response::getInstance();
21 if (isset($_REQUEST['send_error_report'])
22 && ($_REQUEST['send_error_report'] == true
23 || $_REQUEST['send_error_report'] == '1')
24 ) {
25 if ($_REQUEST['exception_type'] == 'php') {
26 /**
27 * Prevent infinite error submission.
28 * Happens in case error submissions fails.
29 * If reporting is done in some time interval,
30 * just clear them & clear json data too.
32 if (isset($_SESSION['prev_error_subm_time'])
33 && isset($_SESSION['error_subm_count'])
34 && $_SESSION['error_subm_count'] >= 3
35 && ($_SESSION['prev_error_subm_time']-time()) <= 3000
36 ) {
37 $_SESSION['error_subm_count'] = 0;
38 $_SESSION['prev_errors'] = '';
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\libraries\Message::notice($msg);
90 } else {
91 $msg = PMA\libraries\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();