mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-26 03:43:08 +01:00
Added custum action feature
This commit is contained in:
parent
8336c0c647
commit
da80c71268
4 changed files with 157 additions and 1 deletions
104
public_html/custom_action.php
Normal file
104
public_html/custom_action.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
require_once 'core.php';
|
||||
|
||||
if(LSsession :: startLSsession()) {
|
||||
|
||||
if ((isset($_GET['LSobject'])) && (isset($_GET['dn'])) && (isset($_GET['customAction']))) {
|
||||
|
||||
if (LSsession ::loadLSobject($_GET['LSobject'])) {
|
||||
if ( LSsession :: canExecuteCustomAction($_GET['dn'],$_GET['LSobject'],$_GET['customAction']) ) {
|
||||
$object = new $_GET['LSobject']();
|
||||
if ($object -> loadData($_GET['dn'])) {
|
||||
$config = LSconfig :: get('LSobjects.'.$_GET['LSobject'].'.customActions.'.$_GET['customAction']);
|
||||
if (isset($config['function']) && is_callable($config['function'])) {
|
||||
if (isset($config['label'])) {
|
||||
$title=__($config['label']);
|
||||
}
|
||||
else {
|
||||
$title=__($_GET['customAction']);
|
||||
}
|
||||
if (isset($_GET['valid'])) {
|
||||
$objectname=$object -> getDisplayName();
|
||||
$GLOBALS['Smarty'] -> assign('pagetitle',$title.' : '.$objectname);
|
||||
if ($config['function']($object)) {
|
||||
if ($config['onSuccessMsgFormat']) {
|
||||
|
||||
}
|
||||
else {
|
||||
LSsession :: addInfo(getFData(_('The custom action %{customAction} have been successfully execute on %{objectname}.'),array('objectname' => $objectname,'customAction' => $_GET['customAction'])));
|
||||
}
|
||||
LSsession :: redirect('view.php?LSobject='.$_GET['LSobject'].'&refresh');
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSldapObject_15',$objectname);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$objectname=$object -> getDisplayName();
|
||||
$question=(
|
||||
isset($config['question_format'])?
|
||||
getFData(__($config['question_format']),$objectname):
|
||||
getFData(
|
||||
_('Do you really want to execute custom action %{customAction} on %{objectname} ?'),
|
||||
array(
|
||||
'objectname' => $objectname,
|
||||
'customAction' => $_GET['customAction']
|
||||
)
|
||||
)
|
||||
);
|
||||
$GLOBALS['Smarty'] -> assign('pagetitle',$title.' : '.$objectname);
|
||||
$GLOBALS['Smarty'] -> assign('question',$question);
|
||||
$GLOBALS['Smarty'] -> assign('validation_url','custom_action.php?LSobject='.$_GET['LSobject'].'&dn='.$_GET['dn'].'&customAction='.$_GET['customAction'].'&valid');
|
||||
$GLOBALS['Smarty'] -> assign('validation_label',_('Validate'));
|
||||
}
|
||||
LSsession :: setTemplate('question.tpl');
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_13');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_12');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_11');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSldapObject_01');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_12');
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
LSsession :: setTemplate('login.tpl');
|
||||
}
|
||||
|
||||
// Affichage des retours d'erreurs
|
||||
LSsession :: displayTemplate();
|
||||
?>
|
|
@ -1884,6 +1884,32 @@ class LSsession {
|
|||
return self :: relationCanAccess($dn,$LSobject,$relationName,'w');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le droit de l'utilisateur a executer une customAction
|
||||
*
|
||||
* @param[in] string $dn Le DN de l'objet
|
||||
* @param[in] string $LSobject Le type de l'objet
|
||||
* @param[in] string $customActionName Le nom de la customAction
|
||||
*
|
||||
* @retval boolean True si l'utilisateur peut executer cette customAction, false sinon
|
||||
*/
|
||||
public static function canExecuteCustomAction($dn,$LSobject,$customActionName) {
|
||||
$conf=LSconfig :: get('LSobjects.'.$LSobject.'.customActions.'.$customActionName);
|
||||
if (!is_array($conf))
|
||||
return;
|
||||
$whoami = self :: whoami($dn);
|
||||
|
||||
if (isset($conf['rights']) && is_array($conf['rights'])) {
|
||||
foreach($whoami as $who) {
|
||||
if (in_array($who,$conf['rights'])) {
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute un fichier temporaire
|
||||
*
|
||||
|
@ -2169,7 +2195,10 @@ class LSsession {
|
|||
LSerror :: defineError('LSsession_12',
|
||||
_("LSsession : Some informations are missing to display this page.")
|
||||
);
|
||||
// 13 -> 16 : not yet used
|
||||
LSerror :: defineError('LSsession_13',
|
||||
_("LSsession : The function of the custom action %{name} does not exists or is not configured.")
|
||||
);
|
||||
// 14 -> 16 : not yet used
|
||||
LSerror :: defineError('LSsession_17',
|
||||
_("LSsession : Error during creation of list of levels. Contact administrators. (Code : %{code})")
|
||||
);
|
||||
|
|
|
@ -71,6 +71,15 @@ if (loadDir('../'.LS_OBJECTS_DIR)) {
|
|||
add($rel['emptyText']);
|
||||
}
|
||||
}
|
||||
// Custom Actions
|
||||
if (is_array($conf['customActions'])) {
|
||||
foreach($conf['customActions'] as $act) {
|
||||
add($act['label']);
|
||||
add($act['question_format']);
|
||||
add($act['onSuccessMsgFormat']);
|
||||
}
|
||||
}
|
||||
|
||||
// LSform
|
||||
if (is_array($conf['LSform']['layout'])) {
|
||||
foreach($conf['LSform']['layout'] as $lay) {
|
||||
|
|
|
@ -62,6 +62,20 @@ if(LSsession :: startLSsession()) {
|
|||
);
|
||||
}
|
||||
|
||||
// Custum Actions
|
||||
$customActionsConfig = LSconfig :: get('LSobjects.'.$LSobject.'.customActions');
|
||||
if (is_array($customActionsConfig)) {
|
||||
foreach($customActionsConfig as $name => $config) {
|
||||
if (LSsession :: canExecuteCustomAction($dn,$LSobject,$name)) {
|
||||
$LSview_actions[] = array (
|
||||
'label' => ((isset($config['label']))?__($config['label']):__($name)),
|
||||
'url' => 'custom_action.php?LSobject='.$LSobject.'&dn='.$dn.'&customAction='.$name,
|
||||
'action' => ((isset($config['icon']))?$config['icon']:'generate')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LSsession :: getLSuserObjectDn() != $dn) {
|
||||
$object = new $LSobject();
|
||||
$object -> loadData($dn);
|
||||
|
|
Loading…
Reference in a new issue