dolibarr 23.0.3
server_actioncomm.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 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 *
20 * Path to WSDL is: http://localhost/dolibarr/webservices/server_actioncomm.php?wsdl
21 */
22
28if (!defined('NOCSRFCHECK')) {
29 define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
30}
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
33}
34if (!defined('NOREQUIREMENU')) {
35 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
36}
37if (!defined('NOREQUIREHTML')) {
38 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
39}
40if (!defined('NOREQUIREAJAX')) {
41 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
42}
43if (!defined("NOLOGIN")) {
44 define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
45}
46if (!defined("NOSESSION")) {
47 define("NOSESSION", '1');
48}
49
50require '../main.inc.php';
51require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
52require_once DOL_DOCUMENT_ROOT."/core/lib/ws.lib.php";
53
54require_once DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php";
55require_once DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php";
56require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
62dol_syslog("Call ActionComm webservices interfaces");
63
64// Enable and test if module web services is enabled
65if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
66 $langs->load("admin");
67 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
68 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
69 print $langs->trans("ToActivateModule");
70 exit;
71}
72
73// Create the soap Object
74$server = new nusoap_server();
75$server->soap_defencoding = 'UTF-8';
76$server->decode_utf8 = false;
77$ns = 'http://www.dolibarr.org/ns/';
78$server->configureWSDL('WebServicesDolibarrActionComm', $ns);
79// @phan-suppress-next-line PhanUndeclaredProperty
80$server->wsdl->schemaTargetNamespace = $ns;
81
82
83// Define WSDL Authentication object
84$server->wsdl->addComplexType(
85 'authentication',
86 'complexType',
87 'struct',
88 'all',
89 '',
90 array(
91 'dolibarrkey' => array('name' => 'dolibarrkey', 'type' => 'xsd:string'),
92 'sourceapplication' => array('name' => 'sourceapplication', 'type' => 'xsd:string'),
93 'login' => array('name' => 'login', 'type' => 'xsd:string'),
94 'password' => array('name' => 'password', 'type' => 'xsd:string'),
95 'entity' => array('name' => 'entity', 'type' => 'xsd:string'),
96 )
97);
98
99// Define WSDL Return object
100$server->wsdl->addComplexType(
101 'result',
102 'complexType',
103 'struct',
104 'all',
105 '',
106 array(
107 'result_code' => array('name' => 'result_code', 'type' => 'xsd:string'),
108 'result_label' => array('name' => 'result_label', 'type' => 'xsd:string'),
109 )
110);
111
112
113$actioncomm_fields = array(
114 'id' => array('name' => 'id', 'type' => 'xsd:string'),
115 'ref' => array('name' => 'ref', 'type' => 'xsd:string'),
116 'ref_ext' => array('name' => 'ref_ext', 'type' => 'xsd:string'),
117 'type_id' => array('name' => 'type_id', 'type' => 'xsd:string'),
118 'type_code' => array('name' => 'type_code', 'type' => 'xsd:string'),
119 'type' => array('name' => 'type', 'type' => 'xsd:string'),
120 'label' => array('name' => 'label', 'type' => 'xsd:string'),
121 'datep' => array('name' => 'datep', 'type' => 'xsd:dateTime'),
122 'datef' => array('name' => 'datef', 'type' => 'xsd:dateTime'),
123 'datec' => array('name' => 'datec', 'type' => 'xsd:dateTime'),
124 'datem' => array('name' => 'datem', 'type' => 'xsd:dateTime'),
125 'note' => array('name' => 'note', 'type' => 'xsd:string'),
126 'percentage' => array('name' => 'percentage', 'type' => 'xsd:string'),
127 'author' => array('name' => 'author', 'type' => 'xsd:string'),
128 'usermod' => array('name' => 'usermod', 'type' => 'xsd:string'),
129 'userownerid' => array('name' => 'userownerid', 'type' => 'xsd:string'),
130 'priority' => array('name' => 'priority', 'type' => 'xsd:string'),
131 'fulldayevent' => array('name' => 'fulldayevent', 'type' => 'xsd:string'),
132 'location' => array('name' => 'location', 'type' => 'xsd:string'),
133 'socid' => array('name' => 'socid', 'type' => 'xsd:string'),
134 'contactid' => array('name' => 'contactid', 'type' => 'xsd:string'),
135 'projectid' => array('name' => 'projectid', 'type' => 'xsd:string'),
136 'fk_element' => array('name' => 'fk_element', 'type' => 'xsd:string'),
137 'elementtype' => array('name' => 'elementtype', 'type' => 'xsd:string'));
138
139$elementtype = 'actioncomm';
140
141//Retrieve all extrafield for actioncomm
142// fetch optionals attributes and labels
143$extrafields = new ExtraFields($db);
144$extrafields->fetch_name_optionals_label($elementtype, true);
145$extrafield_array = null;
146if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype]['count'] > 0) {
147 $extrafield_array = array();
148}
149if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
150 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
151 $type = $extrafields->attributes[$elementtype]['type'][$key];
152 if ($type == 'date' || $type == 'datetime') {
153 $type = 'xsd:dateTime';
154 } else {
155 $type = 'xsd:string';
156 }
157
158 $extrafield_array['options_'.$key] = array('name' => 'options_'.$key, 'type' => $type);
159 }
160}
161if (is_array($extrafield_array)) {
162 $actioncomm_fields = array_merge($actioncomm_fields, $extrafield_array);
163}
164
165// Define other specific objects
166$server->wsdl->addComplexType(
167 'actioncomm',
168 'complexType',
169 'struct',
170 'all',
171 '',
172 $actioncomm_fields
173);
174
175
176$server->wsdl->addComplexType(
177 'actioncommtype',
178 'complexType',
179 'array',
180 'sequence',
181 '',
182 array(
183 'code' => array('name' => 'code', 'type' => 'xsd:string'),
184 'libelle' => array('name' => 'libelle', 'type' => 'xsd:string')
185 )
186);
187
188$server->wsdl->addComplexType(
189 'actioncommtypes',
190 'complexType',
191 'array',
192 'sequence',
193 '',
194 array(
195 'actioncommtype' => array(
196 'name' => 'actioncommtype',
197 'type' => 'tns:actioncommtype',
198 'minOccurs' => '0',
199 'maxOccurs' => 'unbounded'
200 )
201 )
202);
203
204
205// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
206// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
207// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
208$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
209$styleuse = 'encoded'; // encoded/literal/literal wrapped
210// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
211
212
213// Register WSDL
214$server->register(
215 'getListActionCommType',
216 // Entry values
217 array('authentication' => 'tns:authentication'),
218 // Exit values
219 array('result' => 'tns:result', 'actioncommtypes' => 'tns:actioncommtypes'),
220 $ns,
221 $ns.'#getListActionCommType',
222 $styledoc,
223 $styleuse,
224 'WS to get actioncommType'
225);
226
227// Register WSDL
228$server->register(
229 'getActionComm',
230 // Entry values
231 array('authentication' => 'tns:authentication', 'id' => 'xsd:string'),
232 // Exit values
233 array('result' => 'tns:result', 'actioncomm' => 'tns:actioncomm'),
234 $ns,
235 $ns.'#getActionComm',
236 $styledoc,
237 $styleuse,
238 'WS to get actioncomm'
239);
240
241// Register WSDL
242$server->register(
243 'createActionComm',
244 // Entry values
245 array('authentication' => 'tns:authentication', 'actioncomm' => 'tns:actioncomm'),
246 // Exit values
247 array('result' => 'tns:result', 'id' => 'xsd:string'),
248 $ns,
249 $ns.'#createActionComm',
250 $styledoc,
251 $styleuse,
252 'WS to create a actioncomm'
253);
254
255// Register WSDL
256$server->register(
257 'updateActionComm',
258 // Entry values
259 array('authentication' => 'tns:authentication', 'actioncomm' => 'tns:actioncomm'),
260 // Exit values
261 array('result' => 'tns:result', 'id' => 'xsd:string'),
262 $ns,
263 $ns.'#updateActionComm',
264 $styledoc,
265 $styleuse,
266 'WS to update a actioncomm'
267);
268
269
270
271
279function getActionComm($authentication, $id)
280{
281 global $db, $conf, $langs;
282
283 dol_syslog("Function: getActionComm login=".$authentication['login']." id=".$id);
284
285 if ($authentication['entity']) {
286 $conf->entity = $authentication['entity'];
287 }
288
289 // Init and check authentication
290 $objectresp = array();
291 $errorcode = '';
292 $errorlabel = '';
293 $error = 0;
294 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
295 // Check parameters
296 if ($error || (!$id)) {
297 $error++;
298 $errorcode = 'BAD_PARAMETERS';
299 $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
300 }
301
302 if (!$error) {
303 $fuser->loadRights();
304
305 if ($fuser->hasRight('agenda', 'allactions', 'read')) {
306 $actioncomm = new ActionComm($db);
307 $result = $actioncomm->fetch($id);
308 if ($result > 0) {
309 $actioncomm_result_fields = array(
310 'id' => $actioncomm->id,
311 'ref' => $actioncomm->ref,
312 'ref_ext' => $actioncomm->ref_ext,
313 'type_id' => $actioncomm->type_id,
314 'type_code' => $actioncomm->type_code,
315 'type' => $actioncomm->type,
316 'label' => $actioncomm->label,
317 'datep' => dol_print_date($actioncomm->datep, 'dayhourrfc'),
318 'datef' => dol_print_date($actioncomm->datef, 'dayhourrfc'),
319 'datec' => dol_print_date($actioncomm->datec, 'dayhourrfc'),
320 'datem' => dol_print_date($actioncomm->datem, 'dayhourrfc'),
321 'note' => $actioncomm->note_private,
322 'percentage' => $actioncomm->percentage,
323 'author' => $actioncomm->authorid,
324 'usermod' => $actioncomm->usermodid,
325 'userownerid' => $actioncomm->userownerid,
326 'priority' => $actioncomm->priority,
327 'fulldayevent' => $actioncomm->fulldayevent,
328 'location' => $actioncomm->location,
329 'socid' => $actioncomm->socid,
330 'contactid' => $actioncomm->contact_id,
331 'projectid' => $actioncomm->fk_project,
332 'fk_element' => $actioncomm->fk_element,
333 'elementtype' => $actioncomm->elementtype
334 );
335
336 $elementtype = 'actioncomm';
337
338 // Retrieve all extrafield for actioncomm
339 // fetch optionals attributes and labels
340 $extrafields = new ExtraFields($db);
341 $extrafields->fetch_name_optionals_label($elementtype, true);
342 //Get extrafield values
343 $actioncomm->fetch_optionals();
344
345 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
346 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
347 $actioncomm_result_fields = array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key]));
348 }
349 }
350
351 // Create
352 $objectresp = array(
353 'result' => array('result_code' => 'OK', 'result_label' => ''),
354 'actioncomm' => $actioncomm_result_fields);
355 } else {
356 $error++;
357 $errorcode = 'NOT_FOUND';
358 $errorlabel = 'Object not found for id='.$id;
359 }
360 } else {
361 $error++;
362 $errorcode = 'PERMISSION_DENIED';
363 $errorlabel = 'User does not have permission for this request';
364 }
365 }
366
367 if ($error) {
368 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
369 }
370
371 return $objectresp;
372}
373
374
381function getListActionCommType($authentication)
382{
383 global $db, $conf, $langs;
384
385 dol_syslog("Function: getListActionCommType login=".$authentication['login']);
386
387 if ($authentication['entity']) {
388 $conf->entity = $authentication['entity'];
389 }
390
391 // Init and check authentication
392 $objectresp = array();
393 $errorcode = '';
394 $errorlabel = '';
395 $error = 0;
396 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
397
398 if (!$error) {
399 $fuser->loadRights();
400
401 if ($fuser->hasRight('agenda', 'myactions', 'read')) {
402 $cactioncomm = new CActionComm($db);
403 $result = $cactioncomm->liste_array('', 'code');
404 if ($result > 0) {
405 $resultarray = array();
406 foreach ($cactioncomm->liste_array as $code => $libeller) {
407 $resultarray[] = array('code' => $code, 'libelle' => $libeller);
408 }
409
410 $objectresp = array(
411 'result' => array('result_code' => 'OK', 'result_label' => ''),
412 'actioncommtypes' => $resultarray);
413 } else {
414 $error++;
415 $errorcode = 'NOT_FOUND';
416 $errorlabel = 'Failed to execute liste_array';
417 }
418 } else {
419 $error++;
420 $errorcode = 'PERMISSION_DENIED';
421 $errorlabel = 'User does not have permission for this request';
422 }
423 }
424
425 if ($error) {
426 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
427 }
428
429 return $objectresp;
430}
431
432
440function createActionComm($authentication, $actioncomm)
441{
442 global $db, $conf;
443
444 $now = dol_now();
445
446 dol_syslog("Function: createActionComm login=".$authentication['login']);
447
448 if ($authentication['entity']) {
449 $conf->entity = $authentication['entity'];
450 }
451
452 // Init and check authentication
453 $objectresp = array();
454 $errorcode = '';
455 $errorlabel = '';
456 $error = 0;
457 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
458
459 if (!$error) {
460 $newobject = new ActionComm($db);
461
462 $newobject->datep = $actioncomm['datep'];
463 $newobject->datef = $actioncomm['datef'];
464 $newobject->type_code = $actioncomm['type_code'];
465 $newobject->socid = (int) $actioncomm['socid'];
466 $newobject->fk_project = (int) $actioncomm['projectid'];
467 $newobject->note = $actioncomm['note'];
468 $newobject->note_private = $actioncomm['note'];
469 $newobject->contact_id = (int) $actioncomm['contactid'];
470 $newobject->userownerid = (int) $actioncomm['userownerid'];
471 $newobject->label = $actioncomm['label'];
472 $newobject->percentage = (int) $actioncomm['percentage'];
473 $newobject->priority = (int) $actioncomm['priority'];
474 $newobject->fulldayevent = (int) $actioncomm['fulldayevent'];
475 $newobject->location = $actioncomm['location'];
476 $newobject->fk_element = (int) $actioncomm['fk_element'];
477 $newobject->elementtype = $actioncomm['elementtype'];
478
479 $elementtype = 'actioncomm';
480
481 //Retrieve all extrafield for actioncomm
482 // fetch optionals attributes and labels
483 $extrafields = new ExtraFields($db);
484 $extrafields->fetch_name_optionals_label($elementtype, true);
485 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
486 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
487 $key = 'options_'.$key;
488 $newobject->array_options[$key] = $actioncomm[$key];
489 }
490 }
491
492 $db->begin();
493
494 $result = $newobject->create($fuser);
495 if ($result <= 0) {
496 $error++;
497 }
498
499 if (!$error) {
500 $db->commit();
501 $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id);
502 } else {
503 $db->rollback();
504 $error++;
505 $errorcode = 'KO';
506 $errorlabel = $newobject->error;
507 }
508 }
509
510 if ($error) {
511 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
512 }
513
514 return $objectresp;
515}
516
524function updateActionComm($authentication, $actioncomm)
525{
526 global $db, $conf;
527
528 $now = dol_now();
529
530 dol_syslog("Function: updateActionComm login=".$authentication['login']);
531
532 if ($authentication['entity']) {
533 $conf->entity = $authentication['entity'];
534 }
535
536 // Init and check authentication
537 $objectresp = array();
538 $errorcode = '';
539 $errorlabel = '';
540 $error = 0;
541 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
542 // Check parameters
543 if (empty($actioncomm['id'])) {
544 $error++;
545 $errorcode = 'KO';
546 $errorlabel = "Actioncomm id is mandatory.";
547 }
548
549 if (!$error) {
550 $objectfound = false;
551
552 $object = new ActionComm($db);
553 $result = $object->fetch((int) $actioncomm['id']);
554
555 if (!empty($object->id)) {
556 $objectfound = true;
557
558 $object->datep = $actioncomm['datep'];
559 $object->datef = $actioncomm['datef'];
560 $object->type_code = $actioncomm['type_code'];
561 $object->socid = (int) $actioncomm['socid'];
562 $object->contact_id = (int) $actioncomm['contactid'];
563 $object->fk_project = (int) $actioncomm['projectid'];
564 $object->note = $actioncomm['note'];
565 $object->userownerid = (int) $actioncomm['userownerid'];
566 $object->label = $actioncomm['label'];
567 $object->percentage = (int) $actioncomm['percentage'];
568 $object->priority = (int) $actioncomm['priority'];
569 $object->fulldayevent = (int) $actioncomm['fulldayevent'];
570 $object->location = $actioncomm['location'];
571 $object->fk_element = (int) $actioncomm['fk_element'];
572 $object->elementtype = $actioncomm['elementtype'];
573
574 $elementtype = 'actioncomm';
575
576 //Retrieve all extrafield for actioncomm
577 // fetch optionals attributes and labels
578 $extrafields = new ExtraFields($db);
579 $extrafields->fetch_name_optionals_label($elementtype, true);
580 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
581 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
582 $key = 'options_'.$key;
583 $object->array_options[$key] = $actioncomm[$key];
584 }
585 }
586
587 $db->begin();
588
589 $result = $object->update($fuser);
590 if ($result <= 0) {
591 $error++;
592 }
593 }
594 '@phan-var-force array{id:string} $actioncomm';
595
596 if ((!$error) && ($objectfound)) {
597 $db->commit();
598 $objectresp = array(
599 'result' => array('result_code' => 'OK', 'result_label' => ''),
600 'id' => $object->id
601 );
602 } elseif ($objectfound) {
603 $db->rollback();
604 $error++;
605 $errorcode = 'KO';
606 $errorlabel = $object->error;
607 } else {
608 $error++;
609 $errorcode = 'NOT_FOUND';
610 $errorlabel = 'Actioncomm id='.$actioncomm['id'].' cannot be found';
611 }
612 }
613
614 if ($error) {
615 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
616 }
617
618 return $objectresp;
619}
620
621// Return the results.
622$server->service(file_get_contents("php://input"));
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage standard extra fields.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
createActionComm($authentication, $actioncomm)
Create ActionComm.
getListActionCommType($authentication)
Get getListActionCommType.
getActionComm($authentication, $id)
Get ActionComm.
updateActionComm($authentication, $actioncomm)
Create ActionComm.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:37