dolibarr  9.0.0
oauth.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2018 Frederic France <frederic.france@netlogic.fr>
3  * Copyright (C) 2016 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
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  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
29 
30 
31 // Define $urlwithroot
32 $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
33 $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
34 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('admin', 'oauth'));
38 
39 // Security check
40 if (!$user->admin)
42 
43 $action = GETPOST('action', 'alpha');
44 
45 
46 /*
47  * Actions
48  */
49 
50 if ($action == 'update')
51 {
52  $error = 0;
53 
54  foreach ($list as $constname) {
55  $constvalue = GETPOST($constname[1], 'alpha');
56  if (!dolibarr_set_const($db, $constname[1], $constvalue, 'chaine', 0, '', $conf->entity))
57  $error++;
58  $constvalue = GETPOST($constname[2], 'alpha');
59  if (!dolibarr_set_const($db, $constname[2], $constvalue, 'chaine', 0, '', $conf->entity))
60  $error++;
61  }
62 
63  if (! $error)
64  {
65  setEventMessages($langs->trans("SetupSaved"), null);
66  } else {
67  setEventMessages($langs->trans("Error"), null, 'errors');
68  }
69 }
70 
71 /*
72  * View
73  */
74 
75 llxHeader();
76 
77 $form = new Form($db);
78 
79 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
80 print load_fiche_titre($langs->trans('ConfigOAuth'),$linkback,'title_setup');
81 
82 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
83 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
84 print '<input type="hidden" name="action" value="update">';
85 
86 $head = oauthadmin_prepare_head();
87 
88 dol_fiche_head($head, 'services', '', -1, 'technic');
89 
90 
91 print $langs->trans("ListOfSupportedOauthProviders").'<br><br>';
92 
93 print '<table class="noborder" width="100%">';
94 
95 $i=0;
96 
97 // $list is defined into oauth.lib.php
98 foreach ($list as $key)
99 {
100  $supported=0;
101  if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1;
102  if (! $supported) continue; // show only supported
103 
104  $i++;
105 
106  print '<tr class="liste_titre'.($i > 1 ?' liste_titre_add':'').'">';
107  // Api Name
108  $label = $langs->trans($key[0]);
109  print '<td>'.$label.'</td>';
110  print '<td>';
111  if (! empty($key[3])) print $langs->trans($key[3]);
112  print '</td>';
113  print '</tr>';
114 
115  if ($supported)
116  {
117  $redirect_uri=$urlwithroot.'/core/modules/oauth/'.$supportedoauth2array[$key[0]].'_oauthcallback.php';
118  print '<tr class="oddeven value">';
119  print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
120  print '<td><input style="width: 80%" type"text" name="uri'.$key[0].'" value="'.$redirect_uri.'">';
121  print '</td></tr>';
122  }
123  else
124  {
125  print '<tr class="oddeven value">';
126  print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
127  print '<td>'.$langs->trans("FeatureNotYetSupported").'</td>';
128  print '</td></tr>';
129  }
130 
131  // Api Id
132  print '<tr class="oddeven value">';
133  print '<td><label for="'.$key[1].'">'.$langs->trans($key[1]).'</label></td>';
134  print '<td><input type="text" size="100" id="'.$key[1].'" name="'.$key[1].'" value="'.$conf->global->{$key[1]}.'">';
135  print '</td></tr>';
136 
137  // Api Secret
138  print '<tr class="oddeven value">';
139  print '<td><label for="'.$key[2].'">'.$langs->trans($key[2]).'</label></td>';
140  print '<td><input type="password" size="100" id="'.$key[2].'" name="'.$key[2].'" value="'.$conf->global->{$key[2]}.'">';
141  print '</td></tr>';
142 }
143 
144 print '</table>'."\n";
145 
146 dol_fiche_end();
147 
148 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
149 
150 print '</form>';
151 
152 // End of page
153 llxFooter();
154 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
Definition: oauth.lib.php:272
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.