2008-02-26 18:40:05 +01:00
|
|
|
<?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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
require_once 'core.php';
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
if(LSsession :: startLSsession()) {
|
2008-02-26 18:40:05 +01:00
|
|
|
if (isset($_REQUEST['LSobject'])) {
|
|
|
|
$LSobject = $_REQUEST['LSobject'];
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
if ( LSsession ::loadLSobject($LSobject) ) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$objectList=array();
|
|
|
|
$object = new $LSobject();
|
|
|
|
|
|
|
|
$GLOBALS['Smarty']->assign('pagetitle',$object -> getLabel());
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_objectname',$object -> getLabel());
|
|
|
|
|
|
|
|
if (isset($_SESSION['LSsession']['LSsearch'][$LSobject])) {
|
|
|
|
$filter = $_SESSION['LSsession']['LSsearch'][$LSobject]['filter'];
|
2009-01-24 18:45:14 +01:00
|
|
|
if (isCompatibleDNs($_SESSION['LSsession']['LSsearch'][$LSobject]['topDn'],LSsession :: getTopDn())) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$topDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['topDn'];
|
2008-07-29 18:30:34 +02:00
|
|
|
if (isset($_SESSION['LSsession']['LSsearch'][$LSobject]['selectedTopDn'])) {
|
|
|
|
$selectedTopDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['selectedTopDn'];
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
$selectedTopDn = LSsession :: getTopDn();
|
2008-07-29 18:30:34 +02:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
$selectedTopDn = LSsession :: getTopDn();
|
|
|
|
$topDn = $object -> config['container_dn'].','.LSsession :: getTopDn();
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
$params = $_SESSION['LSsession']['LSsearch'][$LSobject]['params'];
|
|
|
|
$pattern = $_SESSION['LSsession']['LSsearch'][$LSobject]['pattern'];
|
|
|
|
$recur = $_SESSION['LSsession']['LSsearch'][$LSobject]['recur'];
|
|
|
|
$approx = $_SESSION['LSsession']['LSsearch'][$LSobject]['approx'];
|
2008-06-20 17:52:15 +02:00
|
|
|
$orderby = $_SESSION['LSsession']['LSsearch'][$LSobject]['orderby'];
|
|
|
|
$ordersense = $_SESSION['LSsession']['LSsearch'][$LSobject]['ordersense'];
|
|
|
|
$doSubDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['doSubDn'];
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filter = NULL;
|
2009-01-24 18:45:14 +01:00
|
|
|
$topDn = $object -> config['container_dn'].','.LSsession :: getTopDn();
|
2008-06-18 14:27:35 +02:00
|
|
|
$params = array('scope' => 'one');
|
|
|
|
$pattern = false;
|
2009-04-10 19:13:38 +02:00
|
|
|
$recur = LSconfig :: get("LSobjects.$LSobject.LSsearch.recursive");
|
2008-06-18 14:27:35 +02:00
|
|
|
$approx = false;
|
2009-01-24 18:45:14 +01:00
|
|
|
$selectedTopDn = LSsession :: getTopDn();
|
2008-06-20 17:52:15 +02:00
|
|
|
$orderby = false;
|
2009-03-25 18:46:48 +01:00
|
|
|
$_REQUEST['orderby']=LSconfig :: get("LSobjects.$LSobject.orderby");
|
2008-06-20 17:52:15 +02:00
|
|
|
$ordersense = 'ASC';
|
2009-01-24 18:45:14 +01:00
|
|
|
$subDnLdapServer = LSsession :: getSubDnLdapServer();
|
|
|
|
$doSubDn = (($subDnLdapServer)&&(!LSsession :: isSubDnLSobject($LSobject)));
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_REQUEST['LSview_search_submit'])) {
|
2008-07-05 22:28:49 +02:00
|
|
|
if ( $_REQUEST['LSview_pattern']!=$pattern ) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$pattern = $_REQUEST['LSview_pattern'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$approx = (isset($_REQUEST['LSview_approx']));
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
if ($pattern && $pattern!='') {
|
2009-01-25 18:43:30 +01:00
|
|
|
$filter=$object -> getPatternFilter($pattern,$approx);
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-06-18 14:27:35 +02:00
|
|
|
$filter = NULL;
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
|
|
|
|
if (isset($_REQUEST['LSview_recur'])) {
|
|
|
|
$recur = true;
|
2008-04-25 15:48:12 +02:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
else {
|
|
|
|
$recur = false;
|
2009-04-10 19:36:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($recur) {
|
|
|
|
$params['scope'] = 'sub';
|
|
|
|
if (LSsession :: validSubDnLdapServer($_REQUEST['LSselect_topDn'])) {
|
|
|
|
$topDn = $_REQUEST['LSselect_topDn'];
|
|
|
|
$selectedTopDn = $topDn;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$topDn = LSsession :: getTopDn();
|
|
|
|
$selectedTopDn = $topDn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$params['scope'] = 'one';
|
|
|
|
if (LSsession :: validSubDnLdapServer($_REQUEST['LSselect_topDn'])) {
|
|
|
|
$topDn = $object -> config['container_dn'].','.$_REQUEST['LSselect_topDn'];
|
|
|
|
$selectedTopDn = $_REQUEST['LSselect_topDn'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$topDn = $object -> config['container_dn'].','.LSsession :: getTopDn();
|
|
|
|
$selectedTopDn = LSsession :: getTopDn();
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
2008-06-20 17:52:15 +02:00
|
|
|
$sort=false;
|
|
|
|
if ((isset($_REQUEST['orderby']))) {
|
2009-01-07 20:58:08 +01:00
|
|
|
$possible_values= array('displayName','subDn');
|
2008-06-20 17:52:15 +02:00
|
|
|
if (in_array($_REQUEST['orderby'],$possible_values)) {
|
|
|
|
$sort=true;
|
|
|
|
if ($orderby==$_REQUEST['orderby']) {
|
|
|
|
$ordersense = ($ordersense=='ASC')?'DESC':'ASC';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ordersense = 'ASC';
|
|
|
|
}
|
|
|
|
$orderby=$_REQUEST['orderby'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_subDn',$doSubDn);
|
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
// Sauvegarde en Session
|
|
|
|
$_SESSION['LSsession']['LSsearch'][$LSobject] = array(
|
|
|
|
'filter' => $filter,
|
|
|
|
'topDn' => $topDn,
|
|
|
|
'params' => $params,
|
|
|
|
'pattern' => $pattern,
|
|
|
|
'recur' => $recur,
|
|
|
|
'approx' => $approx,
|
2008-06-20 17:52:15 +02:00
|
|
|
'selectedTopDn' => $selectedTopDn,
|
|
|
|
'orderby' => $orderby,
|
|
|
|
'ordersense' => $ordersense,
|
|
|
|
'doSubDn' => $doSubDn
|
2008-06-18 14:27:35 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_pattern',$pattern);
|
|
|
|
|
|
|
|
if ($recur) {
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_recur',true);
|
|
|
|
}
|
|
|
|
if ($approx) {
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_approx',true);
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty']->assign('LSselect_topDn',$selectedTopDn);
|
|
|
|
|
2008-09-28 13:05:02 +02:00
|
|
|
$multiple = (isset($_REQUEST['multiple']))?1:0;
|
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
// Hidden fields
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array(
|
|
|
|
'LSobject' => $LSobject,
|
|
|
|
'LSview_search_submit' => 1,
|
2008-09-28 13:05:02 +02:00
|
|
|
'ajax' => 1,
|
|
|
|
'multiple' => $multiple
|
2008-06-18 14:27:35 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
// Hash de la recherche déterminer à partir des paramètres de la recherche
|
|
|
|
$hash = mhash (MHASH_MD5,
|
|
|
|
print_r(
|
|
|
|
array(
|
|
|
|
'LSobject' => $LSobject,
|
|
|
|
'filter' => $filter,
|
|
|
|
'topDn' => $topDn,
|
|
|
|
'params' => $params
|
|
|
|
),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
if ((LSsession :: cacheSearch()) && isset($_SESSION['LSsession']['LSsearch'][$hash]) && (!isset($_REQUEST['refresh']))) {
|
2008-06-18 14:27:35 +02:00
|
|
|
// On affiche à partir du cache
|
|
|
|
$searchData=$_SESSION['LSsession']['LSsearch'][$hash];
|
2008-09-26 20:03:56 +02:00
|
|
|
LSdebug('From cache');
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-09-26 20:03:56 +02:00
|
|
|
LSdebug('Load');
|
2008-06-18 14:27:35 +02:00
|
|
|
$LSview_actions[] = array (
|
2009-02-12 13:38:56 +01:00
|
|
|
'label' => _('Refresh'),
|
2008-06-18 14:27:35 +02:00
|
|
|
'url' => 'view.php?LSobject='.$LSobject.'&refresh',
|
|
|
|
'action' => 'refresh'
|
|
|
|
);
|
|
|
|
|
2008-11-09 02:40:18 +01:00
|
|
|
$list=$object -> listObjectsName($filter,$topDn,$params);
|
2008-06-18 14:27:35 +02:00
|
|
|
$nbObjects=count($list);
|
|
|
|
$searchData['LSobject_list_nbresult']=$nbObjects;
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
$c=0;
|
2008-06-18 14:27:35 +02:00
|
|
|
|
2008-11-09 02:40:18 +01:00
|
|
|
foreach($list as $objDn => $objName) {
|
2009-01-24 18:45:14 +01:00
|
|
|
if (LSsession :: canAccess($LSobject,$objDn)) {
|
2008-06-18 14:27:35 +02:00
|
|
|
|
|
|
|
$c++;
|
|
|
|
unset($actions);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
$subDn_name=false;
|
2008-06-20 17:52:15 +02:00
|
|
|
if ($doSubDn) {
|
2008-11-09 02:40:18 +01:00
|
|
|
$subDn_name = $object -> getSubDnName($objDn);
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$objectList[]=array(
|
2008-11-09 02:40:18 +01:00
|
|
|
'dn' => $objDn,
|
2009-01-07 20:58:08 +01:00
|
|
|
'displayName' => $objName,
|
2008-06-18 14:27:35 +02:00
|
|
|
'subDn' => $subDn_name
|
2008-02-26 18:40:05 +01:00
|
|
|
);
|
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
else {
|
2008-11-09 02:40:18 +01:00
|
|
|
LSdebug($dn);
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
$searchData['objectList']=$objectList;
|
|
|
|
$searchData['LSview_actions'] = $LSview_actions;
|
2009-01-24 18:45:14 +01:00
|
|
|
if (LSsession :: cacheSearch()) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$_SESSION['LSsession']['LSsearch'][$hash]=$searchData;
|
|
|
|
}
|
2008-07-15 18:24:35 +02:00
|
|
|
if ($orderby) {
|
|
|
|
$sort=true;
|
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_nbresult',$searchData['LSobject_list_nbresult']);
|
|
|
|
|
2008-06-20 17:52:15 +02:00
|
|
|
// Order by if $sort
|
|
|
|
if ($sort) {
|
|
|
|
function sortBy($a,$b) {
|
|
|
|
global $ordersense;
|
|
|
|
global $orderby;
|
|
|
|
|
|
|
|
if ($ordersense=='ASC') {
|
|
|
|
$sense = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sense = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($a == $b) return 0;
|
|
|
|
$sort = array($a[$orderby],$b[$orderby]);
|
|
|
|
sort($sort);
|
|
|
|
if ($sort[0]==$a[$orderby])
|
|
|
|
return 1*$sense;
|
|
|
|
return -1*$sense;
|
|
|
|
}
|
|
|
|
if (!uasort($searchData['objectList'],'sortBy')) {
|
2008-09-26 20:03:56 +02:00
|
|
|
LSdebug('Erreur durant le trie.');
|
2008-06-20 17:52:15 +02:00
|
|
|
}
|
|
|
|
$_SESSION['LSsession']['LSsearch'][$hash]=$searchData;
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_orderby',$orderby);
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense);
|
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
// Pagination
|
2008-09-28 13:05:02 +02:00
|
|
|
if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST_SELECT) {
|
2008-06-18 14:27:35 +02:00
|
|
|
if (isset($_REQUEST['page'])) {
|
2008-09-28 13:05:02 +02:00
|
|
|
$searchData['objectList'] = array_slice($searchData['objectList'], ($_REQUEST['page']) * NB_LSOBJECT_LIST_SELECT, NB_LSOBJECT_LIST_SELECT);
|
2008-06-18 14:27:35 +02:00
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',$_REQUEST['page']);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2008-09-28 13:05:02 +02:00
|
|
|
$searchData['objectList'] = array_slice($searchData['objectList'], 0, NB_LSOBJECT_LIST_SELECT);
|
2008-06-18 14:27:35 +02:00
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',0);
|
|
|
|
}
|
2008-09-28 13:05:02 +02:00
|
|
|
$searchData['LSobject_list_nbpage']=ceil($searchData['LSobject_list_nbresult'] / NB_LSOBJECT_LIST_SELECT);
|
2008-06-18 14:27:35 +02:00
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']);
|
|
|
|
}
|
|
|
|
|
2008-06-20 17:52:15 +02:00
|
|
|
// Select/Pas Select
|
2008-06-18 14:27:35 +02:00
|
|
|
for($i=0;$i<count($searchData['objectList']);$i++) {
|
|
|
|
if (is_array($_SESSION['LSselect'][$LSobject])) {
|
|
|
|
if(in_array($searchData['objectList'][$i]['dn'],$_SESSION['LSselect'][$LSobject])) {
|
|
|
|
$select = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$select = false;
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-06-18 14:27:35 +02:00
|
|
|
$select = false;
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
$searchData['objectList'][$i]['select']=$select;
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search',array(
|
|
|
|
'action' => $_SERVER['PHP_SELF'],
|
2009-02-12 13:38:56 +01:00
|
|
|
'submit' => _('Search'),
|
2008-06-18 14:27:35 +02:00
|
|
|
'LSobject' => $LSobject
|
|
|
|
));
|
|
|
|
|
2009-02-12 13:38:56 +01:00
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_recur_label',_('Recursive search'));
|
|
|
|
$GLOBALS['Smarty']->assign('LSview_search_approx_label',_('Approximative search'));
|
2008-06-18 14:27:35 +02:00
|
|
|
|
2009-02-12 13:38:56 +01:00
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_without_result_label',_("This search didn't get any result."));
|
2008-06-18 14:27:35 +02:00
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']);
|
|
|
|
$GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']);
|
2008-09-28 13:05:02 +02:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSselect_multiple',$multiple);
|
2008-06-18 14:27:35 +02:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setTemplate('select_table.tpl');
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setTemplate('select.tpl');
|
2008-06-18 14:27:35 +02:00
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setAjaxDisplay();
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSsession_12');
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setTemplate('login.tpl');
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Affichage des retours d'erreurs
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: displayTemplate();
|
2008-02-26 18:40:05 +01:00
|
|
|
?>
|