27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
34 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
35 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
39 $langs->loadLangs(array(
'admin',
'oauth',
'modulebuilder'));
46 $action =
GETPOST(
'action',
'aZ09');
47 $provider =
GETPOST(
'provider',
'aZ09');
48 $label =
GETPOST(
'label',
'aZ09');
57 if ($action ==
'add') {
58 if ($provider && $provider !=
'-1') {
59 $constname = strtoupper($provider).($label ?
'-'.$label :
'').
'_ID';
62 setEventMessages($langs->trans(
"AOAuthEntryForThisProviderAndLabelAlreadyHasAKey"),
null,
'errors');
70 if ($action ==
'update') {
71 foreach ($conf->global as $key => $val) {
72 if (!empty($val) && preg_match(
'/^OAUTH_.+_ID$/', $key)) {
73 $constvalue = str_replace(
'_ID',
'', $key);
100 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
101 print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
103 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
104 print
'<input type="hidden" name="token" value="'.newToken().
'">';
105 print
'<input type="hidden" name="action" value="add">';
112 print
'<span class="opacitymedium">'.$langs->trans(
"ListOfSupportedOauthProviders").
'</span><br><br>';
115 print
'<select name="provider" id="provider" class="minwidth150">';
116 print
'<option name="-1" value="-1">'.$langs->trans(
"OAuthProvider").
'</option>';
117 foreach ($list as $key) {
119 $keyforsupportedoauth2array = $key[0];
121 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
129 print
'<option name="'.$keyforsupportedoauth2array.
'" value="'.str_replace(
'_NAME',
'', $keyforsupportedoauth2array).
'">'.$supportedoauth2array[$keyforsupportedoauth2array][
'name'].
'</option>'.
"\n";
133 print
' <input type="text" name="label" value="" placeholder="'.$langs->trans(
"Label").
'" pattern="^\S+$" title="'.$langs->trans(
"SpaceOrSpecialCharAreNotAllowed").
'">';
134 print
' <input type="submit" class="button small" name="add" value="'.$langs->trans(
"Add").
'">';
144 foreach ($conf->global as $key => $val) {
145 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
146 $provider = preg_replace(
'/_ID$/',
'', $key);
147 $listinsetup[] = array($provider.
'_NAME', $provider.
'_ID', $provider.
'_SECRET',
'OAUTH Provider '.str_replace(
'OAUTH_',
'', $provider));
152 if (count($listinsetup) > 0) {
153 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
154 print
'<input type="hidden" name="token" value="'.newToken().
'">';
155 print
'<input type="hidden" name="action" value="update">';
157 print
'<div class="div-table-responsive-no-min">';
158 print
'<table class="noborder centpercent">';
163 foreach ($listinsetup as $key) {
165 $keyforsupportedoauth2array = $key[0];
166 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
167 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
168 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
169 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
171 $keyforprovider =
'';
173 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
174 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
176 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
185 print
'<tr class="liste_titre'.($i > 1 ?
' liste_titre_add' :
'').
'">';
187 $label = $langs->trans($keyforsupportedoauth2array);
189 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
191 if ($keyforprovider) {
192 print
' (<b>'.$keyforprovider.
'</b>)';
194 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
198 if (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials'])) {
199 print $langs->trans(
"OAUTH_URL_FOR_CREDENTIAL", $supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials']);
205 $redirect_uri = $urlwithroot.
'/core/modules/oauth/'.$supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile'].
'_oauthcallback.php';
206 print
'<tr class="oddeven value">';
207 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
208 print
'<td><input style="width: 80%" type"text" name="uri'.$keyforsupportedoauth2array.
'" value="'.$redirect_uri.
'">';
211 print
'<tr class="oddeven value">';
212 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
213 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
218 print
'<tr class="oddeven value">';
219 print
'<td><label for="'.$key[1].
'">'.$langs->trans(
"OAUTH_ID").
'</label></td>';
220 print
'<td><input type="text" size="100" id="'.$key[1].
'" name="'.$key[1].
'" value="'.$conf->global->{$key[1]}.
'">';
224 print
'<tr class="oddeven value">';
225 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_SECRET").
'</label></td>';
226 print
'<td><input type="password" size="100" id="'.$key[2].
'" name="'.$key[2].
'" value="'.$conf->global->{$key[2]}.
'">';
230 print
'</table>'.
"\n";
233 print
$form->buttonsSaveCancel(
"Modify",
'');