- LSldapObject : Ajout des méthodes suivantes :

-> getSubDnValue()
  -> getSubDnName()
- LSview/LSselect : utilisation de la méthode getSubDnName() plutôt que le
  code en local
- config.inc.php :
  -> Modification du paramètre ldapServer['subDn']
  -> Ajout du paramètre LSaccess pour la composition du menu hors config subDn
  -> Suppression ldapServer['LSobjets'] : suppression du pré-chargement
     (cf.ci-dessous)
- LSsession :
  -> Rédéfinition de la méthode de construction du menu de l'interface
     (bug #1665)
  -> Mise en cache de LSaccess
  -> top.tpl : le bouton de rafraichissement subDn devient un bouton de
     rafraichissement génerale de LSsession (config / LSaccess / subDn)
  -> Suppression du pré-chargement des objets et donc de la méthode
     loadLSobjects()
  -> Ajout d'une méthode in_menu() utilisé entre par la méthode canAccess()
     pour valider les accès aux objets
- create.php : Correction d'un bug de chargement d'objet.
- config.error_code.php : Correction bug encodage
- index_ajax.php :
  -> Correction de bugs de chargement d'objets
  -> Suppression du code de gestion des retours d'erreur multiplié et inutile
This commit is contained in:
Benjamin Renard 2008-06-21 16:16:15 +00:00
parent a8931db30d
commit 7f82e8eb49
9 changed files with 657 additions and 557 deletions

View file

@ -248,7 +248,7 @@ $GLOBALS['LSerror_code'] = array (
'level' => 'c'
),
1011 => array (
'msg' => _("LSsession : Vous n'êtes pas authorisé à effectuer cette action."),
'msg' => _("LSsession : Vous n'êtes pas authorisé à  effectuer cette action."),
'level' => 'c'
),
1012 => array (

View file

@ -54,10 +54,15 @@ $GLOBALS['LSconfig'] = array(
)
)
),
'cacheLSrights' => false,
'cacheLSrights' => true,
'cacheSearch' => true,
'authobject' => 'LSeepeople',
'authobject_pwdattr' => 'userPassword',
'LSaccess' => array(
'LSeepeople',
'LSeegroup',
'LSeecompany'
),
'recoverPassword' => array(
'mailAttr' => 'mail',
'recoveryHashAttr' => 'lsRecoveryHash',
@ -71,12 +76,7 @@ $GLOBALS['LSconfig'] = array(
'msg' => "Votre nouveau mot de passe : %{mdp}"
)
),
'emailSender' => 'noreply@lsexample.net',
'LSobjects' => array (
'LSeepeople',
'LSeegroup',
'LSeecompany'
)
'emailSender' => 'noreply@lsexample.net'
)
)
);

View file

