dolibarr 19.0.3
server_category.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012 JF FERRY <jfefe@aternatik.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24if (!defined('NOCSRFCHECK')) {
25 define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
26}
27if (!defined('NOTOKENRENEWAL')) {
28 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
29}
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
38}
39if (!defined("NOLOGIN")) {
40 define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
41}
42if (!defined("NOSESSION")) {
43 define("NOSESSION", '1');
44}
45
46require '../main.inc.php';
47require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
48require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
49require_once DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php";
50
51
52dol_syslog("Call Dolibarr webservices interfaces");
53
54// Enable and test if module web services is enabled
55if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
56 $langs->load("admin");
57 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
58 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
59 print $langs->trans("ToActivateModule");
60 exit;
61}
62
63// Create the soap Object
64$server = new nusoap_server();
65$server->soap_defencoding = 'UTF-8';
66$server->decode_utf8 = false;
67$ns = 'http://www.dolibarr.org/ns/';
68$server->configureWSDL('WebServicesDolibarrCategorie', $ns);
69$server->wsdl->schemaTargetNamespace = $ns;
70
71
72// Define WSDL content
73$server->wsdl->addComplexType(
74 'authentication',
75 'complexType',
76 'struct',
77 'all',
78 '',
79 array(
80 'dolibarrkey' => array('name'=>'dolibarrkey', 'type'=>'xsd:string'),
81 'sourceapplication' => array('name'=>'sourceapplication', 'type'=>'xsd:string'),
82 'login' => array('name'=>'login', 'type'=>'xsd:string'),
83 'password' => array('name'=>'password', 'type'=>'xsd:string'),
84 'entity' => array('name'=>'entity', 'type'=>'xsd:string'),
85 )
86);
87
88/*
89 * Une catégorie
90 */
91$server->wsdl->addComplexType(
92 'categorie',
93 'complexType',
94 'struct',
95 'all',
96 '',
97 array(
98 'id' => array('name'=>'id', 'type'=>'xsd:string'),
99 'id_mere' => array('name'=>'id_mere', 'type'=>'xsd:string'),
100 'label' => array('name'=>'label', 'type'=>'xsd:string'),
101 'description' => array('name'=>'description', 'type'=>'xsd:string'),
102 'socid' => array('name'=>'socid', 'type'=>'xsd:string'),
103 'type' => array('name'=>'type', 'type'=>'xsd:string'),
104 'visible' => array('name'=>'visible', 'type'=>'xsd:string'),
105 'dir'=> array('name'=>'dir', 'type'=>'xsd:string'),
106 'photos' => array('name'=>'photos', 'type'=>'tns:PhotosArray'),
107 'filles' => array('name'=>'filles', 'type'=>'tns:FillesArray')
108 )
109);
110
111/*
112 * Les catégories filles, sous tableau dez la catégorie
113 */
114$server->wsdl->addComplexType(
115 'FillesArray',
116 'complexType',
117 'array',
118 '',
119 'SOAP-ENC:Array',
120 array(),
121 array(
122 array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:categorie[]')
123 ),
124 'tns:categorie'
125);
126
127 /*
128 * Image of product
129 */
130$server->wsdl->addComplexType(
131 'PhotosArray',
132 'complexType',
133 'array',
134 'sequence',
135 '',
136 array(
137 'image' => array(
138 'name' => 'image',
139 'type' => 'tns:image',
140 'minOccurs' => '0',
141 'maxOccurs' => 'unbounded'
142 )
143 )
144);
145
146 /*
147 * An image
148 */
149$server->wsdl->addComplexType(
150 'image',
151 'complexType',
152 'struct',
153 'all',
154 '',
155 array(
156 'photo' => array('name'=>'photo', 'type'=>'xsd:string'),
157 'photo_vignette' => array('name'=>'photo_vignette', 'type'=>'xsd:string'),
158 'imgWidth' => array('name'=>'imgWidth', 'type'=>'xsd:string'),
159 'imgHeight' => array('name'=>'imgHeight', 'type'=>'xsd:string')
160 )
161);
162
163/*
164 * Retour
165 */
166$server->wsdl->addComplexType(
167 'result',
168 'complexType',
169 'struct',
170 'all',
171 '',
172 array(
173 'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
174 'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
175 )
176);
177
178// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
179// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
180// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
181$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
182$styleuse = 'encoded'; // encoded/literal/literal wrapped
183// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
184
185
186// Register WSDL
187$server->register(
188 'getCategory',
189 // Entry values
190 array('authentication'=>'tns:authentication', 'id'=>'xsd:string'),
191 // Exit values
192 array('result'=>'tns:result', 'categorie'=>'tns:categorie'),
193 $ns,
194 $ns.'#getCategory',
195 $styledoc,
196 $styleuse,
197 'WS to get category'
198);
199
200
208function getCategory($authentication, $id)
209{
210 global $db, $conf, $langs;
211
212 $nbmax = 10;
213
214 dol_syslog("Function: getCategory login=".$authentication['login']." id=".$id);
215
216 if ($authentication['entity']) {
217 $conf->entity = $authentication['entity'];
218 }
219
220 $objectresp = array();
221 $errorcode = '';
222 $errorlabel = '';
223 $error = 0;
224 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
225
226 if (!$error && !$id) {
227 $error++;
228 $errorcode = 'BAD_PARAMETERS';
229 $errorlabel = "Parameter id must be provided.";
230 }
231
232 if (!$error) {
233 $fuser->getrights();
234
235 $nbmax = 10;
236 if ($fuser->hasRight('categorie', 'lire')) {
237 $categorie = new Categorie($db);
238 $result = $categorie->fetch($id);
239 if ($result > 0) {
240 $dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
241 $pdir = get_exdir($categorie->id, 2, 0, 0, $categorie, 'category').$categorie->id."/photos/";
242 $dir = $dir.'/'.$pdir;
243
244 $cat = array(
245 'id' => $categorie->id,
246 'id_mere' => $categorie->id_mere,
247 'label' => $categorie->label,
248 'description' => $categorie->description,
249 'socid' => $categorie->socid,
250 //'visible'=>$categorie->visible,
251 'type' => $categorie->type,
252 'dir' => $pdir,
253 'photos' => $categorie->liste_photos($dir, $nbmax)
254 );
255
256 $cats = $categorie->get_filles();
257 if (count($cats) > 0) {
258 foreach ($cats as $fille) {
259 $dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
260 $pdir = get_exdir($fille->id, 2, 0, 0, $categorie, 'category').$fille->id."/photos/";
261 $dir = $dir.'/'.$pdir;
262 $cat['filles'][] = array(
263 'id'=>$fille->id,
264 'id_mere' => $categorie->id_mere,
265 'label'=>$fille->label,
266 'description'=>$fille->description,
267 'socid'=>$fille->socid,
268 //'visible'=>$fille->visible,
269 'type'=>$fille->type,
270 'dir' => $pdir,
271 'photos' => $fille->liste_photos($dir, $nbmax)
272 );
273 }
274 }
275
276 // Create
277 $objectresp = array(
278 'result'=>array('result_code'=>'OK', 'result_label'=>''),
279 'categorie'=> $cat
280 );
281 } else {
282 $error++;
283 $errorcode = 'NOT_FOUND';
284 $errorlabel = 'Object not found for id='.$id;
285 }
286 } else {
287 $error++;
288 $errorcode = 'PERMISSION_DENIED';
289 $errorlabel = 'User does not have permission for this request';
290 }
291 }
292
293 if ($error) {
294 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
295 }
296
297 return $objectresp;
298}
299
300// Return the results.
301$server->service(file_get_contents("php://input"));
Class to manage categories.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getCategory($authentication, $id)
Get category infos and children.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:35