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