websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 149 (differences)
Author: xbright
Log message: * Added PHPXMLRPC
* Edited the way to send notifications : don't use class.jabber.php, send a request to a bot
Change revision:
<?php
# ***** BEGIN LICENSE BLOCK *****
#
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2008 CodingTeam (See AUTHORS and THANKS for details)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, version 3 only.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ***** END LICENSE BLOCK *****
 
/**
 * @file
 * This file contains the ErrorHandler class
 *
 * Handle all PHP and CodingTeam errors, show and exit.
 */
 
 
/**
 * ErrorHandler class
 */
class ErrorHandler
{
    public $lang, $baseurl, $basedir;
 
    function __construct ($lang, $baseurl, $basedir)
    {
        $this->lang = $lang;
        $this->baseurl = $baseurl;
        $this->basedir = $basedir;
        
        if ($this->debug == 'TRUE')
            $this->debug = TRUE;
        else
            $this->debug = FALSE;
    }
 
 
    /**
     * Load the view
     *
     * Generate a pretty textarea with optional Javascript content.
     * @param $error
     *   The error message.
     * @param $status
     *   The error status.
     * @param $http (optional)
     *   HTTP Headers to send.
     */
    function displayError ($error, $status, $http='')
    {
        if (!empty($http))
            Header('HTTP/1.0 '.$http);
 
        // Error status
        if ($status == 0)
            $erstat = _('Banal');
        elseif ($status == 1)
            $erstat = _('Important');
        elseif ($status == 2)
            $erstat = _('Critical');
        elseif ($status == 3)
            $erstat = _('Code error');
        else
            exit('Error.');
 
        $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml" lang="{tpl:lang}" xml:lang="{tpl:lang}">
                <head>
                    <base href="http://codingteam.net/" />
                    <title>'._('An error has occured').' - CodingTeam</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <link href="{tpl:cssdir}default.css" rel="stylesheet" type="text/css" />
                    <link href="{tpl:logosimages}ct_cube.ico" rel="shortcut icon" />
                </head>
                <body>
                    <div id="container">
                        <div id="content">
                            <h1>'._('An error has occured.').'</h1>
                            <p>&nbsp;</p>
                            <div class="error-{erstat}">{error}</div>
                            <p>&nbsp;</p>
                            {text}
                        </div>
                    </div>
                </body>
                </html>';
 
        // Globals
        $temp['tpl:lang'] = $this->lang;
        $temp['tpl:baseurl'] = $this->baseurl;
        $temp['tpl:cssdir'] = 'inc/templates/';
        $temp['tpl:logosimages'] = 'public/images/logos/';
        $temp['erstat'] = $status;
 
        // Error
        if ($status == 3)
        {
            switch ($error[0])
            {
                case 1:
                    $errmsg = 'E_ERROR';
                    break;
                case 2:
                    $errmsg = 'E_WARNING';
                    break;
                case 4:
                    $errmsg = 'E_PARSE';
                    break;
                case 8:
                    $errmsg = 'E_NOTICE';
                    break;
                case 2048:
                    $errmsg = 'E_STRICT';
                    break;
                default:
                    $errmsg = 'E_UNKNOWN';
            }
        
            $temp['error'] = _('An error occured.').'<br />'.$error[1].' ('.$error[0].' - '.$errmsg.')<br />'.sprintf(_('In: %1s at line %2s'), $error[2], $error[3]);
        }
        else
            $temp['error'] = $error;
 
        if ($status == 0)
            $temp['text'] = '<a href="'.$baseurl.'">'._('Go to the index').'</a>';
        else
        {
            ob_start();
                print_r($error[4]);
            $datas = ob_get_clean();
 
            $temp['text'] = '<table style="width: 100%;">
                             <tr><td>'._('Bug status:').'</td>
                                 <td><strong>'.$erstat.'</strong></td></tr>
                             <tr><td style="background: #f0f0f0;">'._('Affects:').'</td>
                                 <td style="background: #f0f0f0;"><strong><a href="http://'.$_SERVER['SERVER_NAME'].'">'.$_SERVER['SERVER_NAME'].'</a></strong></td></tr>
                             <tr><td>'._('CodingTeam version:').'</td>
                                 <td><strong>'.file_get_contents($this->basedir.'/VERSION').'</strong></td></tr>
                             <tr><td style="width: 150px;background: #f0f0f0;">'._('Server identification:').'</td>
                                 <td style="background: #f0f0f0;">'.str_replace('address', 'strong', $_SERVER['SERVER_SIGNATURE']).'</td></tr>
                             <tr><td>'._('Date/time:').'</td>
                                 <td>'.date('Y-m-d H:i:s').'</td></tr>
                          </table>
                          <p>&nbsp;</p>
                          <p>'._('What to do if you can reproduce this bug.').'</p>
                          <div class="error-"><ul>
                              <li class="li"><strong>'._('Contact your server admin').'</strong><br />
                              '._('It is the first thing to do when you see a bug on your forge.').'</li>
                              <li class="li"><strong>'._('Report this bug to upstream').'</strong><br />
                              '.sprintf(_('You can send all datas on this page to the CodingTeam bug tracker at this page: %s.'), '<a href="http://www.codingteam.net/project/codingteam/bugs">http://www.codingteam.net/project/codingteam/bugs</a>').'<br />
                              '._('Be careful not to transmit private data! Also, be sure that this bug concerns only the CodingTeam development team.').'</li>
                          </ul></div>';
        }
 
        // Parse the template
        foreach ($temp as $key => $value)
        {
            $search[] = '{'.$key.'}';
            $replace[] = $value;
        }
        $output = str_replace($search, $replace, $html);
        
        echo $output;
        exit();
    }
}
?>