dolibarr  7.0.0-beta
oauth.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Frederic France <frederic.france@free.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 
37 $langs->load("admin");
38 $langs->load("oauth");
39 
40 // Security check
41 if (!$user->admin)
43 
44 $action = GETPOST('action', 'alpha');
45 
46 
47 /*
48  * Actions
49  */
50 
51 if ($action == 'update')
52 {
53  $error = 0;
54 
55  foreach ($list as $constname) {
56  $constvalue = GETPOST($constname[1], 'alpha');
57  if (!dolibarr_set_const($db, $constname[1], $constvalue, 'chaine', 0, '', $conf->entity))
58  $error++;
59  $constvalue = GETPOST($constname[2], 'alpha');
60  if (!dolibarr_set_const($db, $constname[2], $constvalue, 'chaine', 0, '', $conf->entity))
61  $error++;
62  }
63 
64  if (! $error)
65  {
66  setEventMessages($langs->trans("SetupSaved"), null);
67  } else {
68  setEventMessages($langs->trans("Error"), null, 'errors');
69  }
70 }
71 
72 /*
73  * View
74  */
75 
76 llxHeader();
77 
78 $form = new Form($db);
79 
80 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
81 print load_fiche_titre($langs->trans('ConfigOAuth'),$linkback,'title_setup');
82 
83 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
84 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
85 print '<input type="hidden" name="action" value="update">';
86 
87 $head = oauthadmin_prepare_head();
88 
89 dol_fiche_head($head, 'services', '', -1, 'technic');
90 
91 
92 print $langs->trans("ListOfSupportedOauthProviders").'<br><br>';
93 
94 print '<table class="noborder" width="100%">';
95 
96 $i=0;
97 
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 
145 print '</table>'."\n";
146 
147 dol_fiche_end();
148 
149 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
150 
151 print '</form>';
152 
153 
154 llxFooter();
155 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
Definition: oauth.lib.php:259
print
Draft customers invoices.
Definition: index.php:91