dolibarr  13.0.2
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 
24 if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
25 
26 require "../master.inc.php";
27 require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
29 require_once DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php";
30 
31 
32 dol_syslog("Call Dolibarr webservices interfaces");
33 
34 // Enable and test if module web services is enabled
35 if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
36 {
37  $langs->load("admin");
38  dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
39  print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
40  print $langs->trans("ToActivateModule");
41  exit;
42 }
43 
44 // Create the soap Object
45 $server = new nusoap_server();
46 $server->soap_defencoding = 'UTF-8';
47 $server->decode_utf8 = false;
48 $ns = 'http://www.dolibarr.org/ns/';
49 $server->configureWSDL('WebServicesDolibarrCategorie', $ns);
50 $server->wsdl->schemaTargetNamespace = $ns;
51 
52 
53 // Define WSDL content
54 $server->wsdl->addComplexType(
55  'authentication',
56  'complexType',
57  'struct',
58  'all',
59  '',
60  array(
61  'dolibarrkey' => array('name'=>'dolibarrkey', 'type'=>'xsd:string'),
62  'sourceapplication' => array('name'=>'sourceapplication', 'type'=>'xsd:string'),
63  'login' => array('name'=>'login', 'type'=>'xsd:string'),
64  'password' => array('name'=>'password', 'type'=>'xsd:string'),
65  'entity' => array('name'=>'entity', 'type'=>'xsd:string'),
66  )
67 );
68 
69 /*
70  * Une catégorie
71  */
72 $server->wsdl->addComplexType(
73  'categorie',
74  'complexType',
75  'struct',
76  'all',
77  '',
78  array(
79  'id' => array('name'=>'id', 'type'=>'xsd:string'),
80  'id_mere' => array('name'=>'id_mere', 'type'=>'xsd:string'),
81  'label' => array('name'=>'label', 'type'=>'xsd:string'),
82  'description' => array('name'=>'description', 'type'=>'xsd:string'),
83  'socid' => array('name'=>'socid', 'type'=>'xsd:string'),
84  'type' => array('name'=>'type', 'type'=>'xsd:string'),
85  'visible' => array('name'=>'visible', 'type'=>'xsd:string'),
86  'dir'=> array('name'=>'dir', 'type'=>'xsd:string'),
87  'photos' => array('name'=>'photos', 'type'=>'tns:PhotosArray'),
88  'filles' => array('name'=>'filles', 'type'=>'tns:FillesArray')
89  )
90 );
91 
92 /*
93  * Les catégories filles, sous tableau dez la catégorie
94  */
95 $server->wsdl->addComplexType(
96  'FillesArray',
97  'complexType',
98  'array',
99  '',
100  'SOAP-ENC:Array',
101  array(),
102  array(
103  array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:categorie[]')
104  ),
105  'tns:categorie'
106 );
107 
108  /*
109  * Image of product
110  */
111 $server->wsdl->addComplexType(
112  'PhotosArray',
113  'complexType',
114  'array',
115  'sequence',
116  '',
117  array(
118  'image' => array(
119  'name' => 'image',
120  'type' => 'tns:image',
121  'minOccurs' => '0',
122  'maxOccurs' => 'unbounded'
123  )
124  )
125 );
126 
127  /*
128  * An image
129  */
130 $server->wsdl->addComplexType(
131  'image',
132  'complexType',
133  'struct',
134  'all',
135  '',
136  array(
137  'photo' => array('name'=>'photo', 'type'=>'xsd:string'),
138  'photo_vignette' => array('name'=>'photo_vignette', 'type'=>'xsd:string'),
139  'imgWidth' => array('name'=>'imgWidth', 'type'=>'xsd:string'),
140  'imgHeight' => array('name'=>'imgHeight', 'type'=>'xsd:string')
141  )
142 );
143 
144 /*
145  * Retour
146  */
147 $server->wsdl->addComplexType(
148  'result',
149  'complexType',
150  'struct',
151  'all',
152  '',
153  array(
154  'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
155  'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
156  )
157 );
158 
159 // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
160 // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
161 // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
162 $styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
163 $styleuse = 'encoded'; // encoded/literal/literal wrapped
164 // Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
165 
166 
167 // Register WSDL
168 $server->register(
169  'getCategory',
170  // Entry values
171  array('authentication'=>'tns:authentication', 'id'=>'xsd:string'),
172  // Exit values
173  array('result'=>'tns:result', 'categorie'=>'tns:categorie'),
174  $ns,
175  $ns.'#getCategory',
176  $styledoc,
177  $styleuse,
178  'WS to get category'
179 );
180 
181 
189 function getCategory($authentication, $id)
190 {
191  global $db, $conf, $langs;
192 
193  $nbmax = 10;
194 
195  dol_syslog("Function: getCategory login=".$authentication['login']." id=".$id);
196 
197  if ($authentication['entity']) $conf->entity = $authentication['entity'];
198 
199  $objectresp = array();
200  $errorcode = ''; $errorlabel = '';
201  $error = 0;
202  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
203 
204  if (!$error && !$id)
205  {
206  $error++;
207  $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided.";
208  }
209 
210  if (!$error)
211  {
212  $fuser->getrights();
213 
214  $nbmax = 10;
215  if ($fuser->rights->categorie->lire)
216  {
217  $categorie = new Categorie($db);
218  $result = $categorie->fetch($id);
219  if ($result > 0)
220  {
221  $dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
222  $pdir = get_exdir($categorie->id, 2, 0, 0, $categorie, 'category').$categorie->id."/photos/";
223  $dir = $dir.'/'.$pdir;
224 
225  $cat = array(
226  'id' => $categorie->id,
227  'id_mere' => $categorie->id_mere,
228  'label' => $categorie->label,
229  'description' => $categorie->description,
230  'socid' => $categorie->socid,
231  //'visible'=>$categorie->visible,
232  'type' => $categorie->type,
233  'dir' => $pdir,
234  'photos' => $categorie->liste_photos($dir, $nbmax)
235  );
236 
237  $cats = $categorie->get_filles();
238  if (count($cats) > 0)
239  {
240  foreach ($cats as $fille)
241  {
242  $dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
243  $pdir = get_exdir($fille->id, 2, 0, 0, $categorie, 'category').$fille->id."/photos/";
244  $dir = $dir.'/'.$pdir;
245  $cat['filles'][] = array(
246  'id'=>$fille->id,
247  'id_mere' => $categorie->id_mere,
248  'label'=>$fille->label,
249  'description'=>$fille->description,
250  'socid'=>$fille->socid,
251  //'visible'=>$fille->visible,
252  'type'=>$fille->type,
253  'dir' => $pdir,
254  'photos' => $fille->liste_photos($dir, $nbmax)
255  );
256  }
257  }
258 
259  // Create
260  $objectresp = array(
261  'result'=>array('result_code'=>'OK', 'result_label'=>''),
262  'categorie'=> $cat
263  );
264  }
265  else {
266  $error++;
267  $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id;
268  }
269  }
270  else {
271  $error++;
272  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
273  }
274  }
275 
276  if ($error)
277  {
278  $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
279  }
280 
281  return $objectresp;
282 }
283 
284 // Return the results.
285 $server->service(file_get_contents("php://input"));
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition: ws.lib.php:35
getCategory($authentication, $id)
Get category infos and children.
Class to manage categories.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
print
Draft customers invoices.
Definition: index.php:89