2
// ensure this file is being included by a parent file
3
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
5
* @version $Id: result.class.php 160 2009-11-16 05:58:30Z soeren $
7
* @copyright soeren 2007
8
* @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
9
* @author The The QuiX project (http://quixplorer.sourceforge.net)
12
* The contents of this file are subject to the Mozilla Public License
13
* Version 1.1 (the "License"); you may not use this file except in
14
* compliance with the License. You may obtain a copy of the License at
15
* http://www.mozilla.org/MPL/
17
* Software distributed under the License is distributed on an "AS IS"
18
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
19
* License for the specific language governing rights and limitations
22
* Alternatively, the contents of this file may be used under the terms
23
* of the GNU General Public License Version 2 or later (the "GPL"), in
24
* which case the provisions of the GPL are applicable instead of
25
* those above. If you wish to allow use of your version of this file only
26
* under the terms of the GPL and not to allow others to use
27
* your version of this file under the MPL, indicate your decision by
28
* deleting the provisions above and replace them with the notice and
29
* other provisions required by the GPL. If you do not delete
30
* the provisions above, a recipient may use your version of this file
31
* under either the MPL or the GPL."
36
* Allows to handle errors and send results in JSON format
41
ext_Result::empty_errors();
42
ext_Result::empty_messages();
44
function add_message($message, $type='general') {
45
$_SESSION['ext_message'][$type][] = $message;
47
function empty_messages() {
48
$_SESSION['ext_message'] = array();
50
function count_messages() {
52
if( empty($_SESSION['ext_message'])) {
56
foreach( $_SESSION['ext_message'] as $type ) {
57
if( !empty( $type ) && is_array( $type )) {
58
$count += sizeof( $type );
63
function add_error($error, $type='general') {
64
$_SESSION['ext_error'][$type][] = $error;
66
function empty_errors() {
67
$_SESSION['ext_error'] = array();
69
function count_errors() {
70
if( empty($_SESSION['ext_error'])) {
74
foreach( @$_SESSION['ext_error'] as $type ) {
75
if( !empty( $type ) && is_array( $type )) {
76
$count += sizeof( $type );
81
function sendResult( $action, $success, $msg,$extra=array() ) { // show error-message
84
$success = (bool)$success;
85
if( $success && ext_Result::count_errors() > 0 ) {
87
foreach( @$_SESSION['ext_error'] as $type ) {
88
if( is_array( $type )) {
89
foreach( $type as $error ) {
90
$msg .= '<br />'.$error;
95
$result = array('action' => $action,
96
'message' => str_replace("'", "\\'", $msg ),
97
'error' => str_replace("'", "\\'", $msg ),//.print_r($_POST,true),
100
foreach( $extra as $key => $value ) {
101
$result[$key] = $value;
103
$classname = class_exists('ext_Json') ? 'ext_Json' : 'Services_JSON';
104
$json = new $classname();
105
$jresult = $json->encode($result);
106
if(strtolower(extGetParam($_POST,'requestType')) == 'xmlhttprequest') {
107
header("Content-type: text/html");
114
$msg .= " - ".$extra;
116
ext_Result::add_error( $msg );
118
if( empty( $_GET['error'] )) {
119
session_write_close();
120
extRedirect( make_link("show_error", $GLOBALS["dir"], null, null, null, null, '&error=1&extra='.urlencode( $extra )) );
123
show_header($GLOBALS["error_msg"]["error"]);
125
echo '<div class="quote">';
126
echo '<a href="#errors">'.ext_Result::count_errors() .' '.$GLOBALS["error_msg"]["error"].'</a>, ';
127
echo '<a href="#messages">'.ext_Result::count_messages() .' '.$GLOBALS["error_msg"]["message"].'</a><br />';
130
if( !empty( $_SESSION['ext_message'])) {
131
echo "<a href=\"".str_replace('&dir=', '&ignore=', make_link("list", '' ))."\">[ "
132
.$GLOBALS["error_msg"]["back"]." ]</a>";
134
echo "<div class=\"ext_message\"><a name=\"messages\"></a>
135
<h3>".$GLOBALS["error_msg"]["message"].":</strong>"."</h3>\n";
137
foreach ( $_SESSION['ext_message'] as $msgtype ) {
138
foreach ( $msgtype as $message ) {
139
echo $message ."\n<br/>";
141
echo '<br /><hr /><br />';
143
ext_Result::empty_messages();
145
if( !empty( $_REQUEST['extra'])) echo " - ".htmlspecialchars(urldecode($_REQUEST['extra']), ENT_QUOTES );
149
if( !empty( $_SESSION['ext_error'])) {
150
echo "<div class=\"ext_error\"><a name=\"errors\"></a>
151
<h3>".$GLOBALS["error_msg"]["error"].":</strong>"."</h3>\n";
153
foreach ( $_SESSION['ext_error'] as $errortype ) {
154
foreach ( $errortype as $error ) {
155
echo $error ."\n<br/>";
157
echo '<br /><hr /><br />';
159
ext_Result::empty_errors();
161
echo "<a href=\"".str_replace('&dir=', '&ignore=', make_link("list", '' ))."\">".$GLOBALS["error_msg"]["back"]."</a>";
162
if( !empty( $_REQUEST['extra'])) echo " - ".htmlspecialchars(urldecode($_REQUEST['extra']), ENT_QUOTES );
164
defined('EXPLORER_NOEXEC') or define('EXPLORER_NOEXEC', 1 );
168
//------------------------------------------------------------------------------