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