@ -36,7 +36,7 @@ if($LSsession -> startLSsession()) {
if (isset($LSobject)) {
// Création d'un LSobject
if (class_exists($LSobject)) {
if ($GLOBALS['LSsession'] -> loadLSobject($LSobject)) {
if ( $GLOBALS['LSsession'] -> canCreate($LSobject) ) {
$object = new $LSobject();

View file

@ -40,6 +40,7 @@ class LSldapObject {
var $other_values=array();
var $submitError=true;
var $_whoami=NULL;
var $_subDn_value=NULL;
/**
* Constructeur
@ -929,6 +930,38 @@ class LSldapObject {
function isNew() {
return (!$this -> dn);
}
/**
* Retourne la valeur (DN) du subDn de l'objet
*
* @return string La valeur du subDn de l'object
*/
function getSubDnValue() {
if ($this -> _subDn_value) {
return $this -> _subDn_value;
}
$dn = $this -> getValue('dn');
$subDn_value='';
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
foreach ($subDnLdapServer as $subDn => $subDn_name) {
if (isCompatibleDNs($subDn,$dn)&&($subDn!=$dn)) {
$subDn_value=$subDn;
break;
}
}
$this -> _subDn_value = $subDn_value;
return $subDn_value;
}
/**
* Retourne la nom du subDn de l'objet
*
* @return string Le nom du subDn de l'object
*/
function getSubDnName() {
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
return $subDnLdapServer[$this -> getSubDnValue()];
}
}
?>

View file

@ -144,31 +144,6 @@ class LSsession {
return true;
}
/**
* Chargement des objects LdapSaisie
*
* Chargement des LSobjects contenue dans la variable
* $this -> ldapServer['LSobjects']
*
* @retval boolean true si le chargement a réussi, false sinon.
*/
function loadLSobjects() {
$this -> loadLSclass('LSldapObject');
if(!is_array($this -> ldapServer['LSobjects'])) {
$GLOBALS['LSerror'] -> addErrorCode(1001,"LSobjects['loads']");
return;
}
foreach ($this -> ldapServer['LSobjects'] as $object) {
if ( !$this -> loadLSobject($object) ) {
return;
}
}
return true;
}
/**
* Chargement d'un addons d'LdapSaisie
*
@ -245,30 +220,36 @@ class LSsession {
$this -> ldapServerId = $_SESSION['LSsession']['ldapServerId'];
$this -> tmp_file = $_SESSION['LSsession']['tmp_file'];
if ( $this -> cacheLSrights() ) {
if ( $this -> cacheLSrights() && !isset($_REQUEST['LSsession_refresh']) ) {
$this -> ldapServer = $_SESSION['LSsession']['ldapServer'];
$this -> LSrights = $_SESSION['LSsession']['LSrights'];
$this -> LSaccess = $_SESSION['LSsession']['LSaccess'];
if (!$this -> LSldapConnect())
return;
$this -> loadLSobjects();
}
else {
$this -> setLdapServer($this -> ldapServerId);
if (!$this -> LSldapConnect())
return;
$this -> loadLSobjects();
$this -> loadLSrights();
}
if ( $this -> cacheSudDn() && (!isset($_REQUEST['LSsession_topDn_refresh'])) ) {
if ( $this -> cacheSudDn() && (!isset($_REQUEST['LSsession_refresh'])) ) {
$this -> _subDnLdapServer = $_SESSION['LSsession_subDnLdapServer'];
}
$this -> loadLSobject($this -> ldapServer['authobject']);
if (!$this -> loadLSobject($this -> ldapServer['authobject'])) {
$GLOBALS['LSerror'] -> addErrorCode(1004,$this -> ldapServer['authobject']);
return;
}
$this -> LSuserObject = new $this -> ldapServer['authobject']();
$this -> LSuserObject -> loadData($this -> dn);
$this -> loadLSaccess();
if ( !$this -> cacheLSrights() || isset($_REQUEST['LSsession_refresh']) ) {
$this -> loadLSaccess();
}
$GLOBALS['Smarty'] -> assign('LSsession_username',$this -> LSuserObject -> getDisplayValue());
if ($_POST['LSsession_topDn']) {
@ -293,8 +274,6 @@ class LSsession {
$this -> setLdapServer(0);
}
$this -> loadLSobjects();
// Connexion au serveur LDAP
if ($this -> LSldapConnect()) {
@ -564,9 +543,9 @@ class LSsession {
foreach($this ->ldapServer['subDn'] as $subDn_name => $subDn_config) {
if ($subDn_name == 'LSobject') {
if (is_array($subDn_config)) {
foreach($subDn_config as $LSobject_name => $LSoject_topDn) {
if ($LSoject_topDn) {
$topDn = $LSoject_topDn;
foreach($subDn_config as $LSobject_name => $LSoject_config) {
if ($LSoject_config['topDn']) {
$topDn = $LSoject_config['topDn'];
}
else {
$topDn = NULL;
@ -595,7 +574,9 @@ class LSsession {
}
}
else {
$return[$subDn_config] = $subDn_name;
if ((isCompatibleDNs($subDn_config['dn'],$this -> ldapServer['ldap_config']['basedn']))&&($subDn_config['dn']!="")) {
$return[$subDn_config['dn']] = $subDn_name;
}
}
}
if ($this -> cacheSudDn()) {
@ -616,15 +597,11 @@ class LSsession {
* @return array() Tableau des subDn trié
*/
function getSortSubDnLdapServer() {
if(isset($_SESSION['LSsession']['LSview_subDnLdapServer']) && $this -> cacheSudDn()) {
return $_SESSION['LSsession']['LSview_subDnLdapServer'];
}
$subDnLdapServer = $this -> getSubDnLdapServer();
if (!$subDnLdapServer) {
return array();
}
uksort($subDnLdapServer,"compareDn");
$_SESSION['LSsession']['LSview_subDnLdapServer']=$subDnLdapServer;
return $subDnLdapServer;
}
@ -850,8 +827,8 @@ class LSsession {
$Css_txt.="<link rel='stylesheet' type='text/css' href='templates/css/$file' />\n";
}
$GLOBALS['Smarty'] -> assign('LSsession_css',$Css_txt);
$GLOBALS['Smarty'] -> assign('LSaccess',$this -> LSaccess);
$GLOBALS['Smarty'] -> assign('LSaccess',$this -> LSaccess[$this -> topDn]);
// Niveau
$listTopDn = $this -> getSubDnLdapServer();
@ -942,26 +919,91 @@ class LSsession {
* @retval void
*/
function loadLSaccess() {
if ($this -> canAccess($this -> LSuserObject -> getType(),$this -> dn)) {
$LSaccess = array(
'SELF' => array(
'label' => _('Mon compte'),
'DNs' => $this -> dn
)
);
}
else {
$LSaccess = array();
}
foreach ($GLOBALS['LSobjects'] as $objecttype => $objectconf) {
if ($this -> canAccess($objecttype) ) {
$LSaccess[$objecttype] = array (
'label' => $objectconf['label'],
'Dns' => 'All'
);
$LSaccess=array();
if (is_array($this -> ldapServer['subDn'])) {
foreach($this -> ldapServer['subDn'] as $name => $config) {
if ($name=='LSobject') {
if (is_array($config)) {
// Définition des subDns
foreach($config as $objectType => $objectConf) {
if ($this -> loadLSobject($objectType)) {
if ($subdnobject = new $objectType()) {
$tbl = $subdnobject -> getSelectArray();
if (is_array($tbl)) {
// Définition des accès
$access=array();
if (is_array($objectConf['LSobjects'])) {
foreach($objectConf['LSobjects'] as $type) {
if ($this -> loadLSobject($type)) {
if ($this -> canAccess($type)) {
$access[$type] = $GLOBALS['LSobjects'][$type]['label'];
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$type);
}
}
}
foreach($tbl as $dn => $dn_name) {
$LSaccess[$dn]=$access;
}
}
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$objectType);
}
}
}
}
else {
if ((isCompatibleDNs($this -> ldapServer['ldap_config']['basedn'],$config['dn']))&&($config['dn']!='')) {
$access=array();
if (is_array($config['LSobjects'])) {
foreach($config['LSobjects'] as $objectType) {
if ($this -> loadLSobject($objectType)) {
if ($this -> canAccess($objectType)) {
$access[$objectType] = $GLOBALS['LSobjects'][$objectType]['label'];
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject_name);
}
}
}
$LSaccess[$config['dn']]=$access;
}
}
}
}
else {
if(is_array($this -> ldapServer['LSaccess'])) {
$access=array();
foreach($this -> ldapServer['LSaccess'] as $objectType) {
if ($this -> loadLSobject($objectType)) {
if ($this -> canAccess($objectType)) {
$access[$objectType] = $GLOBALS['LSobjects'][$objectType]['label'];
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject_name);
}
}
$LSaccess[$this -> topDn] = $access;
}
}
foreach($LSaccess as $dn => $access) {
$LSaccess[$dn] = array_merge(
array(
'SELF' => _('Mon compte')
),
$access
);
}
$this -> LSaccess = $LSaccess;
$_SESSION['LSsession']['LSaccess'] = $LSaccess;
}
/**
@ -1013,10 +1055,24 @@ class LSsession {
* @retval boolean True si l'utilisateur a accès, false sinon
*/
function canAccess($LSobject,$dn=NULL,$right=NULL,$attr=NULL) {
if (!$this -> loadLSobject($LSobject))
if (!$this -> loadLSobject($LSobject)) {
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject);
return;
}
if ($dn) {
$whoami = $this -> whoami($dn);
if ($dn==$this -> LSuserObject -> getValue('dn')) {
if (!$this -> in_menu('SELF')) {
return;
}
}
else {
$obj = new $LSobject();
$obj -> dn = $dn;
if (!$this -> in_menu($LSobject,$obj -> getSubDnValue())) {
return;
}
}
}
else {
$objectdn=$GLOBALS['LSobjects'][$LSobject]['container_dn'].','.$this -> topDn;
@ -1272,7 +1328,7 @@ class LSsession {
*
* @param[in] $subDn string subDn
*
* @return string Le nom du subDn ou '' sinon
* @retval string Le nom du subDn ou '' sinon
*/
function getSubDnName($subDn=false) {
if (!$subDn) {
@ -1291,10 +1347,9 @@ class LSsession {
*
* @param[in] $type string Le type d'objet
*
* @return boolean true si le type d'objet est un subDnObject, false sinon
* @retval boolean true si le type d'objet est un subDnObject, false sinon
*/
function isSubDnLSobject($type) {
debug('seach : '.$type);
$result = false;
if (is_array($this -> ldapServer['subDn']['LSobject'])) {
foreach($this -> ldapServer['subDn']['LSobject'] as $key => $value) {
@ -1305,6 +1360,18 @@ class LSsession {
}
return $result;
}
/**
* Retourne si un type d'objet est dans le menu courant
*
* @retval boolean true si le type d'objet est dans le menu, false sinon
*/
function in_menu($LSobject,$topDn=NULL) {
if (!$topDn) {
$topDn=$this -> topDn;
}
return isset($this -> LSaccess[$topDn][$LSobject]);
}
}
?>

View file

@ -20,7 +20,6 @@ if (!isset($_ERRORS)) {
$GLOBALS['LSsession'] -> setLdapServer($_REQUEST['server']);
if ( $GLOBALS['LSsession'] -> LSldapConnect() ) {
session_start();
$GLOBALS['LSsession'] -> loadLSobjects();
$list = $GLOBALS['LSsession'] -> getSubDnLdapServerOptions($_SESSION['LSsession_topDn']);
if (is_string($list)) {
$list="<select name='LSsession_topDn' id='LSsession_topDn'>".$list."</select>";
@ -29,15 +28,6 @@ if (!isset($_ERRORS)) {
'levelLabel' => $GLOBALS['LSsession'] -> getLevelLabel()
);
}
else if (is_array($list)){
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
}
else {
$data = null;
}
}
else {
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
}
}
break;
@ -47,71 +37,77 @@ if (!isset($_ERRORS)) {
switch($_REQUEST['action']) {
case 'onAddFieldBtnClick':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['img'])) ) {
$object = new $_REQUEST['objecttype']();
$object -> loadData($_REQUEST['objectdn']);
$form = $object -> getForm($_REQUEST['idform']);
$emptyField=$form -> getEmptyField($_REQUEST['attribute']);
if ( $emptyField ) {
$data = array(
'html' => $form -> getEmptyField($_REQUEST['attribute']),
'img' => $_REQUEST['img'],
);
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype']();
$object -> loadData($_REQUEST['objectdn']);
$form = $object -> getForm($_REQUEST['idform']);
$emptyField=$form -> getEmptyField($_REQUEST['attribute']);
if ( $emptyField ) {
$data = array(
'html' => $form -> getEmptyField($_REQUEST['attribute']),
'img' => $_REQUEST['img'],
);
}
}
else {
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['objecttype']);
}
}
break;
case 'refreshField':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) {
$object = new $_REQUEST['objecttype']();
//$object -> loadData($_REQUEST['objectdn']);
$form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> getDisplay(true);
if ( $val ) {
$data = array(
'html' => $val['html']
);
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> getDisplay(true);
if ( $val ) {
$data = array(
'html' => $val['html']
);
}
}
else {
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
);
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['objecttype']);
}
}
break;
case 'generatePassword':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['viewBtnId'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['idform'])) ) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> generatePassword();
if ( $val ) {
$data = array(
'generatePassword' => $val,
'fieldId' => $_REQUEST['fieldId'],
'viewBtnId' => $_REQUEST['viewBtnId']
);
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> generatePassword();
if ( $val ) {
$data = array(
'generatePassword' => $val,
'fieldId' => $_REQUEST['fieldId'],
'viewBtnId' => $_REQUEST['viewBtnId']
);
}
}
else {
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
);
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['objecttype']);
}
}
break;
case 'verifyPassword':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['fieldValue'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['objectdn'])) ) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$object -> loadData($_REQUEST['objectdn']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> verifyPassword($_REQUEST['fieldValue']);
$data = array(
'verifyPassword' => $val,
'fieldId' => $_REQUEST['fieldId']
);
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$object -> loadData($_REQUEST['objectdn']);
$field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> verifyPassword($_REQUEST['fieldValue']);
$data = array(
'verifyPassword' => $val,
'fieldId' => $_REQUEST['fieldId']
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['objecttype']);
}
}
break;
}
@ -126,27 +122,32 @@ if (!isset($_ERRORS)) {
$object = new $conf['objectType']();
if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) {
$relationConf = $object->config['relations'][$conf['relationName']];
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
$_SESSION['LSselect'][$relationConf['LSobject']]=array();
if (is_array($list)) {
foreach($list as $o) {
$_SESSION['LSselect'][$relationConf['LSobject']][] = $o -> getDn();
if ($GLOBALS['LSsession'] -> loadLSobject($relationConf['LSobject'])) {
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
$_SESSION['LSselect'][$relationConf['LSobject']]=array();
if (is_array($list)) {
foreach($list as $o) {
$_SESSION['LSselect'][$relationConf['LSobject']][] = $o -> getDn();
}
}
$data = array(
'href' => $_REQUEST['href'],
'id' => $_REQUEST['id']
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
}
$data = array(
'href' => $_REQUEST['href'],
'id' => $_REQUEST['id']
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
$GLOBALS['LSerror'] -> addErrorCode(1004,$relationConf['LSobject']);
}
}
else {
@ -170,38 +171,43 @@ if (!isset($_ERRORS)) {
$object = new $conf['objectType']();
if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) {
$relationConf = $object->config['relations'][$conf['relationName']];
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (is_array($_SESSION['LSselect'][$relationConf['LSobject']])) {
if (method_exists($relationConf['LSobject'],$relationConf['update_function'])) {
$objRel = new $relationConf['LSobject']();
if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
foreach($list as $o) {
$data['html'].= "<li class='LSrelation'>".$o -> getDisplayValue()."</li>\n";
if ($GLOBALS['LSsession'] -> loadLSobject($relationConf['LSobject'])) {
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (is_array($_SESSION['LSselect'][$relationConf['LSobject']])) {
if (method_exists($relationConf['LSobject'],$relationConf['update_function'])) {
$objRel = new $relationConf['LSobject']();
if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
foreach($list as $o) {
$data['html'].= "<li class='LSrelation'>".$o -> getDisplayValue()."</li>\n";
}
}
else {
$data['html'] = "<li>"._('Liste vide.')."</li>\n";
}
$data['id'] = $_REQUEST['id'];
}
else {
$data['html'] = "<li>"._('Liste vide.')."</li>\n";
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
}
$data['id'] = $_REQUEST['id'];
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
$GLOBALS['LSerror'] -> addErrorCode(1015,$relationName);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1015,$relationName);
$GLOBALS['LSerror'] -> addErrorCode(1014,$relationName);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1014,$relationName);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
$GLOBALS['LSerror'] -> addErrorCode(1004,$relationConf['LSobject']);
}
}
else {
@ -225,37 +231,42 @@ if (!isset($_ERRORS)) {
$object = new $conf['objectType']();
if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) {
$relationConf = $object->config['relations'][$conf['relationName']];
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
$ok=false;
foreach($list as $o) {
if($o -> getDisplayValue() == $_REQUEST['value']) {
if (!$o -> deleteOneMember($object)) {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
}
else {
$ok = true;
if ($GLOBALS['LSsession'] -> loadLSobject($relationConf['LSobject'])) {
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
$ok=false;
foreach($list as $o) {
if($o -> getDisplayValue() == $_REQUEST['value']) {
if (!$o -> deleteOneMember($object)) {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
}
else {
$ok = true;
}
}
}
if (!$ok) {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
}
}
if (!$ok) {
else {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
$GLOBALS['LSerror'] -> addErrorCode(1);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
$GLOBALS['LSerror'] -> addErrorCode(1);
$GLOBALS['LSerror'] -> addErrorCode(1013,$conf['relationName']);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$conf['relationName']);
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
$GLOBALS['LSerror'] -> addErrorCode(1004,$relationConf['LSobject']);
}
}
else {
@ -316,9 +327,6 @@ if (!isset($_ERRORS)) {
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
);
}
break;
}

View file

@ -36,8 +36,6 @@ if($LSsession -> startLSsession()) {
$GLOBALS['Smarty']->assign('pagetitle',$object -> getLabel());
$GLOBALS['Smarty']->assign('LSobject_list_objectname',$object -> getLabel());
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
if (isset($_SESSION['LSsession']['LSsearch'][$LSobject])) {
$filter = $_SESSION['LSsession']['LSsearch'][$LSobject]['filter'];
if (isCompatibleDNs($_SESSION['LSsession']['LSsearch'][$LSobject]['topDn'],$GLOBALS['LSsession'] -> topDn)) {
@ -67,6 +65,7 @@ if($LSsession -> startLSsession()) {
$selectedTopDn = $GLOBALS['LSsession'] -> topDn;
$orderby = false;
$ordersense = 'ASC';
$subDnLdapServer = $GLOBALS['LSsession'] -> getSubDnLdapServer();
$doSubDn = (($subDnLdapServer)&&(!$GLOBALS['LSsession']->isSubDnLSobject($LSobject)));
}
@ -211,12 +210,7 @@ if($LSsession -> startLSsession()) {
$subDn_name=false;
if ($doSubDn) {
reset($subDnLdapServer);
while (!$subDn_name && next($subDnLdapServer)) {
if (isCompatibleDNs(key($subDnLdapServer),$thisObject -> getValue('dn'))) {
$subDn_name=current($subDnLdapServer);
}
}
$subDn_name = $thisObject -> getSubDnName();
}
$objectList[]=array(

View file

@ -25,7 +25,7 @@
{if $LSsession_subDn!=""}
<form action="index.php" method='post' id='LSsession_topDn_form'>
<label>{$label_level}
<a href="index.php?LSsession_topDn_refresh"><img src='templates/images/refresh.png' alt='{$_refresh}' title='{$_refresh}' /></a>
<a href="index.php?LSsession_refresh"><img src='templates/images/refresh.png' alt='{$_refresh}' title='{$_refresh}' /></a>
<select name='LSsession_topDn' id='LSsession_topDn'>
{html_options values=$LSsession_subDn_indexes output=$LSsession_subDn_names selected=$LSsession_subDn}
</select>
@ -33,8 +33,8 @@
</form>
{/if}
<ul class='menu'>
{foreach from=$LSaccess item=item key=LSobject_type}
<li class='menu'><a href='view.php?LSobject={$LSobject_type}' class='menu'>{$item.label}</a></li>
{foreach from=$LSaccess item=label key=LSobject_type}
<li class='menu'><a href='view.php?LSobject={$LSobject_type}' class='menu'>{$label}</a></li>
{/foreach}
</ul>
</div>

View file

@ -30,402 +30,400 @@ if($LSsession -> startLSsession()) {
$LSobject = $_REQUEST['LSobject'];
$dn = $_REQUEST['dn'];
if ( $LSobject == 'SELF' ) {
$LSobject = $GLOBALS['LSsession']-> LSuserObject -> getType();
$dn = $GLOBALS['LSsession']-> LSuserObject -> getValue('dn');
}
if ($GLOBALS['LSsession'] -> in_menu($LSobject)) {
if ( $GLOBALS['LSsession'] -> loadLSobject($LSobject) ) {
// Affichage d'un objet
if ( $dn!='' ) {
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$dn)) {
if ( $GLOBALS['LSsession'] -> canEdit($LSobject,$dn) ) {
$LSview_actions[] = array(
'label' => _('Modifier'),
'url' =>'modify.php?LSobject='.$LSobject.'&amp;dn='.$dn,
'action' => 'modify'
);
}
if ($GLOBALS['LSsession'] -> canCreate($LSobject)) {
$LSview_actions[] = array(
'label' => _('Copier'),
'url' =>'create.php?LSobject='.$LSobject.'&amp;load='.$dn,
'action' => 'copy'
);
}
if ($GLOBALS['LSsession'] -> canRemove($LSobject,$dn)) {
$LSview_actions[] = array(
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&amp;dn='.$dn,
'action' => 'delete'
);
}
if ($GLOBALS['LSsession']-> LSuserObject -> getValue('dn') != $dn) {
$object = new $LSobject();
$object -> loadData($dn);
$GLOBALS['Smarty'] -> assign('pagetitle',$object -> getDisplayValue());
if ( $LSobject == 'SELF' ) {
$LSobject = $GLOBALS['LSsession']-> LSuserObject -> getType();
$dn = $GLOBALS['LSsession']-> LSuserObject -> getValue('dn');
}
if ( $GLOBALS['LSsession'] -> loadLSobject($LSobject) ) {
// Affichage d'un objet
if ( $dn!='' ) {
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$dn)) {
if ( $GLOBALS['LSsession'] -> canEdit($LSobject,$dn) ) {
$LSview_actions[] = array(
'label' => _('Modifier'),
'url' =>'modify.php?LSobject='.$LSobject.'&amp;dn='.$dn,
'action' => 'modify'
);
}
if ($GLOBALS['LSsession'] -> canCreate($LSobject)) {
$LSview_actions[] = array(
'label' => _('Copier'),
'url' =>'create.php?LSobject='.$LSobject.'&amp;load='.$dn,
'action' => 'copy'
);
}
if ($GLOBALS['LSsession'] -> canRemove($LSobject,$dn)) {
$LSview_actions[] = array(
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&amp;dn='.$dn,
'action' => 'delete'
);
}
if ($GLOBALS['LSsession']-> LSuserObject -> getValue('dn') != $dn) {
$object = new $LSobject();
$object -> loadData($dn);
$GLOBALS['Smarty'] -> assign('pagetitle',$object -> getDisplayValue());
}
else {
$object = &$GLOBALS['LSsession']-> LSuserObject;
$GLOBALS['Smarty'] -> assign('pagetitle',_('Mon compte'));
}
$view = $object -> getView();
$view -> displayView();
// Relations
if (is_array($object -> config['relations'])) {
$LSrelations=array();
foreach($object -> config['relations'] as $relationName => $relationConf) {
if ($GLOBALS['LSsession'] -> relationCanAccess($object -> getValue('dn'),$relationName)) {
$return=array('label' => $relationConf['label']);
$id=rand();
$return['id']=$id;
$_SESSION['LSrelation'][$id] = array(
'relationName' => $relationName,
'objectType' => $object -> getType(),
'objectDn' => $object -> getDn(),
);
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$relationName)) {
$return['actions'][] = array(
'label' => _('Modifier'),
'url' => 'select.php?LSobject='.$relationConf['LSobject'],
'action' => 'modify'
);
}
$GLOBALS['LSsession'] -> addJSscript('LSselect.js');
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['LSsession'] -> addJSscript('LSrelation.js');
if($GLOBALS['LSsession'] -> loadLSobject($relationConf['LSobject'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
foreach($list as $o) {
$return['objectList'][] = $o -> getDisplayValue();
}
}
else {
$return['objectList']=array();
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
}
$LSrelations[]=$return;
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1016,array('relation' => $relationName,'LSobject' => $relationConf['LSobject']));
}
}
}
$GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations);
}
$GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions);
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['LSsession'] -> setTemplate('view.tpl');
}
else {
$object = &$GLOBALS['LSsession']-> LSuserObject;
$GLOBALS['Smarty'] -> assign('pagetitle',_('Mon compte'));
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
// Affichage d'une liste d'un type d'objet
else {
$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'];
$params = $_SESSION['LSsession']['LSsearch'][$LSobject]['params'];
$pattern = $_SESSION['LSsession']['LSsearch'][$LSobject]['pattern'];
$recur = $_SESSION['LSsession']['LSsearch'][$LSobject]['recur'];
if ($recur) {
$topDn = $GLOBALS['LSsession'] -> topDn;
}
else {
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
}
$approx = $_SESSION['LSsession']['LSsearch'][$LSobject]['approx'];
$orderby = $_SESSION['LSsession']['LSsearch'][$LSobject]['orderby'];
$ordersense = $_SESSION['LSsession']['LSsearch'][$LSobject]['ordersense'];
$doSubDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['doSubDn'];
}
else {
$filter = NULL;
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
$params = array('scope' => 'one');
$pattern = false;
$recur = false;
$approx = false;
$orderby = false;
$ordersense = 'ASC';
$subDnLdapServer = $GLOBALS['LSsession'] -> getSubDnLdapServer();
$doSubDn = (($subDnLdapServer)&&(!$GLOBALS['LSsession']->isSubDnLSobject($LSobject)));
}
$view = $object -> getView();
$view -> displayView();
if (isset($_REQUEST['LSview_search_submit'])) {
if (isset($_REQUEST['LSview_pattern']) && ($_REQUEST['LSview_pattern']!=$pattern)) {
$pattern = $_REQUEST['LSview_pattern'];
}
$approx = (isset($_REQUEST['LSview_approx']));
if ($pattern && $pattern!='') {
$filter='(|';
if ($approx) {
foreach ($object -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'~='.$pattern.')';
}
}
else {
foreach ($object -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'=*'.$pattern.'*)';
}
}
$filter.=')';
}
else {
$filter = NULL;
}
if (isset($_REQUEST['LSview_recur'])) {
$recur = true;
$params['scope'] = 'sub';
$topDn = $GLOBALS['LSsession'] -> topDn;
}
else {
$recur = false;
$params['scope'] = 'one';
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
}
}
// Relations
if (is_array($object -> config['relations'])) {
$LSrelations=array();
foreach($object -> config['relations'] as $relationName => $relationConf) {
if ($GLOBALS['LSsession'] -> relationCanAccess($object -> getValue('dn'),$relationName)) {
$return=array('label' => $relationConf['label']);
$sort=false;
if ((isset($_REQUEST['orderby']))) {
$possible_values= array('displayValue','subDn');
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);
// Sauvegarde en Session
$_SESSION['LSsession']['LSsearch'][$LSobject] = array(
'filter' => $filter,
'topDn' => $topDn,
'params' => $params,
'pattern' => $pattern,
'recur' => $recur,
'approx' => $approx,
'orderby' => $orderby,
'ordersense' => $ordersense,
'doSubDn' => $doSubDn
);
$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);
}
// Hidden fields
$GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array(
'LSobject' => $LSobject,
'LSview_search_submit' => 1
));
// 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
)
);
if (($GLOBALS['LSsession'] -> cacheSearch()) && isset($_SESSION['LSsession']['LSsearch'][$hash]) && (!isset($_REQUEST['refresh']))) {
// On affiche à partir du cache
$searchData=$_SESSION['LSsession']['LSsearch'][$hash];
debug('Recherche : From cache');
}
else {
debug('Recherche : Load');
if ($GLOBALS['LSsession'] -> canCreate($LSobject)) {
$LSview_actions[] = array (
'label' => _('Nouveau'),
'url' => 'create.php?LSobject='.$LSobject,
'action' => 'create'
);
$canCopy=true;
}
$LSview_actions[] = array (
'label' => _('Rafraîchir'),
'url' => 'view.php?LSobject='.$LSobject.'&amp;refresh',
'action' => 'refresh'
);
$list=$object -> listObjects($filter,$topDn,$params);
$nbObjects=0;
foreach($list as $thisObject) {
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) {
$subDn_name=false;
if ($doSubDn) {
$subDn_name = $thisObject -> getSubDnName();
}
$nbObjects++;
unset($actions);
$id=rand();
$return['id']=$id;
$_SESSION['LSrelation'][$id] = array(
'relationName' => $relationName,
'objectType' => $object -> getType(),
'objectDn' => $object -> getDn(),
$actions[] = array(
'label' => _('Voir'),
'url' =>'view.php?LSobject='.$LSobject.'&amp;dn='.$thisObject -> getValue('dn'),
'action' => 'view'
);
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$relationName)) {
$return['actions'][] = array(
if ($GLOBALS['LSsession'] -> canEdit($LSobject,$thisObject->getValue('dn'))) {
$actions[]=array(
'label' => _('Modifier'),
'url' => 'select.php?LSobject='.$relationConf['LSobject'],
'url' => 'modify.php?LSobject='.$LSobject.'&amp;dn='.$thisObject->getValue('dn'),
'action' => 'modify'
);
}
$GLOBALS['LSsession'] -> addJSscript('LSselect.js');
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['LSsession'] -> addJSscript('LSrelation.js');
if($GLOBALS['LSsession'] -> loadLSobject($relationConf['LSobject'])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$objRel = new $relationConf['LSobject']();
$list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) {
foreach($list as $o) {
$return['objectList'][] = $o -> getDisplayValue();
}
}
else {
$return['objectList']=array();
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
}
$LSrelations[]=$return;
if ($canCopy) {
$actions[] = array(
'label' => _('Copier'),
'url' =>'create.php?LSobject='.$LSobject.'&amp;load='.$thisObject -> getValue('dn'),
'action' => 'copy'
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1016,array('relation' => $relationName,'LSobject' => $relationConf['LSobject']));
if ($GLOBALS['LSsession'] -> canRemove($thisObject -> getType(),$thisObject -> getValue('dn'))) {
$actions[] = array (
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&amp;dn='.$thisObject -> getValue('dn'),
'action' => 'delete'
);
}
}
}
$GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations);
}
$GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions);
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['LSsession'] -> setTemplate('view.tpl');
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
// Affichage d'une liste d'un type d'objet
else {
$objectList=array();
$object = new $LSobject();
$GLOBALS['Smarty']->assign('pagetitle',$object -> getLabel());
$GLOBALS['Smarty']->assign('LSobject_list_objectname',$object -> getLabel());
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
if (isset($_SESSION['LSsession']['LSsearch'][$LSobject])) {
$filter = $_SESSION['LSsession']['LSsearch'][$LSobject]['filter'];
$params = $_SESSION['LSsession']['LSsearch'][$LSobject]['params'];
$pattern = $_SESSION['LSsession']['LSsearch'][$LSobject]['pattern'];
$recur = $_SESSION['LSsession']['LSsearch'][$LSobject]['recur'];
if ($recur) {
$topDn = $GLOBALS['LSsession'] -> topDn;
}
else {
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
}
$approx = $_SESSION['LSsession']['LSsearch'][$LSobject]['approx'];
$orderby = $_SESSION['LSsession']['LSsearch'][$LSobject]['orderby'];
$ordersense = $_SESSION['LSsession']['LSsearch'][$LSobject]['ordersense'];
$doSubDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['doSubDn'];
}
else {
$filter = NULL;
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
$params = array('scope' => 'one');
$pattern = false;
$recur = false;
$approx = false;
$orderby = false;
$ordersense = 'ASC';
$doSubDn = (($subDnLdapServer)&&(!$GLOBALS['LSsession']->isSubDnLSobject($LSobject)));
}
if (isset($_REQUEST['LSview_search_submit'])) {
if (isset($_REQUEST['LSview_pattern']) && ($_REQUEST['LSview_pattern']!=$pattern)) {
$pattern = $_REQUEST['LSview_pattern'];
}
$approx = (isset($_REQUEST['LSview_approx']));
if ($pattern && $pattern!='') {
$filter='(|';
if ($approx) {
foreach ($object -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'~='.$pattern.')';
}
}
else {
foreach ($object -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'=*'.$pattern.'*)';
}
}
$filter.=')';
}
else {
$filter = NULL;
}
if (isset($_REQUEST['LSview_recur'])) {
$recur = true;
$params['scope'] = 'sub';
$topDn = $GLOBALS['LSsession'] -> topDn;
}
else {
$recur = false;
$params['scope'] = 'one';
$topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn;
}
}
$sort=false;
if ((isset($_REQUEST['orderby']))) {
$possible_values= array('displayValue','subDn');
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);
// Sauvegarde en Session
$_SESSION['LSsession']['LSsearch'][$LSobject] = array(
'filter' => $filter,
'topDn' => $topDn,
'params' => $params,
'pattern' => $pattern,
'recur' => $recur,
'approx' => $approx,
'orderby' => $orderby,
'ordersense' => $ordersense,
'doSubDn' => $doSubDn
);
$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);
}
// Hidden fields
$GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array(
'LSobject' => $LSobject,
'LSview_search_submit' => 1
));
// 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
)
);
if (($GLOBALS['LSsession'] -> cacheSearch()) && isset($_SESSION['LSsession']['LSsearch'][$hash]) && (!isset($_REQUEST['refresh']))) {
// On affiche à partir du cache
$searchData=$_SESSION['LSsession']['LSsearch'][$hash];
debug('Recherche : From cache');
}
else {
debug('Recherche : Load');
if ($GLOBALS['LSsession'] -> canCreate($LSobject)) {
$LSview_actions[] = array (
'label' => _('Nouveau'),
'url' => 'create.php?LSobject='.$LSobject,
'action' => 'create'
);
$canCopy=true;
}
$LSview_actions[] = array (
'label' => _('Rafraîchir'),
'url' => 'view.php?LSobject='.$LSobject.'&amp;refresh',
'action' => 'refresh'
);
$list=$object -> listObjects($filter,$topDn,$params);
$nbObjects=count($list);
$searchData['LSobject_list_nbresult']=$nbObjects;
$c=0;
foreach($list as $thisObject) {
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) {
$subDn_name=false;
if ($doSubDn) {
reset($subDnLdapServer);
while (!$subDn_name && next($subDnLdapServer)) {
if (isCompatibleDNs(key($subDnLdapServer),$thisObject -> getValue('dn'))) {
$subDn_name=current($subDnLdapServer);
}
}
}
$c++;
unset($actions);
$actions[] = array(
'label' => _('Voir'),
'url' =>'view.php?LSobject='.$LSobject.'&amp;dn='.$thisObject -> getValue('dn'),
'action' => 'view'
);
if ($GLOBALS['LSsession'] -> canEdit($LSobject,$thisObject->getValue('dn'))) {
$actions[]=array(
'label' => _('Modifier'),
'url' => 'modify.php?LSobject='.$LSobject.'&amp;dn='.$thisObject->getValue('dn'),
'action' => 'modify'
$objectList[]=array(
'dn' => $thisObject->getValue('dn'),
'displayValue' => $thisObject->getDisplayValue(),
'actions' => $actions,
'subDn' => $subDn_name
);
}
if ($canCopy) {
$actions[] = array(
'label' => _('Copier'),
'url' =>'create.php?LSobject='.$LSobject.'&amp;load='.$thisObject -> getValue('dn'),
'action' => 'copy'
);
}
if ($GLOBALS['LSsession'] -> canRemove($thisObject -> getType(),$thisObject -> getValue('dn'))) {
$actions[] = array (
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&amp;dn='.$thisObject -> getValue('dn'),
'action' => 'delete'
);
}
$objectList[]=array(
'dn' => $thisObject->getValue('dn'),
'displayValue' => $thisObject->getDisplayValue(),
'actions' => $actions,
'subDn' => $subDn_name
);
}
else {
debug($thisObject->getValue('dn'));
$searchData['LSobject_list_nbresult']=$nbObjects;
$searchData['objectList']=$objectList;
$searchData['LSview_actions'] = $LSview_actions;
if ($GLOBALS['LSsession'] -> cacheSearch()) {
$_SESSION['LSsession']['LSsearch'][$hash]=$searchData;
}
}
$searchData['objectList']=$objectList;
$searchData['LSview_actions'] = $LSview_actions;
if ($GLOBALS['LSsession'] -> cacheSearch()) {
$GLOBALS['Smarty']->assign('LSobject_list_nbresult',$searchData['LSobject_list_nbresult']);
// 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')) {
debug('Erreur durant le trie.');
}
$_SESSION['LSsession']['LSsearch'][$hash]=$searchData;
}
}
$GLOBALS['Smarty']->assign('LSobject_list_nbresult',$searchData['LSobject_list_nbresult']);
// Order by if $sort
if ($sort) {
function sortBy($a,$b) {
global $ordersense;
global $orderby;
if ($ordersense=='ASC') {
$sense = -1;
$GLOBALS['Smarty']->assign('LSobject_list_orderby',$orderby);
$GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense);
// Pagination
if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) {
if (isset($_REQUEST['page'])) {
$searchData['objectList'] = array_slice($searchData['objectList'], ($_REQUEST['page']) * NB_LSOBJECT_LIST, NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',$_REQUEST['page']);
}
else {
$sense = 1;
$searchData['objectList'] = array_slice($searchData['objectList'], 0, NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',0);
}
if ($a == $b) return 0;
$sort = array($a[$orderby],$b[$orderby]);
sort($sort);
if ($sort[0]==$a[$orderby])
return 1*$sense;
return -1*$sense;
$searchData['LSobject_list_nbpage']=ceil($searchData['LSobject_list_nbresult'] / NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']);
}
if (!uasort($searchData['objectList'],'sortBy')) {
debug('Erreur durant le trie.');
}
$_SESSION['LSsession']['LSsearch'][$hash]=$searchData;
}
$GLOBALS['Smarty']->assign('LSobject_list_orderby',$orderby);
$GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense);
// Pagination
if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) {
if (isset($_REQUEST['page'])) {
$searchData['objectList'] = array_slice($searchData['objectList'], ($_REQUEST['page']) * NB_LSOBJECT_LIST, NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',$_REQUEST['page']);
}
else {
$searchData['objectList'] = array_slice($searchData['objectList'], 0, NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',0);
}
$searchData['LSobject_list_nbpage']=ceil($searchData['LSobject_list_nbresult'] / NB_LSOBJECT_LIST);
$GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']);
}
$GLOBALS['LSsession'] -> addJSscript('LSview.js');
$GLOBALS['Smarty']->assign('LSview_search',array(
'action' => $_SERVER['PHP_SELF'],
'submit' => _('Rechercher'),
'LSobject' => $LSobject
));
$GLOBALS['Smarty']->assign('LSview_search_recur_label',_('Recherche récursive'));
$GLOBALS['Smarty']->assign('LSview_search_approx_label',_('Recherche approximative'));
$GLOBALS['LSsession'] -> addJSscript('LSview.js');
$GLOBALS['Smarty']->assign('LSview_search',array(
'action' => $_SERVER['PHP_SELF'],
'submit' => _('Rechercher'),
'LSobject' => $LSobject
));
$GLOBALS['Smarty']->assign('LSview_search_recur_label',_('Recherche récursive'));
$GLOBALS['Smarty']->assign('LSview_search_approx_label',_('Recherche approximative'));
$GLOBALS['Smarty']->assign('LSobject_list_without_result_label',_("Cette recherche n'a retourné aucun résultat."));
$GLOBALS['Smarty']->assign('_Actions',_('Actions'));
$GLOBALS['Smarty']->assign('_Modifier',_('Modifier'));
$GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']);
$GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject);
$GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']);
$GLOBALS['LSsession'] -> setTemplate('viewList.tpl');
$GLOBALS['Smarty']->assign('LSobject_list_without_result_label',_("Cette recherche n'a retourné aucun résultat."));
$GLOBALS['Smarty']->assign('_Actions',_('Actions'));
$GLOBALS['Smarty']->assign('_Modifier',_('Modifier'));
$GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']);
$GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject);
$GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']);
$GLOBALS['LSsession'] -> setTemplate('viewList.tpl');
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject);
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
else {