2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handle error report submission
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'))
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')
24 if ($_REQUEST['exception_type'] == 'php') {
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
36 $_SESSION['error_subm_count'] = 0;
37 $_SESSION['prev_errors'] = '';
38 $response = PMA_Response
::getInstance();
39 $response->addJSON('_stopErrorReportLoop', '1');
41 $_SESSION['prev_error_subm_time'] = time();
42 $_SESSION['error_subm_count'] = (
43 (isset($_SESSION['error_subm_count']))
44 ?
($_SESSION['error_subm_count']+
1)
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) {
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 */
63 if ((isset($_REQUEST['automatic'])
64 && $_REQUEST['automatic'] === "true")
65 ||
$GLOBALS['cfg']['SendErrorReports'] == 'always'
68 'An error has been detected and an error report has been '
69 . 'automatically submitted based on your settings.'
72 $msg = __('Thank you for submitting this report.');
76 'An error has been detected and an error report has been '
77 . 'generated but failed to be sent.'
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 */
89 $msg = PMA_Message
::notice($msg);
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);
99 $response->addJSON('_errSubmitMsg', $msg);
101 } elseif ($_REQUEST['exception_type'] == 'php') {
102 $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
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']);
123 if ($_REQUEST['exception_type'] == 'js') {
124 $response->addHTML(PMA_getErrorReportForm());
126 // clear previous errors & save new ones.
127 $GLOBALS['error_handler']->savePreviousErrors();