index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/webservices/admin/index.php
  22. * \ingroup webservices
  23. * \brief Page to setup webservices module
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. $langs->load("admin");
  29. if (!$user->admin) {
  30. accessforbidden();
  31. }
  32. $actionsave = GETPOST("save");
  33. // Sauvegardes parametres
  34. if ($actionsave) {
  35. $i = 0;
  36. $db->begin();
  37. $i += dolibarr_set_const($db, 'WEBSERVICES_KEY', GETPOST("WEBSERVICES_KEY"), 'chaine', 0, '', $conf->entity);
  38. if ($i >= 1) {
  39. $db->commit();
  40. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  41. } else {
  42. $db->rollback();
  43. setEventMessages($langs->trans("Error"), null, 'errors');
  44. }
  45. }
  46. /*
  47. * View
  48. */
  49. llxHeader();
  50. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  51. print load_fiche_titre($langs->trans("WebServicesSetup"), $linkback, 'title_setup');
  52. print '<span class="opacitymedium">'.$langs->trans("WebServicesDesc")."</span><br>\n";
  53. print "<br>\n";
  54. print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  55. print '<input type="hidden" name="token" value="'.newToken().'">';
  56. print '<input type="hidden" name="action" value="save">';
  57. print '<table class="noborder centpercent">';
  58. print '<tr class="liste_titre">';
  59. print "<td>".$langs->trans("Parameter")."</td>";
  60. print "<td>".$langs->trans("Value")."</td>";
  61. //print "<td>".$langs->trans("Examples")."</td>";
  62. print "<td>&nbsp;</td>";
  63. print "</tr>";
  64. print '<tr class="oddeven">';
  65. print '<td class="fieldrequired">'.$langs->trans("KeyForWebServicesAccess").'</td>';
  66. print '<td><input type="text" class="flat" id="WEBSERVICES_KEY" name="WEBSERVICES_KEY" value="'.(GETPOST('WEBSERVICES_KEY') ?GETPOST('WEBSERVICES_KEY') : (!empty($conf->global->WEBSERVICES_KEY) ? $conf->global->WEBSERVICES_KEY : '')).'" size="40">';
  67. if (!empty($conf->use_javascript_ajax)) {
  68. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  69. }
  70. print '</td>';
  71. print '<td>&nbsp;</td>';
  72. print '</tr>';
  73. print '</table>';
  74. print $form->buttonsSaveCancel("Save", '');
  75. print '</form>';
  76. print '<br><br>';
  77. // Webservices list
  78. $webservices = array(
  79. 'user' => '',
  80. 'thirdparty' => 'isModEnabled("societe")',
  81. 'contact' => 'isModEnabled("societe")',
  82. 'productorservice' => '(isModEnabled("product") || isModEnabled("service"))',
  83. 'order' => 'isModEnabled("commande")',
  84. 'invoice' => 'isModEnabled("facture")',
  85. 'supplier_invoice' => 'isModEnabled("fournisseur")',
  86. 'actioncomm' => 'isModEnabled("agenda")',
  87. 'category' => 'isModEnabled("categorie")',
  88. 'project' => 'isModEnabled("project")',
  89. 'other' => ''
  90. );
  91. // WSDL
  92. print '<u>'.$langs->trans("WSDLCanBeDownloadedHere").':</u><br>';
  93. foreach ($webservices as $name => $right) {
  94. if (!empty($right) && !verifCond($right)) {
  95. continue;
  96. }
  97. $url = DOL_MAIN_URL_ROOT.'/webservices/server_'.$name.'.php?wsdl';
  98. print img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a><br>\n";
  99. }
  100. print '<br>';
  101. // Endpoint
  102. print '<u>'.$langs->trans("EndPointIs").':</u><br>';
  103. foreach ($webservices as $name => $right) {
  104. if (!empty($right) && !verifCond($right)) {
  105. continue;
  106. }
  107. $url = DOL_MAIN_URL_ROOT.'/webservices/server_'.$name.'.php';
  108. print img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a><br>\n";
  109. }
  110. print '<br>';
  111. print '<br>';
  112. print $langs->trans("OnlyActiveElementsAreShown", DOL_URL_ROOT.'/admin/modules.php');
  113. $constname = 'WEBSERVICES_KEY';
  114. print dolJSToSetRandomPassword($constname);
  115. // End of page
  116. llxFooter();
  117. $db->close();