- Correction bug [#1666] Message d'erreur lors d'une requête Ajax lorsque

l'utilisateur n'est pas (ou plus) authentifié.
This commit is contained in:
Benjamin Renard 2008-05-14 09:05:06 +00:00
parent 9b0fb18008
commit 3eeb385d90
2 changed files with 243 additions and 238 deletions

View file

@ -83,7 +83,7 @@ var LSform = new Class({
LSdebug(data); LSdebug(data);
if ( data ) { if ( data ) {
if ( typeof(data.LSerror) != "undefined" ) { if ( typeof(data.LSerror) != "undefined" ) {
varLSdefault.loadingImgHide(); varLSdefault.loadingImgHide(data.imgload);
varLSdefault.displayError(data.LSerror); varLSdefault.displayError(data.LSerror);
return; return;
} }
@ -198,7 +198,7 @@ var LSform = new Class({
var data = Json.evaluate(responseText); var data = Json.evaluate(responseText);
if ( data ) { if ( data ) {
if ( typeof(data.LSerror) != "undefined" ) { if ( typeof(data.LSerror) != "undefined" ) {
varLSdefault.loadingImgHide(); varLSdefault.loadingImgHide(data.imgload);
varLSdefault.displayError(data.LSerror); varLSdefault.displayError(data.LSerror);
return; return;
} }
@ -236,7 +236,7 @@ var LSform = new Class({
var data = Json.evaluate(responseText); var data = Json.evaluate(responseText);
if ( data ) { if ( data ) {
if ( typeof(data.LSerror) != "undefined" ) { if ( typeof(data.LSerror) != "undefined" ) {
varLSdefault.loadingImgHide(); varLSdefault.loadingImgHide(data.imgload);
varLSdefault.displayError(data.LSerror); varLSdefault.displayError(data.LSerror);
return; return;
} }

View file

@ -7,128 +7,133 @@ $GLOBALS['LSsession'] = new LSsession();
if ($_REQUEST['template'] != 'login') { if ($_REQUEST['template'] != 'login') {
if ( !$GLOBALS['LSsession'] -> startLSsession() ) { if ( !$GLOBALS['LSsession'] -> startLSsession() ) {
echo json_encode(array('LSerror' => 'LSsession : Impossible d\'initialiser la LSsession.' )); $_ERRORS = 'LSsession : Impossible d\'initialiser la LSsession.';
} }
} }
$data=NULL; $data=NULL;
switch($_REQUEST['template']) { if (!isset($_ERRORS)) {
case 'login': switch($_REQUEST['template']) {
switch($_REQUEST['action']) { case 'login':
case 'onLdapServerChanged': switch($_REQUEST['action']) {
if ( isset($_REQUEST['server']) ) { case 'onLdapServerChanged':
$GLOBALS['LSsession'] -> setLdapServer($_REQUEST['server']); if ( isset($_REQUEST['server']) ) {
if ( $GLOBALS['LSsession'] -> LSldapConnect() ) { $GLOBALS['LSsession'] -> setLdapServer($_REQUEST['server']);
session_start(); if ( $GLOBALS['LSsession'] -> LSldapConnect() ) {
$GLOBALS['LSsession'] -> loadLSobjects(); session_start();
$list = $GLOBALS['LSsession'] -> getSubDnLdapServerOptions($_SESSION['LSsession_topDn']); $GLOBALS['LSsession'] -> loadLSobjects();
if (is_string($list)) { $list = $GLOBALS['LSsession'] -> getSubDnLdapServerOptions($_SESSION['LSsession_topDn']);
$list="<select name='LSsession_topDn' id='LSsession_topDn'>".$list."</select>"; if (is_string($list)) {
$data = array('list_topDn' => $list); $list="<select name='LSsession_topDn' id='LSsession_topDn'>".$list."</select>";
} $data = array('list_topDn' => $list);
else if (is_array($list)){ }
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors()); else if (is_array($list)){
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
}
else {
$data = null;
}
} }
else { else {
$data = null; $data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
} }
} }
else { break;
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors()); }
} break;
} case 'LSform':
break; switch($_REQUEST['action']) {
} case 'onAddFieldBtnClick':
break; if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['img'])) ) {
case 'LSform': $object = new $_REQUEST['objecttype']();
switch($_REQUEST['action']) { $object -> loadData($_REQUEST['objectdn']);
case 'onAddFieldBtnClick': $form = $object -> getForm($_REQUEST['idform']);
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['img'])) ) { $emptyField=$form -> getEmptyField($_REQUEST['attribute']);
$object = new $_REQUEST['objecttype'](); if ( $emptyField ) {
$object -> loadData($_REQUEST['objectdn']); $data = array(
$form = $object -> getForm($_REQUEST['idform']); 'html' => $form -> getEmptyField($_REQUEST['attribute']),
$emptyField=$form -> getEmptyField($_REQUEST['attribute']); 'img' => $_REQUEST['img'],
if ( $emptyField ) {
$data = array(
'html' => $form -> getEmptyField($_REQUEST['attribute']),
'img' => $_REQUEST['img'],
);
}
else {
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
}
}
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']
);
}
else {
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
); );
}
else {
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
}
} }
} break;
break; case 'refreshField':
case 'generatePassword': if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) {
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['idform'])) ) { $object = new $_REQUEST['objecttype']();
$object = new $_REQUEST['objecttype'](); //$object -> loadData($_REQUEST['objectdn']);
$form = $object -> getForm($_REQUEST['idform']); $form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']); $field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> generatePassword(); $val = $field -> getDisplay(true);
if ( $val ) { if ( $val ) {
$data = array( $data = array(
'generatePassword' => $val, 'html' => $val['html']
'fieldId' => $_REQUEST['fieldId']
);
}
else {
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
); );
}
else {
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
);
}
} }
} break;
break; case 'generatePassword':
} if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['idform'])) ) {
break; $object = new $_REQUEST['objecttype']();
case 'LSrelation': $form = $object -> getForm($_REQUEST['idform']);
switch($_REQUEST['action']) { $field=$form -> getElement($_REQUEST['attribute']);
case 'refreshSession': $val = $field -> generatePassword();
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['href'])) ) { if ( $val ) {
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { $data = array(
$conf = $_SESSION['LSrelation'][$_REQUEST['id']]; 'generatePassword' => $val,
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) { 'fieldId' => $_REQUEST['fieldId']
$object = new $conf['objectType'](); );
if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) { }
$relationConf = $object->config['relations'][$conf['relationName']]; else {
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) { $data = array(
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) { 'LSerror' => $GLOBALS['LSerror']->getErrors()
$objRel = new $relationConf['LSobject'](); );
$list = $objRel -> $relationConf['list_function']($object); }
$_SESSION['LSselect'][$relationConf['LSobject']]=array(); }
if (is_array($list)) { break;
foreach($list as $o) { }
$_SESSION['LSselect'][$relationConf['LSobject']][] = $o -> getDn(); break;
case 'LSrelation':
switch($_REQUEST['action']) {
case 'refreshSession':
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['href'])) ) {
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
$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();
}
} }
$data = array(
'href' => $_REQUEST['href'],
'id' => $_REQUEST['id']
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
} }
$data = array(
'href' => $_REQUEST['href'],
'id' => $_REQUEST['id']
);
} }
else { else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName); $GLOBALS['LSerror'] -> addErrorCode(1011);
} }
} }
else { else {
$GLOBALS['LSerror'] -> addErrorCode(1011); $GLOBALS['LSerror'] -> addErrorCode(1012);
} }
} }
else { else {
@ -139,105 +144,51 @@ switch($_REQUEST['template']) {
$GLOBALS['LSerror'] -> addErrorCode(1012); $GLOBALS['LSerror'] -> addErrorCode(1012);
} }
} }
else { break;
$GLOBALS['LSerror'] -> addErrorCode(1012); case 'refreshList':
} if (isset($_REQUEST['id'])) {
} if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
break; $conf = $_SESSION['LSrelation'][$_REQUEST['id']];
case 'refreshList': if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
if (isset($_REQUEST['id'])) { $object = new $conf['objectType']();
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) {
$conf = $_SESSION['LSrelation'][$_REQUEST['id']]; $relationConf = $object->config['relations'][$conf['relationName']];
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) { if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) {
$object = new $conf['objectType'](); if (is_array($_SESSION['LSselect'][$relationConf['LSobject']])) {
if (($object -> loadData($conf['objectDn'])) && (isset($object->config['relations'][$conf['relationName']]))) { if (method_exists($relationConf['LSobject'],$relationConf['update_function'])) {
$relationConf = $object->config['relations'][$conf['relationName']]; $objRel = new $relationConf['LSobject']();
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$conf['relationName'])) { if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) {
if (is_array($_SESSION['LSselect'][$relationConf['LSobject']])) { if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
if (method_exists($relationConf['LSobject'],$relationConf['update_function'])) { $list = $objRel -> $relationConf['list_function']($object);
$objRel = new $relationConf['LSobject'](); if (is_array($list)) {
if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) { foreach($list as $o) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) { $data['html'].= "<li class='LSrelation'>".$o -> getDisplayValue()."</li>\n";
$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 { else {
$data['html'] = "<li>"._('Liste vide.')."</li>\n"; $GLOBALS['LSerror'] -> addErrorCode(1013,$relationName);
} }
$data['id'] = $_REQUEST['id'];
} }
else { else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$relationName); $GLOBALS['LSerror'] -> addErrorCode(1015,$relationName);
} }
} }
else { 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(1012);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
}
break;
case 'deleteByDisplayValue':
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['value']))) {
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
$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 (!$ok) {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
$GLOBALS['LSerror'] -> addErrorCode(1);
}
} }
else { else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$conf['relationName']); $GLOBALS['LSerror'] -> addErrorCode(1011);
} }
} }
else { else {
$GLOBALS['LSerror'] -> addErrorCode(1011); $GLOBALS['LSerror'] -> addErrorCode(1012);
} }
} }
else { else {
@ -248,68 +199,122 @@ switch($_REQUEST['template']) {
$GLOBALS['LSerror'] -> addErrorCode(1012); $GLOBALS['LSerror'] -> addErrorCode(1012);
} }
} }
else { break;
$GLOBALS['LSerror'] -> addErrorCode(1012); case 'deleteByDisplayValue':
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['value']))) {
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
$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 (!$ok) {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1015,$conf['relationName']);
$GLOBALS['LSerror'] -> addErrorCode(1);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1013,$conf['relationName']);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
} }
} break;
break; }
} break;
break; case 'LSselect':
case 'LSselect': switch($_REQUEST['action']) {
switch($_REQUEST['action']) { case 'addLSselectobject-item':
case 'addLSselectobject-item': if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) {
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) { if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) {
if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) { if (!in_array($_REQUEST['objectdn'],$_SESSION['LSselect'][$_REQUEST['objecttype']])) {
if (!in_array($_REQUEST['objectdn'],$_SESSION['LSselect'][$_REQUEST['objecttype']])) { $_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn'];
}
}
else {
$_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn']; $_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn'];
} }
} }
else { break;
$_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn']; case 'dropLSselectobject-item':
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) {
if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) {
$result=array();
foreach ($_SESSION['LSselect'][$_REQUEST['objecttype']] as $val) {
if ($val!=$_REQUEST['objectdn']) {
$result[]=$val;
}
}
$_SESSION['LSselect'][$_REQUEST['objecttype']]=$result;
}
} }
} break;
break; case 'refreshSession':
case 'dropLSselectobject-item': if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['href'])) ) {
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) { $_SESSION['LSselect'][$_REQUEST['objecttype']]=array();
if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) { $values=json_decode($_REQUEST['values'],false);
$result=array(); if (is_array($values)) {
foreach ($_SESSION['LSselect'][$_REQUEST['objecttype']] as $val) { foreach($values as $val) {
if ($val!=$_REQUEST['objectdn']) { $_SESSION['LSselect'][$_REQUEST['objecttype']][]=$val;
$result[]=$val;
} }
} }
$_SESSION['LSselect'][$_REQUEST['objecttype']]=$result; $data=array(
'href' => $_REQUEST['href'],
'values' => $values
);
} }
} else {
break; $GLOBALS['LSerror'] -> addErrorCode(1012);
case 'refreshSession': $data = array(
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['href'])) ) { 'LSerror' => $GLOBALS['LSerror']->getErrors()
$_SESSION['LSselect'][$_REQUEST['objecttype']]=array(); );
$values=json_decode($_REQUEST['values'],false);
if (is_array($values)) {
foreach($values as $val) {
$_SESSION['LSselect'][$_REQUEST['objecttype']][]=$val;
}
} }
$data=array( break;
'href' => $_REQUEST['href'], }
'values' => $values break;
); }
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
$data = array(
'LSerror' => $GLOBALS['LSerror']->getErrors()
);
}
break;
}
break;
} }
if ($GLOBALS['LSerror']->errorsDefined()) { if ($GLOBALS['LSerror']->errorsDefined()) {
$data['LSerror'] = $GLOBALS['LSerror']->getErrors(); $data['LSerror'] = $GLOBALS['LSerror']->getErrors();
} }
else if (isset($_ERRORS)) {
$data['LSerror'] = $_ERRORS;
}
if (isset($_REQUEST['imgload'])) { if (isset($_REQUEST['imgload'])) {
$data['imgload'] = $_REQUEST['imgload']; $data['imgload'] = $_REQUEST['imgload'];