Add globalSearch feature

This commit is contained in:
Benjamin Renard 2019-05-21 12:06:24 +02:00
parent 7f13464230
commit f130804aae
10 changed files with 296 additions and 1 deletions

View file

@ -68,6 +68,8 @@
// Configuration des recherches de l'objet
), // fin LSsearch
'globalSearch' => [booleen],
// ioFormat
'ioFormat' => array (
// Configuration des formats d'import/export de l'objet
@ -264,6 +266,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term>globalSearch</term>
<listitem>
<simpara>Inclure ou non ce type d'objet dans le résultat des recherches globales
(Par défaut : <literal>True</literal>).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>ioFormat</term>
<listitem>

View file

@ -115,6 +115,18 @@ define('CONST2','val2')
</varlistentry>
<varlistentry>
<term>globalSearch</term>
<listitem>
<simpara>Activation/Désactivation de la recherche globale dans l'annuaire.
</simpara>
<simpara>Valeurs possibles : <emphasis>True</emphasis> ou
<emphasis>False</emphasis></simpara>
<simpara>Valeur par défaut : <emphasis>True</emphasis></simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>keepLSsessionActive</term>
<listitem>

View file

@ -25,6 +25,7 @@ serveur LDAP.</para>
),
'cacheLSprofiles' => [boolean],
'cacheSearch' => [boolean],
'globalSearch' => [boolean],
'authObjectType' => [LSobject],
'authObjectFilter' => [LSformat],
'authObjectTypeAttrPwd' => [attribut],
@ -129,6 +130,16 @@ serveur LDAP.</para>
</varlistentry>
<varlistentry>
<term>globalSearch</term>
<listitem>
<simpara>Activation/Désactivation de la recherche globale sur ce serveur
en particulier. Par defaut, la valeur du paramètre global
<literal>globalSearch</literal> est utilisée.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>authObjectType</term>
<listitem>

View file

@ -104,6 +104,16 @@ a img {
* Menu
******************
*/
form.LSglobal_search {
margin-top: 0.8em;
}
input.LSglobal_search {
background: url(../../images/default/find.png) no-repeat right #fff;
padding-right: 18px;
width: 138px!important;
}
ul.menu {
list-style-image: url(../../images/default/puce.png);
}

View file

@ -0,0 +1,110 @@
<?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 (LSsession :: globalSearch()) {
$LSobjects = LSsession :: $ldapServer['LSaccess'];
$pattern = (isset($_REQUEST['pattern'])?$_REQUEST['pattern']:'');
$LSview_actions=array();
$LSview_actions['refresh'] = array (
'label' => 'Refresh',
'url' => 'global_search.php?pattern='.urlencode($pattern).'&refresh=1',
'action' => 'refresh'
);
LStemplate :: assign('LSview_actions', $LSview_actions);
if (LSsession :: loadLSclass('LSform')) {
LSform :: loadDependenciesDisplayView();
}
$onlyOne = true;
$onlyOneObject = false;
if (LSsession :: loadLSclass('LSsearch')) {
$pages=array();
foreach ($LSobjects as $LSobject) {
if ( LSsession :: loadLSobject($LSobject) ) {
if (!LSconfig::get("LSobjects.$LSobject.globalSearch", true, 'bool'))
continue;
$object = new $LSobject();
LStemplate :: assign('pagetitle',$object -> getLabel());
$LSsearch = new LSsearch($LSobject,'LSview');
$LSsearch -> setParamsFormPostData();
$LSsearch -> run();
if ($LSsearch -> total > 0) {
$page = $LSsearch -> getPage(0);
LStemplate :: assign('page',$page);
LStemplate :: assign('LSsearch',$LSsearch);
$pages[] = LSsession :: fetchTemplate('global_search_one_page.tpl');
if ($onlyOne) {
if ($LSsearch -> total > 1) {
$onlyOne = false;
}
else {
if ($onlyOneObject === false) {
$onlyOneObject = array (
'LSobject' => $LSobject,
'dn' => $page['list'][0] -> dn,
);
}
else {
// More than one LSobject type result with one object found
$onlyOne = false;
}
}
}
}
}
}
}
else {
LSsession :: addErrorCode('LSsession_05','LSsearch');
}
if ($onlyOne && $onlyOneObject && isset($_REQUEST['LSsearch_submit'])) {
LSsession :: redirect('view.php?LSobject='.$onlyOneObject['LSobject'].'&dn='.urlencode($onlyOneObject['dn']));
}
LStemplate :: assign('pattern',$pattern);
LStemplate :: assign('pages',$pages);
LSsession :: setTemplate('global_search.tpl');
LStemplate :: addEvent('displayed', array($LSsearch, 'afterUsingResult'));
}
else {
LSerror :: addErrorCode('LSsession_11');
}
}
else {
LSsession :: setTemplate('login.tpl');
}
// Print template
LSsession :: displayTemplate();

