server_actioncomm.php 17 KB

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