diff --git a/doc/LS.entities.xml b/doc/LS.entities.xml
index a1849efe..5e6027c4 100644
--- a/doc/LS.entities.xml
+++ b/doc/LS.entities.xml
@@ -18,6 +18,7 @@
LSattribute">
LSattributes">
customActions">
+customActions">
LSrelation">
LSrelations">
LSform">
@@ -28,3 +29,4 @@
LSaddons">
LSauthMethod">
LSselect">
+LSsearch">
diff --git a/doc/conf/LSobject/LSsearch.docbook b/doc/conf/LSobject/LSsearch.docbook
index 7327bbd9..129a4bbd 100644
--- a/doc/conf/LSobject/LSsearch.docbook
+++ b/doc/conf/LSobject/LSsearch.docbook
@@ -52,6 +52,9 @@ configuration des &LSobjects;, dans la variable LSsearch
'[LSformat 2]'
)
)
+ ),
+ 'customActions' => array (
+ // Configuration des customActions pour les recherches de ce type d'objet
)
);]]>
@@ -269,7 +272,169 @@ contexte dans lequel cette recherche est effectuée.
+
+ customActions
+
+ Tableau associatif contenant les paramètres de configuration
+ des &customSearchActions;. Voir la section
+ concernée.
+
+
+
+
+ customActions
+ Cette section décrit la manière de configurer les actions personnalisées exécutables
+ sur les recherches d'&LSobjects; appelées &customSearchActions;.
+
+
+Structure
+ array(
+ 'label' => '[label l'action]',
+ 'hideLabel' => '[booléen]',
+ 'icon' => '[nom de l'icône de l'action]',
+ 'function' => '[fonction à exécuter]',
+ 'question_format' => '[LSformat de la question de confirmation]',
+ 'onSuccessMsgFormat' => '[LSformat du message à afficher en cas de succès de l'action]',
+ 'disableOnSuccessMsg' => '[booléen]',
+ 'noConfirmation' => '[booléen]',
+ 'redirectToObjectList' => '[booléen]',
+ 'rights' => array(
+ 'LSprofile1',
+ 'LSprofile2',
+ ...
+ )
+ )
+);]]>
+
+
+
+Paramètres de configuration
+
+
+ label
+
+ Le label de l'action.
+
+
+
+
+ hideLabel
+
+ Cache le label dans le bouton de l'action.
+
+
+
+
+ icon
+
+ Nom de l'îcone à afficher dans le bouton de l'action. Ce nom correspond
+ au nom du fichier de l'image (sans l'extention) qui devra se trouver dans le
+ dossier /public_html/images/[nom du theme d'images]/.
+
+
+
+
+ function
+
+ Le nom de la fonction à exécuter qui implémente l'action personnalisée
+ Cette fonction prendra en seule paramètre l'objet &LSsearch; sur lequel l'action
+ devra être exécutée et retournera True en cas de succès ou
+ False en cas d'échec d'exécution de la fonction.
+
+
+
+
+ question_format
+
+ Le &LSformat; de la question de confirmation d'exécution de l'action.
+ Ce &LSformat; sera composé à l'aide du label de l'action.
+
+
+
+
+ onSuccessMsgFormat
+
+ Le &LSformat; du message à afficher en cas de succès d'exécution de
+ l'action. Ce &LSformat; sera composé à l'aide du label de l'action.
+
+
+
+
+ disableOnSuccessMsg
+
+ Booléen permetant de désactiver le message afficher en cas de succès
+ d'exécution de l'action.
+
+
+
+
+ noConfirmation
+
+ Booléen permetant de désactiver la confirmation de l'exécution de
+ l'action.
+
+
+
+
+ redirectToObjectList
+
+ Booléen permetant de rediriger ou non l'utilisateur vers la liste
+ des objets (Vrai par défaut). Si l'utilisateur n'est redirigé, le template
+ par défaut (ou celui défini durant l'éxécution de la fonction) sera affiché.
+
+
+
+
+
+ rights
+
+ Tableau contenant la liste des noms des &LSprofiles; ayant le droit
+ d'exécuter cette action.
+
+
+
+
+
+
+ Ecriture d'une fonction implémentant une customAction
+ Une fonction implémentant une customAction se déclare de
+ la manière suivante :
+
+Cette fonction doit prendre pour seul paramètre, l'objet &LSsearch; sur lequel l'action
+personnalisée doit être exécutée et doit retourner soit True si
+tout s'est bien passé, soit False en cas de problème.
+
+La recherche passée en paramètre n'a pas encore été exécutée. En conséquence,
+si vous avez besoin d'accéder au résultat de la recherche, il est nécessaire d'exécuter au préalable :
+$search -> run();. Cela permet en outre, de modifier les paramètres de la recherche
+avant de l'exécuter. Cela peut par exemple être utile, si vous avez besoin d'accèder aux valeurs
+d'attributs particuliers, d'ajouter des attributs au résultat de la recherche :
+$search -> setParam('attributes',array('attr1','attr2'));.
+
+Ces fonctions sont le plus couramment définies au sein d'&LSaddon;.
+
+
+
+
+
diff --git a/public_html/custom_search_action.php b/public_html/custom_search_action.php
new file mode 100644
index 00000000..b223ef90
--- /dev/null
+++ b/public_html/custom_search_action.php
@@ -0,0 +1,100 @@
+ setParam('extraDisplayedColumns',True);
+ $LSsearch -> setParamsFormPostData();
+
+ if ( LSsession :: canExecuteLSsearchCustomAction($LSsearch,$customAction) ) {
+ $config = LSconfig :: get('LSobjects.'.$LSobject.'.LSsearch.customActions.'.$customAction);
+ if (isset($config['function']) && is_callable($config['function'])) {
+ if (isset($config['label'])) {
+ $title=__($config['label']);
+ }
+ else {
+ $title=__($customAction);
+ }
+ if (isset($_GET['valid']) || $config['noConfirmation']) {
+ LStemplate :: assign('pagetitle',$title);
+ if ($config['function']($LSsearch)) {
+ if ($config['disableOnSuccessMsg']!=true) {
+ if ($config['onSuccessMsgFormat']) {
+ LSsession :: addInfo(getFData(__($config['onSuccessMsgFormat']),$objectname));
+ }
+ else {
+ LSsession :: addInfo(getFData(_('The custom action %{title} have been successfully execute this search.'),$title));
+ }
+ }
+ if (!isset($config['redirectToObjectList']) || $config['redirectToObjectList']) {
+ LSsession :: redirect('view.php?LSobject='.$LSobject.'&refresh');
+ }
+ }
+ else {
+ LSerror :: addErrorCode('LSsearch_16',$customAction);
+ }
+ }
+ else {
+ $question=(
+ isset($config['question_format'])?
+ getFData(__($config['question_format']),$title):
+ getFData(_('Do you really want to execute custom action %{title} on this search ?'),$title)
+ );
+ LStemplate :: assign('pagetitle',$title);
+ LStemplate :: assign('question',$question);
+ LStemplate :: assign('validation_url','custom_search_action.php?LSobject='.urlencode($LSobject).'&customAction='.urlencode($customAction).'&valid');
+ LStemplate :: assign('validation_label',_('Validate'));
+ LSsession :: setTemplate('question.tpl');
+ }
+ }
+ else {
+ LSerror :: addErrorCode('LSsession_13');
+ }
+ }
+ else {
+ LSerror :: addErrorCode('LSsession_11');
+ }
+ }
+ else {
+ LSsession :: addErrorCode('LSsession_05','LSsearch');
+ }
+ }
+ else {
+ LSerror :: addErrorCode('LSsession_12');
+ }
+
+}
+else {
+ LSsession :: setTemplate('login.tpl');
+}
+
+// Affichage des retours d'erreurs
+LSsession :: displayTemplate();
+?>
diff --git a/public_html/includes/class/class.LSsearch.php b/public_html/includes/class/class.LSsearch.php
index cecacf2c..edcff017 100644
--- a/public_html/includes/class/class.LSsearch.php
+++ b/public_html/includes/class/class.LSsearch.php
@@ -1011,6 +1011,7 @@ class LSsearch {
**/
public function __get($key) {
$params = array (
+ 'basedn',
'sortBy',
'sortDirection'
);
@@ -1314,5 +1315,6 @@ _("LSsearch : The function of the custum information %{name} is not callable.")
LSerror :: defineError('LSsearch_15',
_("LSsearch : Invalid predefinedFilter for LSobject type %{type} : %{label} (filter : %{filter}).")
);
-
-?>
+LSerror :: defineError('LSsearch_16',
+_("LSsearch : Error during execution of the custom action %{customAction}.")
+);
diff --git a/public_html/includes/class/class.LSsession.php b/public_html/includes/class/class.LSsession.php
index 934c82ab..8d308825 100644
--- a/public_html/includes/class/class.LSsession.php
+++ b/public_html/includes/class/class.LSsession.php
@@ -1896,6 +1896,35 @@ class LSsession {
return;
}
+ /**
+ * Retourne le droit de l'utilisateur a executer une customAction
+ * sur une recherche
+ *
+ * @param[in] string $LSsearch L'objet LSsearch
+ * @param[in] string $customActionName Le nom de la customAction
+ *
+ * @retval boolean True si l'utilisateur peut executer cette customAction, false sinon
+ */
+ public static function canExecuteLSsearchCustomAction($LSsearch,$customActionName) {
+ $conf=LSconfig :: get('LSobjects.'.$LSsearch -> LSobject.'.LSsearch.customActions.'.$customActionName);
+ if (!is_array($conf))
+ return;
+ $dn=$LSsearch -> basedn;
+ if (is_null($dn)) $dn=self::getTopDn();
+
+ $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
*
diff --git a/public_html/lang/generate_lang_file.php b/public_html/lang/generate_lang_file.php
index 1d525002..be921633 100755
--- a/public_html/lang/generate_lang_file.php
+++ b/public_html/lang/generate_lang_file.php
@@ -127,6 +127,14 @@ if (loadDir('../'.LS_OBJECTS_DIR) && loadDir('../'.LS_LOCAL_DIR.LS_OBJECTS_DIR))
add($cconf['label']);
}
}
+ if (is_array($conf['LSsearch']['customActions'])) {
+ foreach($conf['LSsearch']['customActions'] as $act) {
+ add($act['label']);
+ add($act['question_format']);
+ add($act['onSuccessMsgFormat']);
+ }
+ }
+
if(is_array($conf['attrs'])) {
diff --git a/public_html/view.php b/public_html/view.php
index 78afd767..0b996c4b 100644
--- a/public_html/view.php
+++ b/public_html/view.php
@@ -151,6 +151,23 @@ if(LSsession :: startLSsession()) {
'url' => 'view.php?LSobject='.$LSobject.'&LSsearchPurgeSession',
'action' => 'delete'
);*/
+
+ // Custum Actions
+ $customActionsConfig = LSconfig :: get('LSobjects.'.$LSobject.'.LSsearch.customActions');
+ if (is_array($customActionsConfig)) {
+ foreach($customActionsConfig as $name => $config) {
+ if (LSsession :: canExecuteLSsearchCustomAction($LSsearch,$name)) {
+ $LSview_actions[] = array (
+ 'label' => ((isset($config['label']))?__($config['label']):__($name)),
+ 'hideLabel' => ((isset($config['hideLabel']))?$config['hideLabel']:False),
+ 'url' => 'custom_search_action.php?LSobject='.$LSobject.'&customAction='.$name,
+ 'action' => ((isset($config['icon']))?$config['icon']:'generate'),
+ 'class' => 'LScustomActions'.(($config['noConfirmation'])?' LScustomActions_noConfirmation':'')
+ );
+ }
+ }
+ }
+
LStemplate :: assign('LSview_actions',$LSview_actions);
$LSsearch -> run();