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