24 if (!defined(
"NOCSRFCHECK")) {
25 define(
"NOCSRFCHECK",
'1');
28 require
'../master.inc.php';
29 require_once NUSOAP_PATH.
'/nusoap.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
37 dol_syslog(
"Call Dolibarr webservices interfaces");
42 if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
43 $langs->load(
"admin");
44 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
45 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
46 print $langs->trans(
"ToActivateModule");
51 $listofreferent = array(
53 'order' =>
'commande',
54 'invoice' =>
'facture',
55 'invoice_predefined' =>
'facture_rec',
56 'proposal_supplier' =>
'commande_fournisseur',
57 'order_supplier' =>
'commande_fournisseur',
58 'invoice_supplier' =>
'facture_fourn',
59 'contract' =>
'contrat',
60 'intervention' =>
'fichinter',
61 'trip' =>
'deplacement',
62 'expensereport' =>
'expensereport_det',
64 'agenda' =>
'actioncomm',
65 'project_task' =>
'projet_task',
69 $server =
new nusoap_server();
70 $server->soap_defencoding =
'UTF-8';
71 $server->decode_utf8 =
false;
72 $ns =
'http://www.dolibarr.org/ns/';
73 $server->configureWSDL(
'WebServicesDolibarrOther', $ns);
74 $server->wsdl->schemaTargetNamespace = $ns;
77 $server->wsdl->addComplexType(
84 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
85 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
86 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
87 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
88 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
93 $server->wsdl->addComplexType(
100 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
101 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
106 $server->wsdl->addComplexType(
113 'id' => array(
'name'=>
'id',
'type'=>
'xsd:int'),
114 'user' => array(
'name'=>
'user',
'type'=>
'xsd:int'),
118 $server->wsdl->addComplexType(
126 'name' =>
'elementsArray',
127 'type' =>
'tns:element',
129 'maxOccurs' =>
'unbounded'
134 $project_elements = array();
135 foreach ($listofreferent as $key => $label) {
136 $project_elements[$key] = array(
'name'=>$key,
'type'=>
'tns:elementsArray');
138 $server->wsdl->addComplexType(
148 $project_fields = array(
149 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
150 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
151 'label' => array(
'name'=>
'label',
'type'=>
'xsd:string'),
152 'thirdparty_id' => array(
'name'=>
'thirdparty_id',
'type'=>
'xsd:int'),
153 'public' => array(
'name'=>
'public',
'type'=>
'xsd:int'),
154 'status' => array(
'name'=>
'status',
'type'=>
'xsd:int'),
155 'date_start' => array(
'name'=>
'date_start',
'type'=>
'xsd:date'),
156 'date_end' => array(
'name'=>
'date_end',
'type'=>
'xsd:date'),
157 'budget' => array(
'name'=>
'budget',
'type'=>
'xsd:int'),
158 'description' => array(
'name'=>
'description',
'type'=>
'xsd:string'),
159 'elements' => array(
'name'=>
'elements',
'type'=>
'tns:elements')
162 $elementtype =
'project';
167 $extrafields->fetch_name_optionals_label($elementtype,
true);
168 $extrafield_array =
null;
169 if (is_array($extrafields) && count($extrafields) > 0) {
170 $extrafield_array = array();
172 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
173 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
175 $type = $extrafields->attributes[$elementtype][
'type'][$key];
176 if ($type ==
'date' || $type ==
'datetime') {
177 $type =
'xsd:dateTime';
179 $type =
'xsd:string';
181 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
184 if (is_array($extrafield_array)) {
185 $project_fields = array_merge($project_fields, $extrafield_array);
188 $server->wsdl->addComplexType(
201 $styleuse =
'encoded';
208 array(
'authentication'=>
'tns:authentication',
'project'=>
'tns:project'),
210 array(
'result'=>
'tns:result',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
212 $ns.
'#createProject',
215 'WS to create project'
222 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
224 array(
'result'=>
'tns:result',
'project'=>
'tns:project'),
244 dol_syslog(
"Function: createProject login=".$authentication[
'login']);
246 if ($authentication[
'entity']) {
247 $conf->entity = $authentication[
'entity'];
251 $objectresp = array();
252 $errorcode =
''; $errorlabel =
'';
256 if (empty($project[
'ref'])) {
257 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
264 if ($fuser->rights->projet->creer) {
266 $newobject->ref = $project[
'ref'];
267 $newobject->title = $project[
'label'];
268 $newobject->socid = $project[
'thirdparty_id'];
269 $newobject->public = $project[
'public'];
270 $newobject->statut = $project[
'status'];
271 $newobject->date_start =
dol_stringtotime($project[
'date_start'],
'dayrfc');
273 $newobject->budget_amount = $project[
'budget'];
274 $newobject->description = $project[
'description'];
276 $elementtype =
'project';
281 $extrafields->fetch_name_optionals_label($elementtype,
true);
282 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
283 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
284 $key =
'options_'.$key;
285 $newobject->array_options[$key] = $project[$key];
291 $result = $newobject->create($fuser);
292 if (!$error && $result > 0) {
294 $result = $newobject->add_contact($fuser->id,
'PROJECTLEADER',
'internal');
304 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
309 $errorlabel = $newobject->error;
313 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
318 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
336 dol_syslog(
"Function: getProject login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref);
338 if ($authentication[
'entity']) {
339 $conf->entity = $authentication[
'entity'];
343 $objectresp = array();
344 $errorcode =
''; $errorlabel =
'';
348 if (!$error && (($id && $ref))) {
350 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref can't be both provided. You must choose one or other but not both.";
356 if ($fuser->rights->projet->lire) {
358 $result = $project->fetch($id, $ref);
360 $project_result_fields = array(
361 'id' => $project->id,
362 'ref' => $project->ref,
363 'label' => $project->title,
364 'thirdparty_id' => $project->socid,
365 'public' => $project->public,
366 'status' => $project->statut,
367 'date_start' => $project->date_start ?
dol_print_date($project->date_start,
'dayrfc') :
'',
368 'date_end' => $project->date_end ?
dol_print_date($project->date_end,
'dayrfc') :
'',
369 'budget' => $project->budget_amount,
370 'description' => $project->description,
373 $elementtype =
'project';
377 $extrafields->fetch_name_optionals_label($elementtype,
true);
380 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
381 $project->fetch_optionals();
382 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
383 $project_result_fields = array_merge($project_result_fields, array(
'options_'.$key => $project->array_options[
'options_'.$key]));
388 global $listofreferent;
390 foreach ($listofreferent as $key => $tablename) {
391 $elements[$key] = array();
392 $element_array = $project->get_element_list($key, $tablename);
393 if (count($element_array) > 0 && is_array($element_array)) {
394 foreach ($element_array as $element) {
395 $tmp = explode(
'_', $element);
396 $idofelement = count($tmp) > 0 ? $tmp[0] :
"";
397 $idofelementuser = count($tmp) > 1 ? $tmp[1] :
"";
398 $elements[$key][] = array(
'id' => $idofelement,
'user' => $idofelementuser);
402 $project_result_fields[
'elements'] = $elements;
406 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
407 'project'=>$project_result_fields
411 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref;
415 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
420 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
427 $server->service(file_get_contents(
"php://input"));
Class to manage projects.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
createProject($authentication, $project)
Create project.
getProject($authentication, $id='', $ref='')
Get a project.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.