Ticket #336: xtc_db_error.inc.php

File xtc_db_error.inc.php, 3.2 KB (added by Torsten Riemer, 11 years ago)

xtc_db_error.inc.php

Line 
1<?php
2/* -----------------------------------------------------------------------------------------
3 $Id: xtc_db_error.inc.php 5008 2013-07-04 12:37:12Z GTB $
4
5 modified eCommerce Shopsoftware
6 http://www.modified-shop.org
7
8 Copyright (c) 2009 - 2013 [www.modified-shop.org]
9 -----------------------------------------------------------------------------------------
10 based on:
11 (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
12 (c) 2002-2003 osCommerce(database.php,v 1.19 2003/03/22); www.oscommerce.com
13 (c) 2003 nextcommerce (xtc_db_error.inc.php,v 1.4 2003/08/19); www.nextcommerce.org
14 (c) 2006 XT-Commerce (xtc_db_error.inc.php 899 2005-04-29)
15
16 Released under the GNU General Public License
17 ---------------------------------------------------------------------------------------*/
18
19 function xtc_db_error($query, $errno, $error) {
20
21 // Deliver 503 Error on database error (so crawlers won't index the error page)
22 if (!defined('DIR_FS_ADMIN')) {
23 header("HTTP/1.1 503 Service Temporarily Unavailable");
24 header("Status: 503 Service Temporarily Unavailable");
25 header("Connection: Close");
26 }
27
28 // Send an email to the shop owner if a sql error occurs
29 if (defined('EMAIL_SQL_ERRORS') && EMAIL_SQL_ERRORS == 'true') {
30 if (defined('RUN_MODE_ADMIN')) {
31 // PHPMailer
32 require_once (DIR_FS_EXTERNAL.'phpmailer/class.phpmailer.php');
33 require_once (DIR_FS_INC.'xtc_php_mail.inc.php');
34 }
35 $subject = 'DATA BASE ERROR AT - ' . STORE_NAME;
36 $message = '<font color="#000000"><strong>' . $errno . ' - ' . $error . '<br /><br />' . $query . '<br /><br />Request URL: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'<br /><br /><small><font color="#ff0000">[XT SQL Error]</font></small><br /><br /></strong></font>';
37 xtc_php_mail(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, '', '', STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, '', '', $subject, nl2br($message), $message);
38 }
39
40 // show the full sql error + full query only to logged-in admins or error_reporting() != 0
41 if (isset($_SESSION['customers_status']['customers_status']) && $_SESSION['customers_status']['customers_status'] == '0' || error_reporting() != 0) {
42 die('<font color="#000000"><strong>' . $errno . ' - ' . $error . '<br /><br />' . $query . '<br /><br /><small><font color="#ff0000">[MOD SQL Error]</font></small><br /><br /></strong></font>');
43 } else {
44 die('<font color="#ff0000"><strong>Es ist ein Fehler aufgetreten!<br />There was an error!<br />Il y avait une erreur!</strong></font>');
45 }
46
47 //and display an info message for the shop customer and redirect him
48 echo '<p>'.ERROR_SQL_DB_QUERY.'</p>';
49 if ($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] != $_SERVER['HTTP_HOST']) {
50 $redirect_time = 5; // in seconds
51 echo '<p>'.sprintf(ERROR_SQL_DB_QUERY_REDIRECT, $redirect_time).'</p>';
52 echo '<script language="javascript">';
53 $redirect_time = $redirect_time * 1000; // convert to milliseconds for javascript redirect
54 echo 'setTimeout(\'location.href="http://' . $_SERVER['HTTP_HOST'] . '"\','.$redirect_time.');';
55 echo '</script>';
56 }
57 exit();
58 }
59?>