2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handle error report submission
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'))
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')
30 if ($_POST['exception_type'] == 'php') {
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
42 $_SESSION['error_subm_count'] = 0;
43 $_SESSION['prev_errors'] = '';
44 $response->addJSON('_stopErrorReportLoop', '1');
46 $_SESSION['prev_error_subm_time'] = time();
47 $_SESSION['error_subm_count'] = (
48 (isset($_SESSION['error_subm_count']))
49 ?
($_SESSION['error_subm_count']+
1)
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)) {
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 */
68 if ((isset($_POST['automatic'])
69 && $_POST['automatic'] === "true")
70 ||
$GLOBALS['cfg']['SendErrorReports'] == 'always'
73 'An error has been detected and an error report has been '
74 . 'automatically submitted based on your settings.'
77 $msg = __('Thank you for submitting this report.');
81 'An error has been detected and an error report has been '
82 . 'generated but failed to be sent.'
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 */
94 $msg = Message
::notice($msg);
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);
104 $response->addJSON('_errSubmitMsg', $msg);
106 } elseif ($_POST['exception_type'] == 'php') {
107 $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
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']);
129 if ($_POST['exception_type'] == 'js') {
130 $response->addHTML($errorReport->getForm());
132 // clear previous errors & save new ones.
133 $GLOBALS['error_handler']->savePreviousErrors();