From 16df350e744410c72f030ffa7492aaa65e0daed1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 20 Feb 2009 14:05:22 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSmail=20:=20Cr=C3=A9ation=20d'une=20classe?= =?UTF-8?q?=20PHP=20g=C3=A9rant=20les=20d=C3=A9pendances=20=20=20d'afficha?= =?UTF-8?q?ge=20et=20les=20requ=C3=AAtes=20Ajax.=20-=20LSrelation=20:=20?= =?UTF-8?q?=20=20-=20Cr=C3=A9ation=20d'une=20classe=20PHP=20g=C3=A9rant=20?= =?UTF-8?q?les=20d=C3=A9pendances=20d'affichage=20et=20=20=20=20=20les=20r?= =?UTF-8?q?equ=C3=AAtes=20Ajax.=20=20=20-=20Modification=20du=20JS=20pour?= =?UTF-8?q?=20faire=20appels=20=C3=A0=20ces=20m=C3=A9thodes=20=20=20-=20La?= =?UTF-8?q?=20m=C3=A9thode=20displayInLSview()=20remplace=20le=20bloc=20du?= =?UTF-8?q?=20fichier=20view.php=20=20=20=20=20pour=20l'affichage=20des=20?= =?UTF-8?q?relations=20d'un=20objet.=20=20=20-=20Internationalisation.=20-?= =?UTF-8?q?=20LSselect=20:=20Cr=C3=A9ation=20d'une=20classe=20PHP=20g?= =?UTF-8?q?=C3=A9rant=20les=20d=C3=A9pendances=20=20=20d'affichage=20et=20?= =?UTF-8?q?les=20requ=C3=AAtes=20Ajax.=20-=20LSformElement=5Fpassword=20:?= =?UTF-8?q?=20=20=20-=20Ajout=20de=20m=C3=A9thodes=20statiques=20g=C3=A9ra?= =?UTF-8?q?nt=20les=20appels=20Ajax.=20=20=20-=20Modification=20du=20JS=20?= =?UTF-8?q?pour=20faire=20appels=20=C3=A0=20ces=20m=C3=A9thodes=20-=20LSfo?= =?UTF-8?q?rmElement=5Fselect=5Fobject=20:=20=20=20-=20Ajout=20de=20m?= =?UTF-8?q?=C3=A9thodes=20statiques=20g=C3=A9rant=20les=20appels=20Ajax.?= =?UTF-8?q?=20=20=20-=20Modification=20du=20JS=20pour=20faire=20appels=20?= =?UTF-8?q?=C3=A0=20ces=20m=C3=A9thodes=20-=20LSformElement=5Fmail=20:=20U?= =?UTF-8?q?tilisation=20des=20nouvelles=20fonctionnalit=C3=A9s=20pour=20?= =?UTF-8?q?=20=20g=C3=A9rer=20les=20d=C3=A9pendances.=20-=20LSformElement?= =?UTF-8?q?=5Fimage=20:=20Utilisation=20des=20nouvelles=20fonctionnalit?= =?UTF-8?q?=C3=A9s=20pour=20=20=20g=C3=A9rer=20les=20d=C3=A9pendances.=20-?= =?UTF-8?q?=20LSsession=20:=20=20=20-=20Ajout=20de=20m=C3=A9thodes=20stati?= =?UTF-8?q?ques=20g=C3=A9rant=20les=20appels=20Ajax=20des=20formulaires=20?= =?UTF-8?q?=20=20=20=20de=20login=20et=20de=20recup=C3=A9ration=20de=20mot?= =?UTF-8?q?=20de=20passe.=20=20=20-=20Modification=20des=20JS=20pour=20fai?= =?UTF-8?q?re=20appels=20=C3=A0=20ces=20m=C3=A9thodes=20=20=20-=20Ajout=20?= =?UTF-8?q?d'un=20m=C3=A9canisme=20permettant=20de=20garder=20la=20session?= =?UTF-8?q?=20PHP=20active=20=20=20-=20Modification=20de=20LSdefault.js=20?= =?UTF-8?q?pour=20g=C3=A9rer=20ce=20m=C3=A9canisme=20-=20LSform=20:=20=20?= =?UTF-8?q?=20-=20Ajout=20de=20m=C3=A9thodes=20statiques=20g=C3=A9rant=20l?= =?UTF-8?q?es=20appels=20Ajax=20des=20formulaires=20=20=20-=20Ajout=20de?= =?UTF-8?q?=20la=20m=C3=A9thode=20loadDependenciesDisplayView()=20g=C3=A9r?= =?UTF-8?q?ant=20les=20=20=20=20=20d=C3=A9pendances=20d'affichage=20d'une?= =?UTF-8?q?=20LSview.=20=20=20-=20Utilisation=20des=20nouvelles=20fonction?= =?UTF-8?q?nalit=C3=A9s=20pour=20g=C3=A9rer=20les=20=20=20=20=20d=C3=A9pen?= =?UTF-8?q?dances.=20-=20view.php=20/=20modify.php=20/select.php=20:=20Uti?= =?UTF-8?q?lisation=20des=20nouvelles=20=20=20fonctionnalit=C3=A9s=20pour?= =?UTF-8?q?=20g=C3=A9rer=20les=20d=C3=A9pendances=20et=20les=20LSrelations?= =?UTF-8?q?.=20-=20LSview=20:=20Modification=20de=20l'internationnalisatio?= =?UTF-8?q?n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/includes/class/class.LSform.php | 49 ++- .../class/class.LSformElement_image.php | 3 + .../class/class.LSformElement_mail.php | 10 +- .../class/class.LSformElement_password.php | 38 ++ .../class.LSformElement_select_object.php | 39 +- trunk/includes/class/class.LSmail.php | 87 ++++ trunk/includes/class/class.LSrelation.php | 298 +++++++++++++ trunk/includes/class/class.LSselect.php | 87 ++++ trunk/includes/class/class.LSsession.php | 33 ++ trunk/includes/js/LSdefault.js | 16 + .../js/LSformElement_password_field.js | 4 +- .../js/LSformElement_select_object_field.js | 8 +- trunk/includes/js/LSrelation.js | 16 +- trunk/includes/js/LSselect.js | 4 +- trunk/includes/js/LSsession_login.js | 9 +- .../includes/js/LSsession_recoverPassword.js | 9 +- trunk/includes/js/LSview.js | 24 +- trunk/index_ajax.php | 394 +----------------- trunk/modify.php | 2 - trunk/select.php | 2 - trunk/view.php | 87 +--- 21 files changed, 694 insertions(+), 525 deletions(-) create mode 100644 trunk/includes/class/class.LSmail.php create mode 100644 trunk/includes/class/class.LSrelation.php create mode 100644 trunk/includes/class/class.LSselect.php diff --git a/trunk/includes/class/class.LSform.php b/trunk/includes/class/class.LSform.php index d26c62a1..abd6f628 100644 --- a/trunk/includes/class/class.LSform.php +++ b/trunk/includes/class/class.LSform.php @@ -78,13 +78,13 @@ class LSform { */ function display(){ if ($this -> idForm == 'view') { - LSsession :: addJSscript('LSview.js'); - LSsession :: addJSscript('LSform.js'); + self :: loadDependenciesDisplayView(); } else { LSsession :: addJSscript('LSformElement_field.js'); LSsession :: addJSscript('LSformElement.js'); LSsession :: addJSscript('LSform.js'); + LSsession :: addCssFile('LSform.css'); } LSsession :: addHelpInfos( @@ -95,7 +95,6 @@ class LSform { ) ); - LSsession :: addCssFile('LSform.css'); $GLOBALS['Smarty'] -> assign('LSform_action',$_SERVER['PHP_SELF']); $LSform_header = "\t\n \t\n @@ -135,6 +134,25 @@ class LSform { } } + /* + * Méthode chargeant les dépendances d'affichage d'une LSview + * + * @retval void + */ + public static function loadDependenciesDisplayView() { + LSsession :: addCssFile('LSform.css'); + LSsession :: addJSscript('LSform.js'); + LSsession :: addJSconfigParam('LSview_labels', array( + 'delete_confirm_text' => _("Do you really want to delete"), + 'delete_confirm_title' => _("Caution"), + 'delete_confirm_validate' => _("Delete") + )); + if (LSsession :: loadLSclass('LSconfirmBox')) { + LSconfirmBox :: loadDependenciesDisplay(); + } + LSsession :: addJSscript('LSview.js'); + } + /** * Affiche la vue * @@ -143,12 +161,7 @@ class LSform { * @retval void */ function displayView(){ - LSsession :: addCssFile('LSform.css'); - LSsession :: addJSscript('LSform.js'); - LSsession :: addJSconfigParam('LSview_delete_confirm_text',_("Do you really want to delete")); - LSsession :: addJSconfigParam('LSview_delete_confirm_title',_("Caution")); - LSsession :: addJSconfigParam('LSview_delete_confirm_yes_btn_label',_("Delete")); - LSsession :: addJSconfigParam('LSview_delete_confirm_no_btn_label',_("Cancel")); + self :: loadDependenciesDisplayView(); $LSform_object = array( 'type' => $this -> ldapObject -> getType(), @@ -527,6 +540,24 @@ class LSform { $this -> maxFileSize = $size; } + + public static function ajax_onAddFieldBtnClick(&$data) { + if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['fieldId'])) ) { + if (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']), + 'fieldId' => $_REQUEST['fieldId'], + 'fieldtype' => get_class($form -> getElement($_REQUEST['attribute'])) + ); + } + } + } + } } /** diff --git a/trunk/includes/class/class.LSformElement_image.php b/trunk/includes/class/class.LSformElement_image.php index 69a79fce..0c288269 100644 --- a/trunk/includes/class/class.LSformElement_image.php +++ b/trunk/includes/class/class.LSformElement_image.php @@ -73,6 +73,9 @@ class LSformElement_image extends LSformElement { if ($this -> form -> definedError($this -> name)) { $GLOBALS['Smarty'] -> assign('LSformElement_image_errors',true); } + if (LSsession :: loadLSclass('LSsmoothbox')) { + LSsmoothbox :: loadDependenciesDisplay(); + } LSsession :: addJSscript('LSformElement_image.js'); } return $return; diff --git a/trunk/includes/class/class.LSformElement_mail.php b/trunk/includes/class/class.LSformElement_mail.php index f1681b1a..f0f214e7 100644 --- a/trunk/includes/class/class.LSformElement_mail.php +++ b/trunk/includes/class/class.LSformElement_mail.php @@ -34,15 +34,8 @@ LSsession :: loadLSclass('LSformElement_text'); class LSformElement_mail extends LSformElement_text { var $JSscripts = array( - 'LSmail.js', - 'LSsmoothbox.js', - 'LSconfirmBox.js', 'LSformElement_mail.js' ); - var $CSSfiles = array( - 'LSsmoothbox.css', - 'LSconfirmBox.css' - ); var $fetchVariables = array( 'uriClass' => 'LSformElement_mail', @@ -58,6 +51,9 @@ class LSformElement_mail extends LSformElement_text { 'mail' => _("Send a mail from here.") ) ); + if (LSsession :: loadLSclass('LSmail')) { + LSmail :: loadDependenciesDisplay(); + } return parent :: getDisplay($return); } } diff --git a/trunk/includes/class/class.LSformElement_password.php b/trunk/includes/class/class.LSformElement_password.php index 23b051cc..94ded64f 100644 --- a/trunk/includes/class/class.LSformElement_password.php +++ b/trunk/includes/class/class.LSformElement_password.php @@ -20,6 +20,7 @@ ******************************************************************************/ +LSsession :: loadLSclass('LSformElement'); /** * Element password d'un formulaire pour LdapSaisie @@ -186,6 +187,43 @@ class LSformElement_password extends LSformElement { } return true; } + + public static function ajax_verifyPassword(&$data) { + if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldValue'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['objectdn'])) ) { + if (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 + ); + } + } + } + + public static function ajax_generatePassword(&$data) { + if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) { + if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { + $object = new $_REQUEST['objecttype'](); + if ($object) { + $form = $object -> getForm($_REQUEST['idform']); + if ($form) { + $field=$form -> getElement($_REQUEST['attribute']); + if ($field) { + $val = $field -> generatePassword(); + if ( $val ) { + $data = array( + 'generatePassword' => $val + ); + } + } + } + } + } + } + } } ?> diff --git a/trunk/includes/class/class.LSformElement_select_object.php b/trunk/includes/class/class.LSformElement_select_object.php index a527a0ec..dd273537 100644 --- a/trunk/includes/class/class.LSformElement_select_object.php +++ b/trunk/includes/class/class.LSformElement_select_object.php @@ -20,6 +20,7 @@ ******************************************************************************/ +LSsession :: loadLSclass('LSformElement'); /** * Element select d'un formulaire pour LdapSaisie @@ -84,14 +85,9 @@ class LSformElement_select_object extends LSformElement { LSsession :: addJSscript('LSformElement_select_object_field.js'); LSsession :: addJSscript('LSformElement_select_object.js'); - LSsession :: addJSscript('LSform.js'); - LSsession :: addJSscript('LSselect.js'); - LSsession :: addCssFile('LSselect.css'); - LSsession :: addJSscript('LSsmoothbox.js'); - LSsession :: addCssFile('LSsmoothbox.css'); - LSsession :: addJSscript('LSconfirmBox.js'); - LSsession :: addCssFile('LSconfirmBox.css'); - + if (LSsession :: loadLSclass('LSselect')) { + LSselect :: loadDependenciesDisplay(); + } } $return['html'] = $this -> fetchTemplate(NULL,array('selectableObject' => $this -> selectableObject)); return $return; @@ -163,6 +159,33 @@ class LSformElement_select_object extends LSformElement { } return array(); } + + public static function ajax_refresh(&$data) { + if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) { + if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { + $object = new $_REQUEST['objecttype'](); + $form = $object -> getForm($_REQUEST['idform']); + $field=$form -> getElement($_REQUEST['attribute']); + $val = $field -> getValuesFromSession(); + if ( $val ) { + $data = array( + 'objects' => $val + ); + } + } + } + } + + public static function ajax_searchAdd(&$data) { + if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) { + if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { + $object = new $_REQUEST['objecttype'](); + $form = $object -> getForm($_REQUEST['idform']); + $field=$form -> getElement($_REQUEST['attribute']); + $data['objects'] = $field -> searchAdd($_REQUEST['pattern']); + } + } + } } ?> diff --git a/trunk/includes/class/class.LSmail.php b/trunk/includes/class/class.LSmail.php new file mode 100644 index 00000000..10321564 --- /dev/null +++ b/trunk/includes/class/class.LSmail.php @@ -0,0 +1,87 @@ + loadData($_REQUEST['object']['dn']); + $msg = $obj -> getFData($_REQUEST['msg']); + $subject = $obj -> getFData($_REQUEST['subject']); + } + } + else { + $msg = $_REQUEST['msg']; + $subject = $_REQUEST['subject']; + } + + $GLOBALS['Smarty'] -> assign('LSmail_msg',$msg); + $GLOBALS['Smarty'] -> assign('LSmail_subject',$subject); + if (is_array($_REQUEST['mails'])) { + $GLOBALS['Smarty'] -> assign('LSmail_mails',$_REQUEST['mails']); + } + else if(empty($_REQUEST['mails'])) { + $GLOBALS['Smarty'] -> assign('LSmail_mails',array($_REQUEST['mails'])); + } + $GLOBALS['Smarty'] -> assign('LSmail_mail_label',_('Email')); + $GLOBALS['Smarty'] -> assign('LSmail_subject_label',_('Title')); + $GLOBALS['Smarty'] -> assign('LSmail_msg_label',_('Message')); + + $data = array( + 'html' => $GLOBALS['Smarty'] -> fetch('LSmail.tpl') + ); + } + + public static function ajax_send(&$data) { + if (isset($_REQUEST['infos'])) { + if (LSsession ::loadLSaddon('mail')) { + if(sendMail($_REQUEST['infos']['mail'],$_REQUEST['infos']['subject'],$_REQUEST['infos']['msg'])) { + $data = array( + 'msgok' => _("Your message has been sent successfully.") + ); + } + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + +} + +?> diff --git a/trunk/includes/class/class.LSrelation.php b/trunk/includes/class/class.LSrelation.php new file mode 100644 index 00000000..a9197ca1 --- /dev/null +++ b/trunk/includes/class/class.LSrelation.php @@ -0,0 +1,298 @@ + _('Do you really want to delete'), + 'close_confirm_title' => _('Warning'), + 'close_confirm_validate' => _('Delete') + )); + } + + /* + * Méthode chargeant les informations des LSrelations d'un objet et définissant + * les variables templates pour l'affichage dans une LSview. + * + * @param[in] LSldapObject L'objet dont on cherche les LSrelations + * + * @retval void + */ + public static function displayInLSview($object) { + if (($object instanceof LSldapObject) && (is_array($object -> config['LSrelation']))) { + $LSrelations=array(); + $LSrelations_JSparams=array(); + foreach($object -> config['LSrelation'] as $relationName => $relationConf) { + if (LSsession :: relationCanAccess($object -> getValue('dn'),$object->getType(),$relationName)) { + $return=array( + 'label' => $relationConf['label'], + 'LSobject' => $relationConf['LSobject'] + ); + + if (isset($relationConf['emptyText'])) { + $return['emptyText'] = $relationConf['emptyText']; + } + else { + $return['emptyText'] = _('No object.'); + } + + $id=rand(); + $return['id']=$id; + $LSrelations_JSparams[$id]=array( + 'emptyText' => $return['emptyText'] + ); + $_SESSION['LSrelation'][$id] = array( + 'relationName' => $relationName, + 'objectType' => $object -> getType(), + 'objectDn' => $object -> getDn(), + ); + if (LSsession :: relationCanEdit($object -> getValue('dn'),$object->getType(),$relationName)) { + $return['actions'][] = array( + 'label' => _('Modify'), + 'url' => 'select.php?LSobject='.$relationConf['LSobject'].'&multiple=1', + 'action' => 'modify' + ); + } + + if (LSsession :: loadLSclass('LSrelation')) { + LSrelation :: loadDependenciesDisplay(); + } + + if(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) { + $o_infos = array( + 'text' => $o -> getDisplayName(NULL,true), + 'dn' => $o -> getDn() + ); + $return['objectList'][] = $o_infos; + } + } + else { + $return['objectList']=array(); + } + } + else { + LSerror :: addErrorCode('LSrelations_01',$relationName); + } + $LSrelations[]=$return; + } + else { + LSerror :: addErrorCode('LSrelations_04',array('relation' => $relationName,'LSobject' => $relationConf['LSobject'])); + } + } + } + + $GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations); + LSsession :: addJSconfigParam('LSrelations',$LSrelations_JSparams); + } + } + + public static function ajax_refreshSession(&$return) { + if ((isset($_REQUEST['id'])) && (isset($_REQUEST['href'])) ) { + if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { + $conf = $_SESSION['LSrelation'][$_REQUEST['id']]; + if (LSsession ::loadLSobject($conf['objectType'])) { + $object = new $conf['objectType'](); + if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { + $relationConf = $object->config['LSrelation'][$conf['relationName']]; + if (LSsession ::loadLSobject($relationConf['LSobject'])) { + if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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(); + } + } + $return = array( + 'href' => $_REQUEST['href'], + 'id' => $_REQUEST['id'] + ); + } + else { + LSerror :: addErrorCode('LSrelations_01',$relationName); + } + } + else { + LSerror :: addErrorCode('LSsession_11'); + } + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + } + + public static function ajax_refreshList(&$data) { + if (isset($_REQUEST['id'])) { + if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { + $conf = $_SESSION['LSrelation'][$_REQUEST['id']]; + if (LSsession ::loadLSobject($conf['objectType'])) { + $object = new $conf['objectType'](); + if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { + $relationConf = $object->config['LSrelation'][$conf['relationName']]; + if (LSsession ::loadLSobject($relationConf['LSobject'])) { + if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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)&&(!empty($list))) { + foreach($list as $o) { + $data['html'].= "
  • ".$o -> getDisplayName(NULL,true)."
  • \n"; + } + } + else { + if (isset($relationConf['emptyText'])) { + $data['html'] = "
  • ".$relationConf['emptyText']."
  • \n"; + } + else { + $data['html'] = "
  • "._('No object.')."
  • \n"; + } + } + $data['id'] = $_REQUEST['id']; + } + else { + LSerror :: addErrorCode('LSrelations_01',$relationName); + } + } + else { + LSerror :: addErrorCode('LSrelations_03',$relationName); + } + } + else { + LSerror :: addErrorCode('LSrelations_02',$relationName); + } + } + } + else { + LSerror :: addErrorCode('LSsession_11'); + } + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + } + + public static function ajax_deleteByDn(&$data) { + if ((isset($_REQUEST['id'])) && (isset($_REQUEST['dn']))) { + if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { + $conf = $_SESSION['LSrelation'][$_REQUEST['id']]; + if (LSsession ::loadLSobject($conf['objectType'])) { + $object = new $conf['objectType'](); + if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { + $relationConf = $object->config['LSrelation'][$conf['relationName']]; + if (LSsession ::loadLSobject($relationConf['LSobject'])) { + if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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 -> getDn() == $_REQUEST['dn']) { + if (!$o -> $relationConf['remove_function']($object)) { + LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); + } + else { + $ok = true; + } + } + } + if (!$ok) { + LSdebug($_REQUEST['value']." introuvé parmi la liste"); + LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); + } + else { + $data=array( + 'dn' => $_REQUEST['dn'] + ); + } + } + else { + LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); + } + } + else { + LSerror :: addErrorCode('LSrelations_01',$conf['relationName']); + } + } + else { + LSerror :: addErrorCode('LSsession_11'); + } + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } + } +} + +?> diff --git a/trunk/includes/class/class.LSselect.php b/trunk/includes/class/class.LSselect.php new file mode 100644 index 00000000..266b76f4 --- /dev/null +++ b/trunk/includes/class/class.LSselect.php @@ -0,0 +1,87 @@ + $values + ); + } + else { + LSerror :: addErrorCode('LSsession_12'); + } + } +} + +?> diff --git a/trunk/includes/class/class.LSsession.php b/trunk/includes/class/class.LSsession.php index 0279bd84..cfbf7e53 100644 --- a/trunk/includes/class/class.LSsession.php +++ b/trunk/includes/class/class.LSsession.php @@ -1008,6 +1008,10 @@ class LSsession { $JSscript_txt.="\n"; } + if (!isset(self :: $ldapServer['keepLSsessionActive']) || (self :: $ldapServer['keepLSsessionActive'])) { + self :: addJSconfigParam('keepLSsessionActive',ini_get('session.gc_maxlifetime')); + } + $GLOBALS['Smarty'] -> assign('LSjsConfig',json_encode(self :: $_JSconfigParams)); if ($GLOBALS['LSdebug']['active']) { @@ -1867,6 +1871,35 @@ class LSsession { _("LSrelation : Some parameters are missing in the invocation of the methods of handling relations standard (Methode : %{meth}).") ); } + + public static function ajax_onLdapServerChangedLogin(&$data) { + if ( isset($_REQUEST['server']) ) { + self :: setLdapServer($_REQUEST['server']); + $data = array(); + if ( self :: LSldapConnect() ) { + session_start(); + if (isset($_SESSION['LSsession_topDn'])) { + $sel = $_SESSION['LSsession_topDn']; + } + else { + $sel = NULL; + } + $list = self :: getSubDnLdapServerOptions($sel); + if (is_string($list)) { + $data['list_topDn'] = ""; + $data['subDnLabel'] = self :: getSubDnLabel(); + } + } + $data['recoverPassword'] = isset(self :: $ldapServer['recoverPassword']); + } + } + + public static function ajax_onLdapServerChangedRecoverPassword(&$data) { + if ( isset($_REQUEST['server']) ) { + self :: setLdapServer($_REQUEST['server']); + $data=array('recoverPassword' => isset(self :: $ldapServer['recoverPassword'])); + } + } } ?> diff --git a/trunk/includes/js/LSdefault.js b/trunk/includes/js/LSdefault.js index cb3f60f4..6b93d75b 100644 --- a/trunk/includes/js/LSdefault.js +++ b/trunk/includes/js/LSdefault.js @@ -65,6 +65,11 @@ var LSdefault = new Class({ document.addEvent('keyup',this.onWantMoo.bindWithEvent(this)); this.LStips = new Tips('.LStips'); + + if ($type(this.LSjsConfig['keepLSsessionActive'])) { + this.LSjsConfig['keepLSsessionActive'] = (Math.round(this.LSjsConfig['keepLSsessionActive']*0.70)*1000); + this.keepLSsession.delay(this.LSjsConfig['keepLSsessionActive'],this); + } }, onWantMoo: function(event) { @@ -288,6 +293,17 @@ var LSdefault = new Class({ removeTip: function(el) { this.LStips.detach(el); + }, + + keepLSsession: function() { + LSdebug('Keep LSsession'); + data: {} + new Request({url: 'index_ajax.php', data: {}, onSuccess: this.keepLSsessionComplete.bind(this)}).send(); + }, + + keepLSsessionComplete: function() { + LSdebug('Keep LSsession OK'); + this.keepLSsession.delay(this.LSjsConfig['keepLSsessionActive'],this); } }); diff --git a/trunk/includes/js/LSformElement_password_field.js b/trunk/includes/js/LSformElement_password_field.js index 056cc2d7..4d6e3883 100644 --- a/trunk/includes/js/LSformElement_password_field.js +++ b/trunk/includes/js/LSformElement_password_field.js @@ -136,7 +136,7 @@ var LSformElement_password_field = new Class({ onGenerateBtnClick: function() { var data = { - template: 'LSform', + template: 'LSformElement_password', action: 'generatePassword', attribute: this.name, objecttype: varLSform.objecttype, @@ -183,7 +183,7 @@ var LSformElement_password_field = new Class({ onVerifyBtnClick: function() { var data = { - template: 'LSform', + template: 'LSformElement_password', action: 'verifyPassword', attribute: this.name, objecttype: varLSform.objecttype, diff --git a/trunk/includes/js/LSformElement_select_object_field.js b/trunk/includes/js/LSformElement_select_object_field.js index 36080f4a..458355ed 100644 --- a/trunk/includes/js/LSformElement_select_object_field.js +++ b/trunk/includes/js/LSformElement_select_object_field.js @@ -114,8 +114,8 @@ var LSformElement_select_object_field = new Class({ onLSsmoothboxValid: function() { var data = { - template: 'LSform', - action: 'LSformElement_select_object_refresh', + template: 'LSformElement_select_object', + action: 'refresh', attribute: this.name, objecttype: varLSform.objecttype, objectdn: varLSform.objectdn, @@ -321,8 +321,8 @@ var LSformElement_select_object_field = new Class({ if (this._lastSearch!=this.searchAddInput.value) { this._lastSearch=this.searchAddInput.value; var data = { - template: 'LSform', - action: 'LSformElement_select_object_searchAdd', + template: 'LSformElement_select_object', + action: 'searchAdd', attribute: this.name, objecttype: varLSform.objecttype, idform: varLSform.idform, diff --git a/trunk/includes/js/LSrelation.js b/trunk/includes/js/LSrelation.js index c6d62f2a..3cbfd70e 100644 --- a/trunk/includes/js/LSrelation.js +++ b/trunk/includes/js/LSrelation.js @@ -1,5 +1,14 @@ var LSrelation = new Class({ initialize: function(){ + this.labels = varLSdefault.LSjsConfig['LSrelation_labels']; + if (!$type(this.labels)) { + this.labels = { + close_confirm_text: 'Do you really want to delete', + close_confirm_title: 'Warning', + close_confirm_validate: 'Delete' + }; + } + this.edit = 0; this.deleteBtn = []; this.deleteBtnId = 0; @@ -35,10 +44,9 @@ var LSrelation = new Class({ if (this._confirmDelete) { var a = img.getPrevious('a'); this.confirmBox = new LSconfirmBox({ - text: 'Do you really want to delete "'+a.innerHTML+'" ?', - title: 'Warning', - validate_label: 'Delete', - cancel_label: 'Cancel', + text: this.labels.close_confirm_text + ' "'+a.innerHTML+'" ?', + title: this.labels.close_confirm_title, + validate_label: this.labels.close_confirm_validate, startElement: img, onConfirm: this.deleteFromImg.bind(this,img) }); diff --git a/trunk/includes/js/LSselect.js b/trunk/includes/js/LSselect.js index bdf83fe7..bed1a0d5 100644 --- a/trunk/includes/js/LSselect.js +++ b/trunk/includes/js/LSselect.js @@ -52,7 +52,7 @@ var LSselect = new Class({ if (checkbox.checked) { var data = { template: 'LSselect', - action: 'addLSselectobject-item', + action: 'addItem', objectdn: checkbox.value, objecttype: $('LSselect-object').getProperties('caption').caption, multiple: this.multiple @@ -61,7 +61,7 @@ var LSselect = new Class({ else { var data = { template: 'LSselect', - action: 'dropLSselectobject-item', + action: 'dropItem', objectdn: checkbox.value, objecttype: $('LSselect-object').getProperties('caption').caption, multiple: this.multiple diff --git a/trunk/includes/js/LSsession_login.js b/trunk/includes/js/LSsession_login.js index 38cb7f3a..0a53c87a 100644 --- a/trunk/includes/js/LSsession_login.js +++ b/trunk/includes/js/LSsession_login.js @@ -26,10 +26,11 @@ var LSsession_login = new Class({ var imgload = varLSdefault.loadingImgDisplay(this.loading_zone,'inside','big'); var server = this.select_ldapserver.value; var data = { - template: 'login', - action: 'onLdapServerChanged', - server: server, - imgload: imgload + noLSsession: 1, + template: 'LSsession', + action: 'onLdapServerChangedLogin', + server: server, + imgload: imgload }; new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send(); }, diff --git a/trunk/includes/js/LSsession_recoverPassword.js b/trunk/includes/js/LSsession_recoverPassword.js index 4c20cc43..f42d8076 100644 --- a/trunk/includes/js/LSsession_recoverPassword.js +++ b/trunk/includes/js/LSsession_recoverPassword.js @@ -25,10 +25,11 @@ var LSsession_recoverPassword = new Class({ var imgload = varLSdefault.loadingImgDisplay(this.loading_zone,'inside','big'); var server = this.select_ldapserver.value; var data = { - template: 'recoverPassword', - action: 'onLdapServerChanged', - server: server, - imgload: imgload + noLSsession: 1, + template: 'LSsession', + action: 'onLdapServerChangedRecoverPassword', + server: server, + imgload: imgload }; new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send(); }, diff --git a/trunk/includes/js/LSview.js b/trunk/includes/js/LSview.js index 8228a011..3a94ae25 100644 --- a/trunk/includes/js/LSview.js +++ b/trunk/includes/js/LSview.js @@ -1,5 +1,14 @@ var LSview = new Class({ initialize: function(){ + this.labels = varLSdefault.LSjsConfig['LSview_labels']; + if (!$type(this.labels)) { + this.labels = { + delete_confirm_text: "Do you really want to delete", + delete_confirm_title: "Caution", + delete_confirm_validate: "Delete" + }; + } + $$('td.LSobject-list-names').each(function(el) { el.addEvent('click',this.onTdLSobjectListNamesClick.bind(this,el)); }, this); @@ -43,7 +52,7 @@ var LSview = new Class({ this._confirmBoxOpen = 1; var name = a.getParent().getPrevious('td').getElement('a').innerHTML; this.confirmBox = new LSconfirmBox({ - text: varLSdefault.LSjsConfig['LSview_delete_label'] + ' "'+name+'" ?', + text: this.labels.delete_confirm_text + ' "'+name+'" ?', startElement: a, onConfirm: this.removeFromA.bind(this,a), onClose: this.onConfirmBoxClose.bind(this) @@ -57,13 +66,12 @@ var LSview = new Class({ this._confirmBoxOpen = 1; var name = $('LSview_title').innerHTML; this.confirmBox = new LSconfirmBox({ - text: varLSdefault.LSjsConfig['LSview_delete_confirm_text'] + ' "'+name+'" ?', - title: varLSdefault.LSjsConfig['LSview_delete_confirm_title'], - validate_label: varLSdefault.LSjsConfig['LSview_delete_confirm_yes_btn_label'], - cancel_label: varLSdefault.LSjsConfig['LSview_delete_confirm_no_btn_label'], - startElement: a, - onConfirm: this.removeFromA.bind(this,a), - onClose: this.onConfirmBoxClose.bind(this) + text: this.labels.delete_confirm_text + ' "'+name+'" ?', + title: this.labels.delete_confirm_title, + validate_label: this.labels.delete_confirm_yes_btn, + startElement: a, + onConfirm: this.removeFromA.bind(this,a), + onClose: this.onConfirmBoxClose.bind(this) }); } }, diff --git a/trunk/index_ajax.php b/trunk/index_ajax.php index ba449d02..c18ea578 100644 --- a/trunk/index_ajax.php +++ b/trunk/index_ajax.php @@ -2,7 +2,7 @@ require_once 'includes/class/class.LSsession.php'; -if (($_REQUEST['template'] != 'login')&&($_REQUEST['template'] != 'recoverPassword')) { +if (!isset($_REQUEST['noLSsession'])) { if ( !LSsession :: startLSsession() ) { LSerror :: addErrorCode('LSsession_22'); $_ERRORS = true; @@ -14,392 +14,12 @@ else { $data=NULL; if (!isset($_ERRORS)) { - switch($_REQUEST['template']) { - case 'login': - switch($_REQUEST['action']) { - case 'onLdapServerChanged': - if ( isset($_REQUEST['server']) ) { - LSsession :: setLdapServer($_REQUEST['server']); - $data = array(); - if ( LSsession :: LSldapConnect() ) { - session_start(); - if (isset($_SESSION['LSsession_topDn'])) { - $sel = $_SESSION['LSsession_topDn']; - } - else { - $sel = NULL; - } - $list = LSsession :: getSubDnLdapServerOptions($sel); - if (is_string($list)) { - $data['list_topDn'] = ""; - $data['subDnLabel'] = LSsession :: getSubDnLabel(); - } - } - $data['recoverPassword'] = isset(LSsession::$ldapServer['recoverPassword']); - } - break; - } - break; - case 'recoverPassword': - switch($_REQUEST['action']) { - case 'onLdapServerChanged': - if ( isset($_REQUEST['server']) ) { - LSsession :: setLdapServer($_REQUEST['server']); - $data=array('recoverPassword' => isset(LSsession::$ldapServer['recoverPassword'])); - } - break; - } - break; - case 'LSform': - switch($_REQUEST['action']) { - case 'onAddFieldBtnClick': - if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['fieldId'])) ) { - if (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']), - 'fieldId' => $_REQUEST['fieldId'], - 'fieldtype' => get_class($form -> getElement($_REQUEST['attribute'])) - ); - } - } - } - break; - case 'LSformElement_select_object_refresh': - if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) { - if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { - $object = new $_REQUEST['objecttype'](); - $form = $object -> getForm($_REQUEST['idform']); - $field=$form -> getElement($_REQUEST['attribute']); - $val = $field -> getValuesFromSession(); - if ( $val ) { - $data = array( - 'objects' => $val - ); - } - } - } - break; - case 'LSformElement_select_object_searchAdd': - if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) { - if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { - $object = new $_REQUEST['objecttype'](); - $form = $object -> getForm($_REQUEST['idform']); - $field=$form -> getElement($_REQUEST['attribute']); - $data['objects'] = $field -> searchAdd($_REQUEST['pattern']); - } - } - break; - case 'generatePassword': - if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) { - if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { - $object = new $_REQUEST['objecttype'](); - if ($object) { - $form = $object -> getForm($_REQUEST['idform']); - if ($form) { - $field=$form -> getElement($_REQUEST['attribute']); - if ($field) { - $val = $field -> generatePassword(); - if ( $val ) { - $data = array( - 'generatePassword' => $val - ); - } - } - } - } - } - } - break; - case 'verifyPassword': - if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldValue'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['objectdn'])) ) { - if (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 - ); - } - } - break; - } - 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 (LSsession ::loadLSobject($conf['objectType'])) { - $object = new $conf['objectType'](); - if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { - $relationConf = $object->config['LSrelation'][$conf['relationName']]; - if (LSsession ::loadLSobject($relationConf['LSobject'])) { - if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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 { - LSerror :: addErrorCode('LSrelations_01',$relationName); - } - } - else { - LSerror :: addErrorCode('LSsession_11'); - } - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - break; - case 'refreshList': - if (isset($_REQUEST['id'])) { - if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { - $conf = $_SESSION['LSrelation'][$_REQUEST['id']]; - if (LSsession ::loadLSobject($conf['objectType'])) { - $object = new $conf['objectType'](); - if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { - $relationConf = $object->config['LSrelation'][$conf['relationName']]; - if (LSsession ::loadLSobject($relationConf['LSobject'])) { - if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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)&&(!empty($list))) { - foreach($list as $o) { - $data['html'].= "
  • ".$o -> getDisplayName(NULL,true)."
  • \n"; - } - } - else { - if (isset($relationConf['emptyText'])) { - $data['html'] = "
  • ".$relationConf['emptyText']."
  • \n"; - } - else { - $data['html'] = "
  • "._('No object.')."
  • \n"; - } - } - $data['id'] = $_REQUEST['id']; - } - else { - LSerror :: addErrorCode('LSrelations_01',$relationName); - } - } - else { - LSerror :: addErrorCode('LSrelations_03',$relationName); - } - } - else { - LSerror :: addErrorCode('LSrelations_02',$relationName); - } - } - } - else { - LSerror :: addErrorCode('LSsession_11'); - } - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - break; - case 'deleteByDn': - if ((isset($_REQUEST['id'])) && (isset($_REQUEST['dn']))) { - if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) { - $conf = $_SESSION['LSrelation'][$_REQUEST['id']]; - if (LSsession ::loadLSobject($conf['objectType'])) { - $object = new $conf['objectType'](); - if (($object -> loadData($conf['objectDn'])) && (isset($object->config['LSrelation'][$conf['relationName']]))) { - $relationConf = $object->config['LSrelation'][$conf['relationName']]; - if (LSsession ::loadLSobject($relationConf['LSobject'])) { - if (LSsession :: relationCanEdit($object -> getValue('dn'),$object -> getType(),$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 -> getDn() == $_REQUEST['dn']) { - if (!$o -> $relationConf['remove_function']($object)) { - LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); - } - else { - $ok = true; - } - } - } - if (!$ok) { - LSdebug($_REQUEST['value']." introuvé parmi la liste"); - LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); - } - else { - $data=array( - 'dn' => $_REQUEST['dn'] - ); - } - } - else { - LSerror :: addErrorCode('LSrelations_03',$conf['relationName']); - } - } - else { - LSerror :: addErrorCode('LSrelations_01',$conf['relationName']); - } - } - else { - LSerror :: addErrorCode('LSsession_11'); - } - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - break; - } - break; - case 'LSselect': - switch($_REQUEST['action']) { - case 'addLSselectobject-item': - if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['multiple']))) { - if (!$_REQUEST['multiple']) { - $_SESSION['LSselect'][$_REQUEST['objecttype']]=array($_REQUEST['objectdn']); - } - else if (is_array($_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']; - } - } - break; - 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; - case 'refreshSession': - if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) ) { - $_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( - 'values' => $values - ); - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - break; - } - break; - case 'LSmail': - switch($_REQUEST['action']) { - case 'display': - if (isset($_REQUEST['object']['type']) && isset($_REQUEST['object']['dn'])) { - if (LSsession ::loadLSobject($_REQUEST['object']['type'])) { - $obj = new $_REQUEST['object']['type'](); - $obj -> loadData($_REQUEST['object']['dn']); - $msg = $obj -> getFData($_REQUEST['msg']); - $subject = $obj -> getFData($_REQUEST['subject']); - } - } - else { - $msg = $_REQUEST['msg']; - $subject = $_REQUEST['subject']; - } - - $GLOBALS['Smarty'] -> assign('LSmail_msg',$msg); - $GLOBALS['Smarty'] -> assign('LSmail_subject',$subject); - if (is_array($_REQUEST['mails'])) { - $GLOBALS['Smarty'] -> assign('LSmail_mails',$_REQUEST['mails']); - } - else if(empty($_REQUEST['mails'])) { - $GLOBALS['Smarty'] -> assign('LSmail_mails',array($_REQUEST['mails'])); - } - $GLOBALS['Smarty'] -> assign('LSmail_mail_label',_('Email')); - $GLOBALS['Smarty'] -> assign('LSmail_subject_label',_('Title')); - $GLOBALS['Smarty'] -> assign('LSmail_msg_label',_('Message')); - - $data = array( - 'html' => $GLOBALS['Smarty'] -> fetch('LSmail.tpl') - ); - break; - case 'send': - if (isset($_REQUEST['infos'])) { - if (LSsession ::loadLSaddon('mail')) { - if(sendMail($_REQUEST['infos']['mail'],$_REQUEST['infos']['subject'],$_REQUEST['infos']['msg'])) { - $data = array( - 'msgok' => _("Your message has been sent successfully.") - ); - } - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - } - break; + $class = $_REQUEST['template']; + if (LSsession :: loadLSclass($class)) { + $meth = 'ajax_'.$_REQUEST['action']; + if (method_exists($class,$meth)) { + call_user_func(array($class,$meth),&$data); + } } } diff --git a/trunk/modify.php b/trunk/modify.php index 9a3a85d4..605fb944 100644 --- a/trunk/modify.php +++ b/trunk/modify.php @@ -108,8 +108,6 @@ if(LSsession :: startLSsession()) { ); } - LSsession :: addJSscript('LSsmoothbox.js'); - LSsession :: addCssFile('LSsmoothbox.css'); $GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions); LSsession :: setTemplate('modify.tpl'); $form -> display(); diff --git a/trunk/select.php b/trunk/select.php index 73f55037..a4b3c0b3 100644 --- a/trunk/select.php +++ b/trunk/select.php @@ -285,8 +285,6 @@ if(LSsession :: startLSsession()) { $searchData['objectList'][$i]['select']=$select; } - LSsession :: addJSscript('LSview.js'); - $GLOBALS['Smarty']->assign('LSview_search',array( 'action' => $_SERVER['PHP_SELF'], 'submit' => _('Search'), diff --git a/trunk/view.php b/trunk/view.php index 463e86df..bb6fe79d 100644 --- a/trunk/view.php +++ b/trunk/view.php @@ -76,88 +76,11 @@ if(LSsession :: startLSsession()) { $view -> displayView(); // LSrelations - if (is_array($object -> config['LSrelation'])) { - $LSrelations=array(); - $LSrelations_JSparams=array(); - foreach($object -> config['LSrelation'] as $relationName => $relationConf) { - if (LSsession :: relationCanAccess($object -> getValue('dn'),$LSobject,$relationName)) { - $return=array( - 'label' => $relationConf['label'], - 'LSobject' => $relationConf['LSobject'] - ); - - if (isset($relationConf['emptyText'])) { - $return['emptyText'] = $relationConf['emptyText']; - } - else { - $return['emptyText'] = _('No object.'); - } - - $id=rand(); - $return['id']=$id; - $LSrelations_JSparams[$id]=array( - 'emptyText' => $return['emptyText'] - ); - $_SESSION['LSrelation'][$id] = array( - 'relationName' => $relationName, - 'objectType' => $object -> getType(), - 'objectDn' => $object -> getDn(), - ); - if (LSsession :: relationCanEdit($object -> getValue('dn'),$LSobject,$relationName)) { - $return['actions'][] = array( - 'label' => _('Modify'), - 'url' => 'select.php?LSobject='.$relationConf['LSobject'].'&multiple=1', - 'action' => 'modify' - ); - } - - LSsession :: addJSscript('LSselect.js'); - LSsession :: addCssFile('LSselect.css'); - LSsession :: addJSscript('LSsmoothbox.js'); - LSsession :: addCssFile('LSsmoothbox.css'); - LSsession :: addJSscript('LSrelation.js'); - LSsession :: addCssFile('LSrelation.css'); - LSsession :: addJSscript('LSconfirmBox.js'); - LSsession :: addCssFile('LSconfirmBox.css'); - LSsession :: addJSscript('LSview.js'); - - if(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) { - $o_infos = array( - 'text' => $o -> getDisplayName(NULL,true), - 'dn' => $o -> getDn() - ); - $return['objectList'][] = $o_infos; - } - } - else { - $return['objectList']=array(); - } - } - else { - LSerror :: addErrorCode('LSrelations_01',$relationName); - } - $LSrelations[]=$return; - } - else { - LSerror :: addErrorCode('LSrelations_04',array('relation' => $relationName,'LSobject' => $relationConf['LSobject'])); - } - } - } - - LSsession :: addJSscript('LSconfirmBox.js'); - LSsession :: addCssFile('LSconfirmBox.css'); - $GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations); - LSsession :: addJSconfigParam('LSrelations',$LSrelations_JSparams); + if (LSsession :: loadLSclass('LSrelation')) { + LSrelation :: displayInLSview($object); } $GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions); - LSsession :: addJSscript('LSsmoothbox.js'); - LSsession :: addCssFile('LSsmoothbox.css'); LSsession :: setTemplate('view.tpl'); } else { @@ -440,9 +363,9 @@ if(LSsession :: startLSsession()) { $GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']); } // Fin Pagination - LSsession :: addJSscript('LSconfirmBox.js'); - LSsession :: addCssFile('LSconfirmBox.css'); - LSsession :: addJSscript('LSview.js'); + if (LSsession :: loadLSclass('LSform')) { + LSform :: loadDependenciesDisplayView(); + } $GLOBALS['Smarty']->assign('LSview_search',array( 'action' => $_SERVER['PHP_SELF'],