View file

@ -532,6 +532,8 @@ class LSsession {
return;
}
LStemplate :: assign('globalSearch', self :: globalSearch());
if (isset($_GET['LSsession_logout'])) {
// Trigger LSauth logout
LSauth :: logout();
@ -632,6 +634,7 @@ class LSsession {
self :: loadLSaccess();
self :: loadLSaddonsViewsAccess();
LStemplate :: assign('LSsession_username',self :: getLSuserObject() -> getDisplayName());
LStemplate :: assign('globalSearch', self :: globalSearch());
$_SESSION['LSsession']=self :: getContextInfos();
return true;
}
@ -2259,6 +2262,17 @@ class LSsession {
return ( (LSconfig :: get('cacheSearch')) || (self :: $ldapServer['cacheSearch']));
}
/**
* Return true if global search is enabled
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean True if global search is enabled, false instead
*/
public static function globalSearch() {
return LSconfig :: get('globalSearch', LSconfig :: get('globalSearch', true, 'bool'), 'bool', self :: $ldapServer);
}
/**
* Retourne le label des niveaux pour le serveur ldap courant
*

View file

@ -71,6 +71,9 @@ $GLOBALS['LSlang'] = array (
"Given email address is invalid." =>
"L'adresse mail saisie est invalide.",
"Global search" =>
"Recherche globale",
"Godfather of ..." =>
"Parrain de ...",

View file

@ -0,0 +1,29 @@
{include file='ls:top.tpl'}
<form action='global_search.php' method='post' class='LSview_search' id='LSsearch_form'>
<div class='LSview_search'>
<input type='text' name='pattern' class='LSview_search' value='{$pattern|escape:"htmlall"}'/>
<input type='submit' value='{tr msg="Search"}' name='LSsearch_submit' class='LSview_search' />
</div>
<h1>{tr msg="Global search"}</h1>
{if $LSview_actions != ''}
<ul class='LSview-actions LSview_search'>
{foreach from=$LSview_actions item=item}
{if is_array($item)}
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions'><img src='{img name=$item.action}' alt='{tr msg=$label}' title='{tr msg=label}' /> {tr msg=$item.label}</a></li>
{/if}
{/foreach}
</ul>
{/if}
{foreach from=$pages item=page}
{$page}
{foreachelse}
<p style="text-align: center">{tr msg="This search didn't get any result."}</p>
{/foreach}
</form>
{include file='ls:bottom.tpl'}

View file

@ -0,0 +1,88 @@
<h2>
{$pagetitle}
</h2>
<table class='LSobject-list'>
<tr class='LSobject-list'>
<th class='LSobject-list'>
{if $LSsearch->sort}
<a href='view.php?LSobject={$LSsearch->LSobject}&amp;sortBy=displayName&amp;nocache={$smarty.now}'>
{if $LSsearch->sortBy == 'displayName'}
<strong>{$LSsearch->label_objectName|escape:'htmlall'}</strong>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_objectName|escape:'htmlall'}
{/if}
</a>
{else}
{$LSsearch->label_objectName|escape:'htmlall'}
{/if}
</th>
{if $LSsearch->displaySubDn}
<th class='LSobject-list LSobject-list-subdn'>
{if $LSsearch->sort}
<a href='view.php?LSobject={$LSsearch->LSobject}&amp;sortBy=subDn&amp;nocache={$smarty.now}'>
{if $LSsearch->sortBy == 'subDn'}
<strong>{$LSsearch->label_level|escape:'htmlall'}</strong>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_level|escape:'htmlall'}
{/if}
</a>
{else}
{$LSsearch->label_level|escape:'htmlall'}
{/if}
</th>
{/if}
<th class='LSobject-list'>{$LSsearch->label_actions}</th>
</tr>
{foreach from=$page.list item=object}
<tr class='{cycle values="LSobject-list,LSobject-list LSobject-list-bis"}'>
<td class='LSobject-list LSobject-list-names'><a href='view.php?LSobject={$LSsearch->LSobject|escape:'url'}&amp;dn={$object->dn|escape:'url'}' class='LSobject-list'>{$object->displayName|escape:'htmlall'}</a> </td>
{if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn|escape:'htmlall'}</td>{/if}
<td class='LSobject-list LSobject-list-actions'>
{foreach from=$object->actions item=item}
<a href='{$item.url|escape:'quotes'}' class='LSobject-list-actions'><img src='{img name=$item.action|escape:'url'}' alt='{$item.label|escape:'quotes'}' title='{$item.label|escape:'quotes'}'/></a>
{/foreach}
</td>
</tr>
{foreachelse}
<tr class='LSobject-list'>
<td colspan='3' class='LSobject-list-without-result'>{$LSsearch->label_no_result|escape:'htmlall'}</td>
</tr>
{/foreach}
</table>
<span id='LSobject_list_nbresult'>{$LSsearch->label_total|escape:'htmlall'}</span>
{if $page.nbPages > 1}
<p class='LSobject-list-page'>
{if $page.nbPages > 10}
{if $page.nb > 5}
{if $page.nb > $page.nbPages-6}
{assign var=start value=$page.nbPages-12}
{else}
{assign var=start value=$page.nb-6}
{/if}
{else}
{assign var=start value=0}
{/if}
<a href='view.php?LSobject={$LSsearch->LSobject|escape:'url'}&amp;page=0' class='LSobject-list-page'>&lt;</a>
{foreach from=0|range:10 item=i}
{if $page.nb==$start+$i}
<strong class='LSobject-list-page'>{$page.nb+1}</strong>
{else}
<a href='view.php?LSobject={$LSsearch->LSobject|escape:'url'}&amp;page={$i+$start}' class='LSobject-list-page'>{$i+$start+1}</a>
{/if}
{/foreach}
<a href='view.php?LSobject={$LSsearch->LSobject|escape:'url'}&amp;page={$page.nbPages-1}' class='LSobject-list-page'>&gt;</a>
{else}
{section name=listpage loop=$page.nbPages step=1}
{if $page.nb == $smarty.section.listpage.index}
<strong class='LSobject-list-page'>{$page.nb+1}</strong>
{else}
<a href='view.php?LSobject={$LSsearch->LSobject|escape:'url'}&amp;page={$smarty.section.listpage.index}' class='LSobject-list-page'>{$smarty.section.listpage.index+1}</a>
{/if}
{/section}
{/if}
</p>
{/if}

View file

@ -28,6 +28,14 @@
</label>
</form>
{/if}
{if $globalSearch}
<form action='global_search.php' method='post' class='LSview_search LSglobal_search'>
<input type='hidden' name='LSsearch_submit' value='1'/>
<input type='text' name='pattern' class='LSview_search LSglobal_search' placeholder='{tr msg='Global search'}'/>
</form>
{/if}
<ul class='menu'>
{foreach from=$LSaccess item=label key=LSobject_type}
<li class='menu'><a href='view.php?LSobject={$LSobject_type|escape:"url"}' class='menu'>{tr msg=$label}</a></li>