dolibarr 20.0.0
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 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';
57
58
59dol_syslog("Call ActionComm webservices interfaces");
60
61// Enable and test if module web services is enabled
62if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
63 $langs->load("admin");
64 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
65 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
66 print $langs->trans("ToActivateModule");
67 exit;
68}
69
70// Create the soap Object
71$server = new nusoap_server();
72$server->soap_defencoding = 'UTF-8';
73$server->decode_utf8 = false;
74$ns = 'http://www.dolibarr.org/ns/';
75$server->configureWSDL('WebServicesDolibarrActionComm', $ns);
76$server->wsdl->schemaTargetNamespace = $ns;
77
78
79// Define WSDL Authentication object
80$server->wsdl->addComplexType(
81 'authentication',
82 'complexType',
83 'struct',
84 'all',
85 '',
86 array(
87 'dolibarrkey' => array('name' => 'dolibarrkey', 'type' => 'xsd:string'),
88 'sourceapplication' => array('name' => 'sourceapplication', 'type' => 'xsd:string'),
89 'login' => array('name' => 'login', 'type' => 'xsd:string'),
90 'password' => array('name' => 'password', 'type' => 'xsd:string'),
91 'entity' => array('name' => 'entity', 'type' => 'xsd:string'),
92 )
93);
94
95// Define WSDL Return object
96$server->wsdl->addComplexType(
97 'result',
98 'complexType',
99 'struct',
100 'all',
101 '',
102 array(
103 'result_code' => array('name' => 'result_code', 'type' => 'xsd:string'),
104 'result_label' => array('name' => 'result_label', 'type' => 'xsd:string'),
105 )
106);
107
108
109$actioncomm_fields = array(
110 'id' => array('name' => 'id', 'type' => 'xsd:string'),
111 'ref' => array('name' => 'ref', 'type' => 'xsd:string'),
112 'ref_ext' => array('name' => 'ref_ext', 'type' => 'xsd:string'),
113 'type_id' => array('name' => 'type_id', 'type' => 'xsd:string'),
114 'type_code' => array('name' => 'type_code', 'type' => 'xsd:string'),
115 'type' => array('name' => 'type', 'type' => 'xsd:string'),
116 'label' => array('name' => 'label', 'type' => 'xsd:string'),
117 'datep' => array('name' => 'datep', 'type' => 'xsd:dateTime'),
118 'datef' => array('name' => 'datef', 'type' => 'xsd:dateTime'),
119 'datec' => array('name' => 'datec', 'type' => 'xsd:dateTime'),
120 'datem' => array('name' => 'datem', 'type' => 'xsd:dateTime'),
121 'note' => array('name' => 'note', 'type' => 'xsd:string'),
122 'percentage' => array('name' => 'percentage', 'type' => 'xsd:string'),
123 'author' => array('name' => 'author', 'type' => 'xsd:string'),
124 'usermod' => array('name' => 'usermod', 'type' => 'xsd:string'),
125 'userownerid' => array('name' => 'userownerid', 'type' => 'xsd:string'),
126 'priority' => array('name' => 'priority', 'type' => 'xsd:string'),
127 'fulldayevent' => array('name' => 'fulldayevent', 'type' => 'xsd:string'),
128 'location' => array('name' => 'location', 'type' => 'xsd:string'),
129 'socid' => array('name' => 'socid', 'type' => 'xsd:string'),
130 'contactid' => array('name' => 'contactid', 'type' => 'xsd:string'),
131 'projectid' => array('name' => 'projectid', 'type' => 'xsd:string'),
132 'fk_element' => array('name' => 'fk_element', 'type' => 'xsd:string'),
133 'elementtype' => array('name' => 'elementtype', 'type' => 'xsd:string'));
134
135
136$elementtype = 'actioncomm';
137
138//Retrieve all extrafield for actioncomm
139// fetch optionals attributes and labels
140$extrafields = new ExtraFields($db);
141$extrafields->fetch_name_optionals_label($elementtype, true);
142$extrafield_array = null;
143if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype]['count'] > 0) {
144 $extrafield_array = array();
145}
146if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
147 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
148 $type = $extrafields->attributes[$elementtype]['type'][$key];
149 if ($type == 'date' || $type == 'datetime') {
150 $type = 'xsd:dateTime';
151 } else {
152 $type = 'xsd:string';
153 }
154
155 $extrafield_array['options_'.$key] = array('name' => 'options_'.$key, 'type' => $type);
156 }
157}
158if (is_array($extrafield_array)) {
159 $actioncomm_fields = array_merge($actioncomm_fields, $extrafield_array);
160}
161
162// Define other specific objects
163$server->wsdl->addComplexType(
164 'actioncomm',
165 'complexType',
166 'struct',
167 'all',
168 '',
169 $actioncomm_fields
170);
171
172
173$server->wsdl->addComplexType(
174 'actioncommtype',
175 'complexType',
176 'array',
177 'sequence',
178 '',
179 array(
180 'code' => array('name' => 'code', 'type' => 'xsd:string'),
181 'libelle' => array('name' => 'libelle', 'type' => 'xsd:string')
182 )
183);
184
185$server->wsdl->addComplexType(
186 'actioncommtypes',
187 'complexType',
188 'array',
189 'sequence',
190 '',
191 array(
192 'actioncommtype' => array(
193 'name' => 'actioncommtype',
194 'type' => 'tns:actioncommtype',
195 'minOccurs' => '0',
196 'maxOccurs' => 'unbounded'
197 )
198 )
199);
200
201
202// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
203// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
204// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
205$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
206$styleuse = 'encoded'; // encoded/literal/literal wrapped
207// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
208
209
210// Register WSDL
211$server->register(
212 'getListActionCommType',
213 // Entry values
214 array('authentication' => 'tns:authentication'),
215 // Exit values
216 array('result' => 'tns:result', 'actioncommtypes' => 'tns:actioncommtypes'),
217 $ns,
218 $ns.'#getListActionCommType',
219 $styledoc,
220 $styleuse,
221 'WS to get actioncommType'
222);
223
224// Register WSDL
225$server->register(
226 'getActionComm',
227 // Entry values
228 array('authentication' => 'tns:authentication', 'id' => 'xsd:string'),
229 // Exit values
230 array('result' => 'tns:result', 'actioncomm' => 'tns:actioncomm'),
231 $ns,
232 $ns.'#getActionComm',
233 $styledoc,
234 $styleuse,
235 'WS to get actioncomm'
236);
237
238// Register WSDL
239$server->register(
240 'createActionComm',
241 // Entry values
242 array('authentication' => 'tns:authentication', 'actioncomm' => 'tns:actioncomm'),
243 // Exit values
244 array('result' => 'tns:result', 'id' => 'xsd:string'),
245 $ns,
246 $ns.'#createActionComm',
247 $styledoc,
248 $styleuse,
249 'WS to create a actioncomm'
250);
251
252// Register WSDL
253$server->register(
254 'updateActionComm',
255 // Entry values
256 array('authentication' => 'tns:authentication', 'actioncomm' => 'tns:actioncomm'),
257 // Exit values
258 array('result' => 'tns:result', 'id' => 'xsd:string'),
259 $ns,
260 $ns.'#updateActionComm',
261 $styledoc,
262 $styleuse,
263 'WS to update a actioncomm'
264);
265
266
267
268
276function getActionComm($authentication, $id)
277{
278 global $db, $conf, $langs;
279
280 dol_syslog("Function: getActionComm login=".$authentication['login']." id=".$id);
281
282 if ($authentication['entity']) {
283 $conf->entity = $authentication['entity'];
284 }
285
286 // Init and check authentication
287 $objectresp = array();
288 $errorcode = '';
289 $errorlabel = '';
290 $error = 0;
291 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
292 // Check parameters
293 if ($error || (!$id)) {
294 $error++;
295 $errorcode = 'BAD_PARAMETERS';
296 $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
297 }
298
299 if (!$error) {
300 $fuser->getrights();
301
302 if ($fuser->hasRight('agenda', 'allactions', 'read')) {
303 $actioncomm = new ActionComm($db);
304 $result = $actioncomm->fetch($id);
305 if ($result > 0) {
306 $actioncomm_result_fields = array(
307 'id' => $actioncomm->id,
308 'ref' => $actioncomm->ref,
309 'ref_ext' => $actioncomm->ref_ext,
310 'type_id' => $actioncomm->type_id,
311 'type_code' => $actioncomm->type_code,
312 'type' => $actioncomm->type,
313 'label' => $actioncomm->label,
314 'datep' => dol_print_date($actioncomm->datep, 'dayhourrfc'),
315 'datef' => dol_print_date($actioncomm->datef, 'dayhourrfc'),
316 'datec' => dol_print_date($actioncomm->datec, 'dayhourrfc'),
317 'datem' => dol_print_date($actioncomm->datem, 'dayhourrfc'),
318 'note' => $actioncomm->note_private,
319 'percentage' => $actioncomm->percentage,
320 'author' => $actioncomm->authorid,
321 'usermod' => $actioncomm->usermodid,
322 'userownerid' => $actioncomm->userownerid,
323 'priority' => $actioncomm->priority,
324 'fulldayevent' => $actioncomm->fulldayevent,
325 'location' => $actioncomm->location,
326 'socid' => $actioncomm->socid,
327 'contactid' => $actioncomm->contact_id,
328 'projectid' => $actioncomm->fk_project,
329 'fk_element' => $actioncomm->fk_element,
330 'elementtype' => $actioncomm->elementtype
331 );
332
333 $elementtype = 'actioncomm';
334
335 // Retrieve all extrafield for actioncomm
336 // fetch optionals attributes and labels
337 $extrafields = new ExtraFields($db);
338 $extrafields->fetch_name_optionals_label($elementtype, true);
339 //Get extrafield values
340 $actioncomm->fetch_optionals();
341
342 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
343 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
344 $actioncomm_result_fields = array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key]));
345 }
346 }
347
348 // Create
349 $objectresp = array(
350 'result' => array('result_code' => 'OK', 'result_label' => ''),
351 'actioncomm' => $actioncomm_result_fields);
352 } else {
353 $error++;
354 $errorcode = 'NOT_FOUND';
355 $errorlabel = 'Object not found for id='.$id;
356 }
357 } else {
358 $error++;
359 $errorcode = 'PERMISSION_DENIED';
360 $errorlabel = 'User does not have permission for this request';
361 }
362 }
363
364 if ($error) {
365 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
366 }
367
368 return $objectresp;
369}
370
371
378function getListActionCommType($authentication)
379{
380 global $db, $conf, $langs;
381
382 dol_syslog("Function: getListActionCommType login=".$authentication['login']);
383
384 if ($authentication['entity']) {
385 $conf->entity = $authentication['entity'];
386 }
387
388 // Init and check authentication
389 $objectresp = array();
390 $errorcode = '';
391 $errorlabel = '';
392 $error = 0;
393 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
394
395 if (!$error) {
396 $fuser->getrights();
397
398 if ($fuser->hasRight('agenda', 'myactions', 'read')) {
399 $cactioncomm = new CActionComm($db);
400 $result = $cactioncomm->liste_array('', 'code');
401 if ($result > 0) {
402 $resultarray = array();
403 foreach ($cactioncomm->liste_array as $code => $libeller) {
404 $resultarray[] = array('code' => $code, 'libelle' => $libeller);
405 }
406
407 $objectresp = array(
408 'result' => array('result_code' => 'OK', 'result_label' => ''),
409 'actioncommtypes' => $resultarray);
410 } else {
411 $error++;
412 $errorcode = 'NOT_FOUND';
413 $errorlabel = 'Failed to execute liste_array';
414 }
415 } else {
416 $error++;
417 $errorcode = 'PERMISSION_DENIED';
418 $errorlabel = 'User does not have permission for this request';
419 }
420 }
421
422 if ($error) {
423 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
424 }
425
426 return $objectresp;
427}
428
429
437function createActionComm($authentication, $actioncomm)
438{
439 global $db, $conf;
440
441 $now = dol_now();
442
443 dol_syslog("Function: createActionComm login=".$authentication['login']);
444
445 if ($authentication['entity']) {
446 $conf->entity = $authentication['entity'];
447 }
448
449 // Init and check authentication
450 $objectresp = array();
451 $errorcode = '';
452 $errorlabel = '';
453 $error = 0;
454 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
455
456 if (!$error) {
457 $newobject = new ActionComm($db);
458
459 $newobject->datep = $actioncomm['datep'];
460 $newobject->datef = $actioncomm['datef'];
461 $newobject->type_code = $actioncomm['type_code'];
462 $newobject->socid = $actioncomm['socid'];
463 $newobject->fk_project = $actioncomm['projectid'];
464 $newobject->note = $actioncomm['note'];
465 $newobject->note_private = $actioncomm['note'];
466 $newobject->contact_id = $actioncomm['contactid'];
467 $newobject->userownerid = $actioncomm['userownerid'];
468 $newobject->label = $actioncomm['label'];
469 $newobject->percentage = $actioncomm['percentage'];
470 $newobject->priority = $actioncomm['priority'];
471 $newobject->fulldayevent = $actioncomm['fulldayevent'];
472 $newobject->location = $actioncomm['location'];
473 $newobject->fk_element = $actioncomm['fk_element'];
474 $newobject->elementtype = $actioncomm['elementtype'];
475
476 $elementtype = 'actioncomm';
477
478 //Retrieve all extrafield for actioncomm
479 // fetch optionals attributes and labels
480 $extrafields = new ExtraFields($db);
481 $extrafields->fetch_name_optionals_label($elementtype, true);
482 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
483 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
484 $key = 'options_'.$key;
485 $newobject->array_options[$key] = $actioncomm[$key];
486 }
487 }
488
489 $db->begin();
490
491 $result = $newobject->create($fuser);
492 if ($result <= 0) {
493 $error++;
494 }
495
496 if (!$error) {
497 $db->commit();
498 $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id);
499 } else {
500 $db->rollback();
501 $error++;
502 $errorcode = 'KO';
503 $errorlabel = $newobject->error;
504 }
505 }
506
507 if ($error) {
508 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
509 }
510
511 return $objectresp;
512}
513
521function updateActionComm($authentication, $actioncomm)
522{
523 global $db, $conf;
524
525 $now = dol_now();
526
527 dol_syslog("Function: updateActionComm login=".$authentication['login']);
528
529 if ($authentication['entity']) {
530 $conf->entity = $authentication['entity'];
531 }
532
533 // Init and check authentication
534 $objectresp = array();
535 $errorcode = '';
536 $errorlabel = '';
537 $error = 0;
538 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
539 // Check parameters
540 if (empty($actioncomm['id'])) {
541 $error++;
542 $errorcode = 'KO';
543 $errorlabel = "Actioncomm id is mandatory.";
544 }
545
546 if (!$error) {
547 $objectfound = false;
548
549 $object = new ActionComm($db);
550 $result = $object->fetch($actioncomm['id']);
551
552 if (!empty($object->id)) {
553 $objectfound = true;
554
555 $object->datep = $actioncomm['datep'];
556 $object->datef = $actioncomm['datef'];
557 $object->type_code = $actioncomm['type_code'];
558 $object->socid = $actioncomm['socid'];
559 $object->contact_id = $actioncomm['contactid'];
560 $object->fk_project = $actioncomm['projectid'];
561 $object->note = $actioncomm['note'];
562 $object->userownerid = $actioncomm['userownerid'];
563 $object->label = $actioncomm['label'];
564 $object->percentage = $actioncomm['percentage'];
565 $object->priority = $actioncomm['priority'];
566 $object->fulldayevent = $actioncomm['fulldayevent'];
567 $object->location = $actioncomm['location'];
568 $object->fk_element = $actioncomm['fk_element'];
569 $object->elementtype = $actioncomm['elementtype'];
570
571 $elementtype = 'actioncomm';
572
573 //Retrieve all extrafield for actioncomm
574 // fetch optionals attributes and labels
575 $extrafields = new ExtraFields($db);
576 $extrafields->fetch_name_optionals_label($elementtype, true);
577 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
578 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
579 $key = 'options_'.$key;
580 $object->array_options[$key] = $actioncomm[$key];
581 }
582 }
583
584 $db->begin();
585
586 $result = $object->update($fuser);
587 if ($result <= 0) {
588 $error++;
589 }
590 }
591 '@phan-var-force array{id:string} $actioncomm';
592
593 if ((!$error) && ($objectfound)) {
594 $db->commit();
595 $objectresp = array(
596 'result' => array('result_code' => 'OK', 'result_label' => ''),
597 'id' => $object->id
598 );
599 } elseif ($objectfound) {
600 $db->rollback();
601 $error++;
602 $errorcode = 'KO';
603 $errorlabel = $object->error;
604 } else {
605 $error++;
606 $errorcode = 'NOT_FOUND';
607 $errorlabel = 'Actioncomm id='.$actioncomm['id'].' cannot be found';
608 }
609 }
610
611 if ($error) {
612 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
613 }
614
615 return $objectresp;
616}
617
618// Return the results.
619$server->service(file_get_contents("php://input"));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage standard extra fields.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return 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:36