dolibarr  16.0.5
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  * https://www.gnu.org/licenses/gpl.html
13  *
14  * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15  * https://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 
97  if (isset($GLOBALS['HeaderSent']) && $GLOBALS['HeaderSent']) {
98  SendErrorNode($number, $text);
99  CreateXmlFooter();
100  } else {
101  SetXmlHeaders();
102 
103  dol_syslog('Error: '.$number.' '.$text, LOG_ERR);
104 
105  // Create the XML document header
106  echo '<?xml version="1.0" encoding="utf-8" ?>';
107 
108  echo '<Connector>';
109 
110  SendErrorNode($number, $text);
111 
112  echo '</Connector>';
113  }
114  exit;
115 }
116 
124 function SendErrorNode($number, $text)
125 {
126  if ($text) {
127  echo '<Error number="'.$number.'" text="'.htmlspecialchars($text).'" />';
128  } else {
129  echo '<Error number="'.$number.'" />';
130  }
131 }
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603