dolibarr  7.0.0-beta
basexml.php
1 <?php
2 /*
3  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4  * Copyright (C) 2003-2010 Frederico Caldeira Knabben
5  *
6  * == BEGIN LICENSE ==
7  *
8  * Licensed under the terms of any of the following licenses at your
9  * choice:
10  *
11  * - GNU General Public License Version 2 or later (the "GPL")
12  * http://www.gnu.org/licenses/gpl.html
13  *
14  * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15  * http://www.gnu.org/licenses/lgpl.html
16  *
17  * - Mozilla Public License Version 1.1 or later (the "MPL")
18  * http://www.mozilla.org/MPL/MPL-1.1.html
19  *
20  * == END LICENSE ==
21  *
22  * These functions define the base of the XML response sent by the PHP
23  * connector.
24  */
25 
31 function SetXmlHeaders()
32 {
33  ob_end_clean();
34 
35  // Prevent the browser from caching the result.
36  // Date in the past
37  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
38  // always modified
39  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
40  // HTTP/1.1
41  header('Cache-Control: no-store, no-cache, must-revalidate');
42  header('Cache-Control: post-check=0, pre-check=0', false);
43  // HTTP/1.0
44  header('Pragma: no-cache');
45 
46  // Set the response format.
47  header('Content-Type: text/xml; charset=utf-8');
48 }
49 
58 function CreateXmlHeader( $command, $resourceType, $currentFolder )
59 {
60  SetXmlHeaders();
61 
62  // Create the XML document header.
63  echo '<?xml version="1.0" encoding="utf-8" ?>' ;
64 
65  // Create the main "Connector" node.
66  echo '<Connector command="' . $command . '" resourceType="' . $resourceType . '">' ;
67 
68  // Add the current folder node.
69  echo '<CurrentFolder path="' . ConvertToXmlAttribute($currentFolder) . '" url="' . ConvertToXmlAttribute(GetUrlFromPath($resourceType, $currentFolder, $command)) . '" />' ;
70 
71  $GLOBALS['HeaderSent'] = true ;
72 }
73 
79 function CreateXmlFooter()
80 {
81  echo '</Connector>' ;
82 }
83 
91 function SendError($number, $text)
92 {
93  if ( $_GET['Command'] == 'FileUpload' )
94  SendUploadResults($number, "", "", $text);
95 
96  if ( isset( $GLOBALS['HeaderSent'] ) && $GLOBALS['HeaderSent'] )
97  {
98  SendErrorNode($number, $text);
99  CreateXmlFooter();
100  }
101  else
102  {
103  SetXmlHeaders();
104 
105  dol_syslog('Error: '.$number.' '.$text, LOG_ERR);
106 
107  // Create the XML document header
108  echo '<?xml version="1.0" encoding="utf-8" ?>' ;
109 
110  echo '<Connector>' ;
111 
112  SendErrorNode($number, $text);
113 
114  echo '</Connector>' ;
115  }
116  exit ;
117 }
118 
126 function SendErrorNode($number, $text)
127 {
128  if ($text)
129  echo '<Error number="' . $number . '" text="' . htmlspecialchars($text) . '" />' ;
130  else
131  echo '<Error number="' . $number . '" />' ;
132 }
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.