dolibarr 18.0.6
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 (empty($conf->global->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 = ''; $errorlabel = '';
287 $error = 0;
288 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
289 // Check parameters
290 if ($error || (!$id)) {
291 $error++;
292 $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
293 }
294
295 if (!$error) {
296 $fuser->getrights();
297
298 if ($fuser->rights->agenda->allactions->read) {
299 $actioncomm = new ActionComm($db);
300 $result = $actioncomm->fetch($id);
301 if ($result > 0) {
302 $actioncomm_result_fields = array(
303 'id' => $actioncomm->id,
304 'ref'=> $actioncomm->ref,
305 'ref_ext'=> $actioncomm->ref_ext,
306 'type_id'=> $actioncomm->type_id,
307 'type_code'=> $actioncomm->type_code,
308 'type'=> $actioncomm->type,
309 'label'=> $actioncomm->label,
310 'datep'=> dol_print_date($actioncomm->datep, 'dayhourrfc'),
311 'datef'=> dol_print_date($actioncomm->datef, 'dayhourrfc'),
312 'datec'=> dol_print_date($actioncomm->datec, 'dayhourrfc'),
313 'datem'=> dol_print_date($actioncomm->datem, 'dayhourrfc'),
314 'note'=> $actioncomm->note_private,
315 'percentage'=> $actioncomm->percentage,
316 'author'=> $actioncomm->authorid,
317 'usermod'=> $actioncomm->usermodid,
318 'userownerid'=> $actioncomm->userownerid,
319 'priority'=> $actioncomm->priority,
320 'fulldayevent'=> $actioncomm->fulldayevent,
321 'location'=> $actioncomm->location,
322 'socid'=> $actioncomm->socid,
323 'contactid'=> $actioncomm->contact_id,
324 'projectid'=> $actioncomm->fk_project,
325 'fk_element'=> $actioncomm->fk_element,
326 'elementtype'=> $actioncomm->elementtype
327 );
328
329 $elementtype = 'actioncomm';
330
331 // Retrieve all extrafield for actioncomm
332 // fetch optionals attributes and labels
333 $extrafields = new ExtraFields($db);
334 $extrafields->fetch_name_optionals_label($elementtype, true);
335 //Get extrafield values
336 $actioncomm->fetch_optionals();
337
338 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
339 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
340 $actioncomm_result_fields = array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key]));
341 }
342 }
343
344 // Create
345 $objectresp = array(
346 'result'=>array('result_code'=>'OK', 'result_label'=>''),
347 'actioncomm'=>$actioncomm_result_fields);
348 } else {
349 $error++;
350 $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id;
351 }
352 } else {
353 $error++;
354 $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
355 }
356 }
357
358 if ($error) {
359 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
360 }
361
362 return $objectresp;
363}
364
365
372function getListActionCommType($authentication)
373{
374 global $db, $conf, $langs;
375
376 dol_syslog("Function: getListActionCommType login=".$authentication['login']);
377
378 if ($authentication['entity']) {
379 $conf->entity = $authentication['entity'];
380 }
381
382 // Init and check authentication
383 $objectresp = array();
384 $errorcode = ''; $errorlabel = '';
385 $error = 0;
386 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
387
388 if (!$error) {
389 $fuser->getrights();
390
391 if ($fuser->rights->agenda->myactions->read) {
392 $cactioncomm = new CActionComm($db);
393 $result = $cactioncomm->liste_array('', 'code');
394 if ($result > 0) {
395 $resultarray = array();
396 foreach ($cactioncomm->liste_array as $code => $libeller) {
397 $resultarray[] = array('code'=>$code, 'libelle'=>$libeller);
398 }
399
400 $objectresp = array(
401 'result'=>array('result_code'=>'OK', 'result_label'=>''),
402 'actioncommtypes'=>$resultarray);
403 } else {
404 $error++;
405 $errorcode = 'NOT_FOUND'; $errorlabel = 'Failed to execute liste_array';
406 }
407 } else {
408 $error++;
409 $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
410 }
411 }
412
413 if ($error) {
414 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
415 }
416
417 return $objectresp;
418}
419
420
428function createActionComm($authentication, $actioncomm)
429{
430 global $db, $conf, $langs;
431
432 $now = dol_now();
433
434 dol_syslog("Function: createActionComm login=".$authentication['login']);
435
436 if ($authentication['entity']) {
437 $conf->entity = $authentication['entity'];
438 }
439
440 // Init and check authentication
441 $objectresp = array();
442 $errorcode = ''; $errorlabel = '';
443 $error = 0;
444 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
445
446 if (!$error) {
447 $newobject = new ActionComm($db);
448
449 $newobject->datep = $actioncomm['datep'];
450 $newobject->datef = $actioncomm['datef'];
451 $newobject->type_code = $actioncomm['type_code'];
452 $newobject->socid = $actioncomm['socid'];
453 $newobject->fk_project = $actioncomm['projectid'];
454 $newobject->note = $actioncomm['note'];
455 $newobject->contact_id = $actioncomm['contactid'];
456 $newobject->userownerid = $actioncomm['userownerid'];
457 $newobject->label = $actioncomm['label'];
458 $newobject->percentage = $actioncomm['percentage'];
459 $newobject->priority = $actioncomm['priority'];
460 $newobject->fulldayevent = $actioncomm['fulldayevent'];
461 $newobject->location = $actioncomm['location'];
462 $newobject->fk_element = $actioncomm['fk_element'];
463 $newobject->elementtype = $actioncomm['elementtype'];
464
465 $elementtype = 'actioncomm';
466
467 //Retrieve all extrafield for actioncomm
468 // fetch optionals attributes and labels
469 $extrafields = new ExtraFields($db);
470 $extrafields->fetch_name_optionals_label($elementtype, true);
471 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
472 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
473 $key = 'options_'.$key;
474 $newobject->array_options[$key] = $actioncomm[$key];
475 }
476 }
477
478 $db->begin();
479
480 $result = $newobject->create($fuser);
481 if ($result <= 0) {
482 $error++;
483 }
484
485 if (!$error) {
486 $db->commit();
487 $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id);
488 } else {
489 $db->rollback();
490 $error++;
491 $errorcode = 'KO';
492 $errorlabel = $newobject->error;
493 }
494 }
495
496 if ($error) {
497 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
498 }
499
500 return $objectresp;
501}
502
510function updateActionComm($authentication, $actioncomm)
511{
512 global $db, $conf, $langs;
513
514 $now = dol_now();
515
516 dol_syslog("Function: updateActionComm login=".$authentication['login']);
517
518 if ($authentication['entity']) {
519 $conf->entity = $authentication['entity'];
520 }
521
522 // Init and check authentication
523 $objectresp = array();
524 $errorcode = ''; $errorlabel = '';
525 $error = 0;
526 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
527 // Check parameters
528 if (empty($actioncomm['id'])) {
529 $error++; $errorcode = 'KO'; $errorlabel = "Actioncomm id is mandatory.";
530 }
531
532 if (!$error) {
533 $objectfound = false;
534
535 $object = new ActionComm($db);
536 $result = $object->fetch($actioncomm['id']);
537
538 if (!empty($object->id)) {
539 $objectfound = true;
540
541 $object->datep = $actioncomm['datep'];
542 $object->datef = $actioncomm['datef'];
543 $object->type_code = $actioncomm['type_code'];
544 $object->socid = $actioncomm['socid'];
545 $object->contact_id = $actioncomm['contactid'];
546 $object->fk_project = $actioncomm['projectid'];
547 $object->note = $actioncomm['note'];
548 $object->userownerid = $actioncomm['userownerid'];
549 $object->label = $actioncomm['label'];
550 $object->percentage = $actioncomm['percentage'];
551 $object->priority = $actioncomm['priority'];
552 $object->fulldayevent = $actioncomm['fulldayevent'];
553 $object->location = $actioncomm['location'];
554 $object->fk_element = $actioncomm['fk_element'];
555 $object->elementtype = $actioncomm['elementtype'];
556
557 $elementtype = 'actioncomm';
558
559 //Retrieve all extrafield for actioncomm
560 // fetch optionals attributes and labels
561 $extrafields = new ExtraFields($db);
562 $extrafields->fetch_name_optionals_label($elementtype, true);
563 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
564 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
565 $key = 'options_'.$key;
566 $object->array_options[$key] = $actioncomm[$key];
567 }
568 }
569
570 $db->begin();
571
572 $result = $object->update($fuser);
573 if ($result <= 0) {
574 $error++;
575 }
576 }
577
578 if ((!$error) && ($objectfound)) {
579 $db->commit();
580 $objectresp = array(
581 'result'=>array('result_code'=>'OK', 'result_label'=>''),
582 'id'=>$object->id
583 );
584 } elseif ($objectfound) {
585 $db->rollback();
586 $error++;
587 $errorcode = 'KO';
588 $errorlabel = $object->error;
589 } else {
590 $error++;
591 $errorcode = 'NOT_FOUND';
592 $errorlabel = 'Actioncomm id='.$actioncomm['id'].' cannot be found';
593 }
594 }
595
596 if ($error) {
597 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
598 }
599
600 return $objectresp;
601}
602
603// Return the results.
604$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.
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