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