server_actioncomm.php 18 KB

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