diff --git a/htdocs/user/api_token/card.php b/htdocs/user/api_token/card.php index 83017864be8..b2ae328c246 100644 --- a/htdocs/user/api_token/card.php +++ b/htdocs/user/api_token/card.php @@ -42,6 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; // Load translation files required by page $langs->loadLangs(array('admin', 'users')); +$error = 0; // Security check $id = GETPOSTINT('id'); @@ -50,6 +51,8 @@ $tokenid = GETPOST('tokenid', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $module = GETPOST('module', 'alpha'); $rights = GETPOSTINT('rights'); +$cancel = GETPOST('cancel', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); if (!isset($id) || empty($id)) { accessforbidden(); @@ -101,6 +104,14 @@ if ($reshook < 0) { } if (empty($reshook)) { + if ($cancel) { + if (!empty($backtopage)) { + header("Location: ".$backtopage); + exit; + } + $action = ''; + } + if (in_array($action, array('addrights', 'delrights'))) { $rigthsarray = []; @@ -224,7 +235,33 @@ if (empty($reshook)) { $token->rights = $newrigths; } - elseif ($action == 'confirm_delete' && $confirm == 'yes' && $caneditfield) { + if ($action == 'add') { + $tokenstring = GETPOST('api_key', 'alphanohtml'); + + if (empty($tokenstring)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ApiToken")), null, 'errors'); + $action = 'create'; + $error++; + } + + if (!$error) { + $db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, token, fk_user, entity, datec)"; + $sql .= " VALUES ('dolibarr_rest_api', '".$db->escape($tokenstring)."', ".($id).", ".((int) $conf->entity).", '".$db->idate(dol_now())."')"; + $resql = $db->query($sql); + + if (!$resql) { + dol_print_error($db); + $db->rollback(); + } else { + $insertedtokenid = $db->last_insert_id(MAIN_DB_PREFIX."oauth_token"); + $db->commit(); + header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id.'&tokenid='.$insertedtokenid); + exit; + } + } + } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $caneditfield) { // Remove token $sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token"; $sql .= " WHERE rowid = '".$tokenid."'"; @@ -279,424 +316,472 @@ $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->tra // Disabled prev/next because there is no token object dol_banner_tab($object, '', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'none', '', $morehtmlref); -// Tokens info -print '
'; -print '
'; -print ''; +if ($action == 'create') { + print ''; + print ''; + print ''; + print ''; -// Login -print ''; -if (!empty($object->ldap_sid) && $object->status == 0) { - print ''; -} else { + print dol_get_fiche_head(); + + print '
'.$langs->trans("Login").''; - print $langs->trans("LoginAccountDisableInDolibarr"); - print '
'; + + print ''; + print ''; + + print ''; print ''; + print "
'.$langs->trans('User').''.$person_name.'
'.$langs->trans('Entity').''.$conf->entity.'
'.$langs->trans("ApiToken").''; - $addadmin = ''; - if (property_exists($object, 'admin')) { - if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) { - $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft valignmiddle"'); - } elseif (!empty($object->admin)) { - $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft valignmiddle"'); - } + print ''; + if (!empty($conf->use_javascript_ajax)) { + print img_picto($langs->transnoentities('Generate'), 'refresh', 'id="generate_api_key" class="linkobject paddingleft"'); } - print showValueWithClipboardCPButton($object->login).$addadmin; + print '
\n"; + + print dol_get_fiche_end(); + + print '
'; + print ''; + print ''; + print '
'; + + print ""; + +} elseif ($id > 0 && !empty($token)) { + // Tokens info + print '
'; + print '
'; + print ''; + + // Login + print ''; + if (!empty($object->ldap_sid) && $object->status == 0) { + print ''; + } else { + print ''; + } + print ''."\n"; + + // Token + print ''; + print ''; -} -print ''."\n"; + print ''."\n"; -// Token -print ''; -print ''; -print ''."\n"; + // Entity + print ''; + print ''; + print ''."\n"; -// Entity -print ''; -print ''; -print ''."\n"; + // Creation date + print ''; + print ''; + print ''."\n"; -// Creation date -print ''; -print ''; -print ''."\n"; + // Modification date + print ''; + print ''; + print ''."\n"; -// Modification date -print ''; -print ''; -print ''."\n"; + print '
'.$langs->trans("Login").''; + print $langs->trans("LoginAccountDisableInDolibarr"); + print ''; + $addadmin = ''; + if (property_exists($object, 'admin')) { + if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) { + $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft valignmiddle"'); + } elseif (!empty($object->admin)) { + $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft valignmiddle"'); + } + } + print showValueWithClipboardCPButton($object->login).$addadmin; + print '
'.$langs->trans("ApiToken").''; + print showValueWithClipboardCPButton($token->token, 1, $token->token); print '
'.$langs->trans("ApiToken").''; -print showValueWithClipboardCPButton($token->token, 1, $token->token); -print '
'.$langs->trans("Entity").''; + print $token->entity; + print '
'.$langs->trans("Entity").''; -print $token->entity; -print '
'.$langs->trans("DateCreation").''; + print $token->date_creation; + print '
'.$langs->trans("DateCreation").''; -print $token->date_creation; -print '
'.$langs->trans("DateModification").''; + print $token->date_modification; + print '
'.$langs->trans("DateModification").''; -print $token->date_modification; -print '
'; + print '
'; + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&tokenid='.$token->token_id.'&action=delete&token='.newToken(), '', $caneditperms); + print '
'; + print '
'; -print ''; -print '
'; -print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&tokenid='.$token->token_id.'&action=delete&token='.newToken(), '', $caneditperms); -print '
'; -print '
'; + print dol_get_fiche_end(); -print dol_get_fiche_end(); - -print load_fiche_titre($langs->trans("ListOfRightsForToken"), '', ''); + print load_fiche_titre($langs->trans("ListOfRightsForToken"), '', ''); + // TODO : Rights part + print ''."\n"; + if ($user->admin) { + print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules")); + } - // TODO : Rights part -print ''."\n"; + $db->begin(); -if ($user->admin) { - print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules")); -} + // Search all modules with permission and reload permissions def. + $modules = array(); + $modulesdir = dolGetModulesDirs(); -$db->begin(); + foreach ($modulesdir as $dir) { + $handle = @opendir(dol_osencode($dir)); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') { + $modName = substr($file, 0, dol_strlen($file) - 10); -// Search all modules with permission and reload permissions def. -$modules = array(); -$modulesdir = dolGetModulesDirs(); + if ($modName) { + include_once $dir.$file; + $objMod = new $modName($db); + '@phan-var-force DolibarrModules $objMod'; -foreach ($modulesdir as $dir) { - $handle = @opendir(dol_osencode($dir)); - if (is_resource($handle)) { - while (($file = readdir($handle)) !== false) { - if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') { - $modName = substr($file, 0, dol_strlen($file) - 10); - - if ($modName) { - include_once $dir.$file; - $objMod = new $modName($db); - '@phan-var-force DolibarrModules $objMod'; - - // Load all lang files of module - if (isset($objMod->langfiles) && is_array($objMod->langfiles)) { - foreach ($objMod->langfiles as $domain) { - $langs->load($domain); + // Load all lang files of module + if (isset($objMod->langfiles) && is_array($objMod->langfiles)) { + foreach ($objMod->langfiles as $domain) { + $langs->load($domain); + } + } + // Load all permissions + if ($objMod->rights_class) { + $ret = $objMod->insert_permissions(0, $token->entity); + $modules[$objMod->rights_class] = $objMod; + //print "modules[".$objMod->rights_class."]=$objMod;"; } } - // Load all permissions - if ($objMod->rights_class) { - $ret = $objMod->insert_permissions(0, $token->entity); - $modules[$objMod->rights_class] = $objMod; - //print "modules[".$objMod->rights_class."]=$objMod;"; - } } } } } -} -$db->commit(); + $db->commit(); -// Load perms ids for the user -$tokenperms = explode(",", $token->rights); + // Load perms ids for the user + $tokenperms = explode(",", $token->rights); -print '
'; -print ''; + print '
'; + print '
'; -print ''; -print ''; -if ($caneditperms) { - print ''; -} else { + print ''; + print ''; + if ($caneditperms) { + print ''; + } else { + print ''; + } print ''; -} -print ''; -//print ''; -print ''; -print ''."\n"; + //print ''; + print ''; + print ''."\n"; -// Load modules rights and correct position if needed -$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault"; -$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; -$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" -$sql .= " AND r.entity = ".((int) $entity); -$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; + // Load modules rights and correct position if needed + $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault"; + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; + $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" + $sql .= " AND r.entity = ".((int)$entity); + $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows($result); - $i = 0; - $oldmod = ''; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + $oldmod = ''; - while ($i < $num) { - $obj = $db->fetch_object($result); + while ($i < $num) { + $obj = $db->fetch_object($result); - // If line is for a module that does not exist anymore (absent of includes/module), we ignore it - if (!isset($obj->module) || empty($modules[$obj->module])) { - $i++; - continue; - } - - // Special cases - if (isModEnabled("reception")) { - // The 2 permissions in fournisseur modules are replaced by permissions into reception module - if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') { + // If line is for a module that does not exist anymore (absent of includes/module), we ignore it + if (!isset($obj->module) || empty($modules[$obj->module])) { $i++; continue; } - if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') { - $i++; - continue; - } - } - $objMod = $modules[$obj->module]; - - // Save field module_position in database if value is wrong - if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) { - if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) { - // TODO Define familyposition - //$familyposition = $modules[$obj->module]->family_position; - $familyposition = 0; - - $newmoduleposition = $modules[$obj->module]->module_position; - - // Correct $newmoduleposition position for external modules - $objMod = $modules[$obj->module]; - if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) { - $newmoduleposition += 100000; + // Special cases + if (isModEnabled("reception")) { + // The 2 permissions in fournisseur modules are replaced by permissions into reception module + if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') { + $i++; + continue; } + if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') { + $i++; + continue; + } + } - $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).","; - $sqlupdate .= " family_position = ".((int) $familyposition); - $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'"; + $objMod = $modules[$obj->module]; - $db->query($sqlupdate); + // Save field module_position in database if value is wrong + if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) { + if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) { + // TODO Define familyposition + //$familyposition = $modules[$obj->module]->family_position; + $familyposition = 0; + + $newmoduleposition = $modules[$obj->module]->module_position; + + // Correct $newmoduleposition position for external modules + $objMod = $modules[$obj->module]; + if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) { + $newmoduleposition += 100000; + } + + $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int)$newmoduleposition).","; + $sqlupdate .= " family_position = ".((int)$familyposition); + $sqlupdate .= " WHERE module_position = ".((int)$obj->module_position)." AND module = '".$db->escape($obj->module)."'"; + + $db->query($sqlupdate); + } } } } -} -//Load perms ids for user and user's groups to show only the perms the user has and avoid better perms in the token. -$allusersperms = array(); + //Load perms ids for user and user's groups to show only the perms the user has and avoid better perms in the token. + $allusersperms = array(); -// Users perms -$sql = "SELECT ur.fk_id"; -$sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur"; -$sql .= " WHERE ur.entity = ".((int) $entity); -$sql .= " AND ur.fk_user = ".((int) $object->id); -$sql .= " UNION "; -// Groups perms -$sql .= "SELECT gr.fk_id"; -$sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr"; -$sql .= " WHERE EXISTS(SELECT gu.rowid FROM llx_usergroup_user as gu WHERE gu.fk_user = ".((int) $id)." AND gu.fk_usergroup = gr.fk_usergroup)"; + // Users perms + $sql = "SELECT ur.fk_id"; + $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur"; + $sql .= " WHERE ur.entity = ".((int)$entity); + $sql .= " AND ur.fk_user = ".((int)$object->id); + $sql .= " UNION "; + // Groups perms + $sql .= "SELECT gr.fk_id"; + $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr"; + $sql .= " WHERE EXISTS(SELECT gu.rowid FROM llx_usergroup_user as gu WHERE gu.fk_user = ".((int)$id)." AND gu.fk_usergroup = gr.fk_usergroup)"; -dol_syslog("get user perms", LOG_DEBUG); -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($result); - array_push($allusersperms, $obj->fk_id); - $i++; - } - $db->free($result); -} else { - dol_print_error($db); -} - -// Load and show all the perms grouped by module - -//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS; -$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault"; -$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; -$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" -$sql .= " AND r.entity = ".((int) $entity); -$sql .= " AND r.id IN (".implode(', ', $allusersperms).")"; -if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { - $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled -} -$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; - -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows($result); - $i = 0; - $j = 0; - $oldmod = ''; - - $cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"])); - $cookietohidegrouparray = explode(',', $cookietohidegroup); - //var_dump($cookietohidegrouparray); - - while ($i < $num) { - $obj = $db->fetch_object($result); - - // If line is for a module that does not exist anymore (absent of includes/module), we ignore it - if (empty($modules[$obj->module])) { + dol_syslog("get user perms", LOG_DEBUG); + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($result); + array_push($allusersperms, $obj->fk_id); $i++; - continue; } + $db->free($result); + } else { + dol_print_error($db); + } - // Special cases - if (isModEnabled("reception")) { - // The 2 permission in fournisseur modules has been replaced by permissions into reception module - if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') { + // Load and show all the perms grouped by module + + //print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS; + $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault"; + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; + $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" + $sql .= " AND r.entity = ".((int)$entity); + $sql .= " AND r.id IN (".implode(', ', $allusersperms).")"; + if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { + $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled + } + $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + $j = 0; + $oldmod = ''; + + $cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"])); + $cookietohidegrouparray = explode(',', $cookietohidegroup); + //var_dump($cookietohidegrouparray); + + while ($i < $num) { + $obj = $db->fetch_object($result); + + // If line is for a module that does not exist anymore (absent of includes/module), we ignore it + if (empty($modules[$obj->module])) { $i++; continue; } - if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') { - $i++; - continue; + + // Special cases + if (isModEnabled("reception")) { + // The 2 permission in fournisseur modules has been replaced by permissions into reception module + if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') { + $i++; + continue; + } + if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') { + $i++; + continue; + } } - } - $objMod = $modules[$obj->module]; + $objMod = $modules[$obj->module]; - if (GETPOSTISSET('forbreakperms_'.$obj->module)) { - $ishidden = GETPOSTINT('forbreakperms_'.$obj->module); - } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group - $ishidden = 1; - } else { - $ishidden = 0; - } - $isexpanded = ! $ishidden; - //var_dump("isexpanded=".$isexpanded); - - $permsgroupbyentitypluszero = array(); - if (!empty($permsgroupbyentity[0])) { - $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[0]); - } - if (!empty($permsgroupbyentity[$entity])) { - $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[$entity]); - } - //var_dump($permsgroupbyentitypluszero); - - // Break found, it's a new module to catch - if (isset($obj->module) && ($oldmod != $obj->module)) { - $oldmod = $obj->module; - - $j++; if (GETPOSTISSET('forbreakperms_'.$obj->module)) { $ishidden = GETPOSTINT('forbreakperms_'.$obj->module); - } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group + } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group $ishidden = 1; } else { $ishidden = 0; } - $isexpanded = ! $ishidden; - //var_dump('$obj->module='.$obj->module.' isexpanded='.$isexpanded); + $isexpanded = !$ishidden; + //var_dump("isexpanded=".$isexpanded); - // Break detected, we get objMod - $objMod = $modules[$obj->module]; - $picto = ($objMod->picto ? $objMod->picto : 'generic'); + $permsgroupbyentitypluszero = array(); + if (!empty($permsgroupbyentity[0])) { + $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[0]); + } + if (!empty($permsgroupbyentity[$entity])) { + $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[$entity]); + } + //var_dump($permsgroupbyentitypluszero); + + // Break found, it's a new module to catch + if (isset($obj->module) && ($oldmod != $obj->module)) { + $oldmod = $obj->module; + + $j++; + if (GETPOSTISSET('forbreakperms_'.$obj->module)) { + $ishidden = GETPOSTINT('forbreakperms_'.$obj->module); + } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group + $ishidden = 1; + } else { + $ishidden = 0; + } + $isexpanded = !$ishidden; + //var_dump('$obj->module='.$obj->module.' isexpanded='.$isexpanded); + + // Break detected, we get objMod + $objMod = $modules[$obj->module]; + $picto = ($objMod->picto ? $objMod->picto : 'generic'); + + // Show break line + print ''; + // Picto and label of module + print ''; + + // Permission and tick (2 columns) + if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) { + if ($caneditperms) { + print ''; + print ''; + } else { + print ''; + print ''; + } + } else { + if ($caneditperms) { + print ''; + print ''; + } else { + print ''; + print ''; + } + } + + // Description of permission (2 columns) + print ''; + print ''; //Add picto + / - when open en closed + print ''."\n"; + } + + $permlabel = (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($langs->trans("PermissionAdvanced".$obj->id) != "PermissionAdvanced".$obj->id) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != "Permission".$obj->id) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label))); + + print ''."\n"; + print ''; - // Show break line - print ''; // Picto and label of module - print ''; // Permission and tick (2 columns) - if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) { + if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) { // Permission granted because admin + print ''; if ($caneditperms) { - print ''; - print ''; } else { - print ''; - print ''; - } - } else { - if ($caneditperms) { - print ''; - print ''; + } elseif (in_array($obj->id, $tokenperms)) { // Permission granted by user + print ''; + if ($caneditperms) { + print ''; } else { - print ''; - print ''; + print ''; } - } - - // Description of permission (2 columns) - print ''; - print ''; //Add picto + / - when open en closed - print ''."\n"; - } - - $permlabel = (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($langs->trans("PermissionAdvanced".$obj->id) != "PermissionAdvanced".$obj->id) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != "Permission".$obj->id) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label))); - - print ''."\n"; - print ''; - - // Picto and label of module - print ''; - - // Permission and tick (2 columns) - if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) { // Permission granted because admin - print ''; - if ($caneditperms) { - print ''; - } else { - print ''; - } - print ''; - } elseif (in_array($obj->id, $tokenperms)) { // Permission granted by user - print ''; - if ($caneditperms) { - print ''; - } else { - print ''; - } - print ''; - } elseif (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero)) { - print ''; - if (in_array($obj->id, $permsgroupbyentitypluszero)) { // Permission granted by group - print ''; - print ''; + } elseif (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero)) { + print ''; + if (in_array($obj->id, $permsgroupbyentitypluszero)) { // Permission granted by group + print ''; + print ''; + } else { + // Do not own permission + if ($caneditperms) { + print ''; + } else { + print ''; + } + print ''; + } } else { // Do not own permission + print ''; if ($caneditperms) { print ''; } - } else { - // Do not own permission - print ''; - if ($caneditperms) { - print ''; + + // Description of permission (1 or 2 columns) + if (!$user->admin) { + print ''; + + // Permission id + if ($user->admin) { + print ''; } - print ''; - } - // Description of permission (1 or 2 columns) - if (!$user->admin) { - print ''."\n"; - print $permlabel; - $idtouse = $obj->id; - if (in_array($idtouse, array(121, 122, 125, 126))) { // Force message for the 3 permission on third parties - $idtouse = 122; + $i++; } - if ($langs->trans("Permission".$idtouse.'b') != "Permission".$idtouse.'b') { - print '
'.$langs->trans("Permission".$idtouse.'b').''; - } - if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') { - print '
'.$langs->trans("Permission".$obj->id.'c').''; - } - if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { - if (preg_match('/_advance$/', $obj->perms)) { - print ' ('.$langs->trans("AdvancedModeOnly").')'; - } - } - // Special warning case for the permission "Allow to modify other users password" - if ($obj->module == 'user' && $obj->perms == 'user' && $obj->subperms == 'password') { - if ((!empty($object->admin) && !empty($objMod->rights_admin_allowed)) || - in_array($obj->id, $tokenperms) /* if edited user owns this permissions */ || - (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero) && in_array($obj->id, $permsgroupbyentitypluszero))) { - print ' '.img_warning($langs->trans("AllowPasswordResetBySendingANewPassByEmail")); - } - } - // Special warning case for the permission "Create/modify other users, groups and permissions" - if ($obj->module == 'user' && $obj->perms == 'user' && ($obj->subperms == 'creer' || $obj->subperms == 'create')) { - if ((!empty($object->admin) && !empty($objMod->rights_admin_allowed)) || - in_array($obj->id, $tokenperms) /* if edited user owns this permissions */ || - (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero) && in_array($obj->id, $permsgroupbyentitypluszero))) { - print ' '.img_warning($langs->trans("AllowAnyPrivileges")); - } - } - // Special case for reading bank account when you have permission to manage Chart of account - if ($obj->module == 'banque' && $obj->perms == 'lire') { - if (isModEnabled("accounting") && $object->hasRight('accounting', 'chartofaccount')) { - print ' '.img_warning($langs->trans("WarningReadBankAlsoAllowedIfUserHasPermission")); - } - } - - print ''; - - // Permission id - if ($user->admin) { - print ''; - } - - print ''."\n"; - - $i++; - } -} else { - dol_print_error($db); -} -print '
'.$langs->trans("Module").''; - print ''.$langs->trans("All").""; - print ' / '; - print ''.$langs->trans("None").""; - print '
'.$langs->trans("Module").''; + print ''.$langs->trans("All").""; + print ' / '; + print ''.$langs->trans("None").""; + print ''; -print ''.img_picto('', 'folder-open', 'class="paddingright"').''.$langs->trans("ExpandAll").''; -print ' | '; -print ''.img_picto('', 'folder', 'class="paddingright"').''.$langs->trans("UndoExpandAll").''; -print '
'; + print ''.img_picto('', 'folder-open', 'class="paddingright"').''.$langs->trans("ExpandAll").''; + print ' | '; + print ''.img_picto('', 'folder', 'class="paddingright"').''.$langs->trans("UndoExpandAll").''; + print '
'; + print ''; + print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName(); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + + print '
'; - print ''; - print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName(); - print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print img_picto($langs->trans("AdministratorDesc"), 'star', 'class="paddingleft valignmiddle"'); print ''; + print ''; + print img_picto($langs->trans("Active"), 'switch_on', '', 0, 0, 0, '', 'opacitymedium'); print ''; + } + print ''; + print ''; + print 'id.'&confirm=yes">'; + //print img_edit_remove($langs->trans("Remove")); + print img_picto($langs->trans("Remove"), 'switch_on'); + print ''; print ''; + print img_picto($langs->trans("Active"), 'switch_on', '', 0, 0, 0, '', 'opacitymedium'); + print ''; - - print ''; - print ''; - - print '
'; - $htmltext = $langs->trans("ID").': '.$obj->id; - $htmltext .= '
'.$langs->trans("Permission").': user->hasRight(\''.dol_escape_htmltag($obj->module).'\', \''.dol_escape_htmltag($obj->perms).'\''.($obj->subperms ? ', \''.dol_escape_htmltag($obj->subperms).'\'' : '').')'; - print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block marginrightonly'); - //print ''.$obj->id.''; - print '
'; -print '
'; - -print ''; + });'; + print "\n"; -print ''; + // Button expand / collapse all + print '$(".showallperms").on("click", function(){ + console.log("Click on showallperms"); -// TODO : Build the hook management -// Other form for add user to group -//$parameters = array('caneditgroup' => $permissiontoeditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude); -//$reshook = $hookmanager->executeHooks('formAddUserToGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -//print $hookmanager->resPrint; + console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click"); + document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ "; + $(".tdforbreakperms").each( function(){ + moduletohide = $(this).data("hide-perms"); + //console.log(moduletohide); + if ($("#idforbreakperms_"+moduletohide).val() != 0) { + $(this).trigger("click"); // emulate the click, so the cooki will be resaved + } + }) + }); -include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; -print dolJSToSetRandomPassword('api_key', 'generate_api_key', 1); + $(".hideallperms").on("click", function(){ + console.log("Click on hideallperms"); + + $(".tdforbreakperms").each( function(){ + moduletohide = $(this).data("hide-perms"); + //console.log(moduletohide); + if ($("#idforbreakperms_"+moduletohide).val() != 1) { + $(this).trigger("click"); // emulate the click, so the cooki will be resaved + } + }) + });'; + print "\n"; + print ''; + + print ''; + + // TODO : Build the hook management + // Other form for add user to group + //$parameters = array('caneditgroup' => $permissiontoeditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude); + //$reshook = $hookmanager->executeHooks('formAddUserToGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + //print $hookmanager->resPrint; + +} + +if (isModEnabled('api') && $action == 'create') { + include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + print dolJSToSetRandomPassword('api_key', 'generate_api_key', 1); +} // End of page llxFooter(); diff --git a/htdocs/user/api_token/list.php b/htdocs/user/api_token/list.php index 6a3d13ad901..87fe5a33a1c 100644 --- a/htdocs/user/api_token/list.php +++ b/htdocs/user/api_token/list.php @@ -162,7 +162,7 @@ $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $morehtmlright = ''; //if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) { -$tmpurlforbutton = DOL_URL_ROOT.'/user/api_token/list.php?id='.$id.'&action=create'; +$tmpurlforbutton = DOL_URL_ROOT.'/user/api_token/card.php?id='.$id.'&action=create'; // TODO Permissions ? $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $tmpurlforbutton, '', $permtoeditline); $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $tmpurlforbutton); //}