31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/api.lib.php';
47$langs->loadLangs(array(
'admin',
'users'));
56$action =
GETPOST(
'action',
'aZ09');
57$massaction =
GETPOST(
'massaction',
'alpha');
58$confirm =
GETPOST(
'confirm',
'alpha');
59$toselect =
GETPOST(
'toselect',
'array');
62$search_user =
GETPOST(
'search_user',
'alpha');
63$search_entity =
GETPOST(
'search_entity',
'alpha');
64$search_datec_startday =
GETPOSTINT(
'search_datec_startday');
65$search_datec_startmonth =
GETPOSTINT(
'search_datec_startmonth');
66$search_datec_startyear =
GETPOSTINT(
'search_datec_startyear');
67$search_datec_endday =
GETPOSTINT(
'search_datec_endday');
68$search_datec_endmonth =
GETPOSTINT(
'search_datec_endmonth');
69$search_datec_endyear =
GETPOSTINT(
'search_datec_endyear');
70$search_datec_start =
dol_mktime(0, 0, 0, $search_datec_startmonth, $search_datec_startday, $search_datec_startyear);
71$search_datec_end =
dol_mktime(23, 59, 59, $search_datec_endmonth, $search_datec_endday, $search_datec_endyear);
72$search_tms_startday =
GETPOSTINT(
'search_tms_startday');
73$search_tms_startmonth =
GETPOSTINT(
'search_tms_startmonth');
74$search_tms_startyear =
GETPOSTINT(
'search_tms_startyear');
75$search_tms_endday =
GETPOSTINT(
'search_tms_endday');
76$search_tms_endmonth =
GETPOSTINT(
'search_tms_endmonth');
77$search_tms_endyear =
GETPOSTINT(
'search_tms_endyear');
78$search_tms_start =
dol_mktime(0, 0, 0, $search_tms_startmonth, $search_tms_startday, $search_tms_startyear);
79$search_tms_end =
dol_mktime(23, 59, 59, $search_tms_endmonth, $search_tms_endday, $search_tms_endyear);
83$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
84$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
86if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
89$offset = $limit * $page;
94 $sortfield =
'oat.tms';
101 'u.login' => array(
'label' =>
"User",
'checked' =>
'1'),
102 'e.label' => array(
'label' =>
"Entity",
'checked' =>
'1'),
103 'oat.datec' => array(
'label' =>
"DateCreation",
'checked' =>
'1'),
104 'oat.tms' => array(
'label' =>
"DateModification",
'checked' =>
'1'),
110if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
113 $search_datec_startday =
'';
114 $search_datec_startmonth =
'';
115 $search_datec_startyear =
'';
116 $search_datec_endday =
'';
117 $search_datec_endmonth =
'';
118 $search_datec_endyear =
'';
119 $search_datec_start =
'';
120 $search_datec_end =
'';
121 $search_tms_startday =
'';
122 $search_tms_startmonth =
'';
123 $search_tms_startyear =
'';
124 $search_tms_endday =
'';
125 $search_tms_endmonth =
'';
126 $search_tms_endyear =
'';
127 $search_tms_start =
'';
128 $search_tms_end =
'';
132if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')
133 ||
GETPOST(
'button_search_x',
'alpha') ||
GETPOST(
'button_search.x',
'alpha') ||
GETPOST(
'button_search',
'alpha')) {
136if (($action ==
'delete' && $confirm ==
'yes')) {
143 $unique_arr = array_unique($toselect);
144 foreach ($unique_arr as $toselectid) {
145 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"oauth_token";
146 $sql .=
" WHERE rowid = ".((int) $toselectid);
147 $sql .=
" AND service = 'dolibarr_rest_api'";
149 $result =
$db->query($sql);
164 } elseif ($nbok > 0) {
181$nbtotalofrecords =
'';
184 $sqlforcount =
'SELECT COUNT(*) as nbtotalofrecords';
185 $sqlforcount .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token as oat";
186 $sqlforcount .=
" WHERE entity IN (0, ".((int)
$conf->entity).
")";
187 $sqlforcount .=
" AND service = 'dolibarr_rest_api'";
188 $resql =
$db->query($sqlforcount);
190 $objforcount =
$db->fetch_object($resql);
191 $nbtotalofrecords = $objforcount->nbtotalofrecords;
196 if (($page * $limit) > $nbtotalofrecords) {
203$sql =
"SELECT oat.rowid, oat.tokenstring, oat.entity, oat.state as rights, oat.fk_user, oat.datec as date_creation, oat.tms as date_modification,";
204$sql .=
" oat.lastaccess, oat.apicount_total";
205$sql .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token as oat";
206$sql .=
" WHERE service = 'dolibarr_rest_api'";
207$sql .=
" AND EXISTS(SELECT 'exist' FROM llx_user as u WHERE u.api_key IS NOT NULL AND u.rowid = oat.fk_user)";
209 $sql .=
" AND EXISTS (SELECT 'exist' FROM ".MAIN_DB_PREFIX.
"user u";
210 $sql .=
" WHERE (u.lastname LIKE '%".$db->escape($search_user).
"%'";
211 $sql .=
" OR u.firstname LIKE '%".$db->escape($search_user).
"%')";
212 $sql .=
" AND oat.fk_user = u.rowid))";
214if ($search_datec_start) {
215 $sql .=
" AND oat.datec >= '".$db->idate($search_datec_start).
"'";
217if ($search_datec_end) {
218 $sql .=
" AND oat.datec <= '".$db->idate($search_datec_end).
"'";
220if ($search_tms_start) {
221 $sql .=
" AND oat.tms >= '".$db->idate($search_tms_start).
"'";
223if ($search_tms_end) {
224 $sql .=
" AND oat.tms <= '".$db->idate($search_tms_end).
"'";
226$sql .=
$db->order($sortfield, $sortorder);
228 $sql .=
$db->plimit($limit + 1, $offset);
231$resql =
$db->query($sql);
233$num =
$db->num_rows($resql);
235llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-api page-admin-index');
238if ($limit > 0 && $limit !=
$conf->liste_limit) {
239 $param .=
'&limit='.((int) $limit);
241if ($search_datec_startday) {
242 $param .=
'&search_date_startday='.urlencode((
string) ($search_datec_startday));
244if ($search_datec_startmonth) {
245 $param .=
'&search_date_startmonth='.urlencode((
string) ($search_datec_startmonth));
247if ($search_datec_startyear) {
248 $param .=
'&search_date_startyear='.urlencode((
string) ($search_datec_startyear));
250if ($search_datec_endday) {
251 $param .=
'&search_date_endday='.urlencode((
string) ($search_datec_endday));
253if ($search_datec_endmonth) {
254 $param .=
'&search_date_endmonth='.urlencode((
string) ($search_datec_endmonth));
256if ($search_datec_endyear) {
257 $param .=
'&search_date_endyear='.urlencode((
string) ($search_datec_endyear));
259if ($search_tms_startday) {
260 $param .=
'&search_date_startday='.urlencode((
string) ($search_tms_startday));
262if ($search_tms_startmonth) {
263 $param .=
'&search_date_startmonth='.urlencode((
string) ($search_tms_startmonth));
265if ($search_tms_startyear) {
266 $param .=
'&search_date_startyear='.urlencode((
string) ($search_tms_startyear));
268if ($search_tms_endday) {
269 $param .=
'&search_date_endday='.urlencode((
string) ($search_tms_endday));
271if ($search_tms_endmonth) {
272 $param .=
'&search_date_endmonth='.urlencode((
string) ($search_tms_endmonth));
274if ($search_tms_endyear) {
275 $param .=
'&search_date_endyear='.urlencode((
string) ($search_tms_endyear));
278$arrayofselected = is_array($toselect) ? $toselect : array();
280$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
287$arrayofmassactions = array(
288 'predelete' =>
img_picto(
'',
'delete',
'class="pictofixedwidth"').$langs->trans(
"Delete")
291if (
GETPOSTINT(
'nomassaction') || in_array($massaction, array(
'presend',
'predelete'))) {
292 $arrayofmassactions = array();
294$massactionbutton = $form->selectMassAction(
'', $arrayofmassactions);
297$tmpurlforbutton = DOL_URL_ROOT.
'/user/api_token/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.
'/api/admin/token_list.php');
298$morehtmlright .= dolGetButtonTitle($langs->trans(
'New'),
'',
'fa fa-plus-circle', $tmpurlforbutton);
300print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
301print
'<input type="hidden" name="token" value="'.newToken().
'">';
302print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
303print
'<input type="hidden" name="action" value="list">';
304print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
305print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
308print_barre_liste($langs->trans(
"ListOfTokensForAllUsers"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'fa-at', 0, $morehtmlright,
'', $limit, 0, 0, 1);
310include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
314include DOL_DOCUMENT_ROOT.
'/core/tpl/apitoken_list.tpl.php';
api_admin_prepare_head()
Return array head with list of tabs to view object information.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.