From ed3d2cda5938cc9e357f035c9d17751cdfd40ef0 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 3 May 2020 19:44:37 +0200 Subject: [PATCH] Replace modify.php by a LSurl route --- .../includes/class/class.LSsearchEntry.php | 2 +- public_html/includes/routes.php | 109 +++++++++++++- public_html/modify.php | 140 ------------------ 3 files changed, 109 insertions(+), 142 deletions(-) delete mode 100644 public_html/modify.php diff --git a/public_html/includes/class/class.LSsearchEntry.php b/public_html/includes/class/class.LSsearchEntry.php index a0672cd2..04debb04 100644 --- a/public_html/includes/class/class.LSsearchEntry.php +++ b/public_html/includes/class/class.LSsearchEntry.php @@ -165,7 +165,7 @@ class LSsearchEntry { if (LSsession :: canEdit($this -> LSobject,$this -> dn)) { $this -> cache['actions'][]=array( 'label' => _('Modify'), - 'url' => 'modify.php?LSobject='.$this -> LSobject.'&dn='.urlencode($this -> dn), + 'url' => 'object/'.$this -> LSobject.'/'.urlencode($this -> dn).'/modify', 'action' => 'modify' ); } diff --git a/public_html/includes/routes.php b/public_html/includes/routes.php index 0bfa7a9a..8b7afd10 100644 --- a/public_html/includes/routes.php +++ b/public_html/includes/routes.php @@ -386,7 +386,7 @@ function handle_LSobject_show($request) { if ( LSsession :: canEdit($LSobject, $dn) ) { $LSview_actions[] = array( 'label' => _('Modify'), - 'url' =>'modify.php?LSobject='.$LSobject.'&dn='.urlencode($dn), + 'url' => "object/$LSobject/".urlencode($dn)."/modify", 'action' => 'modify' ); } @@ -462,6 +462,113 @@ function handle_old_view_php($request) { } LSurl :: add_handler('#^view.php#', 'handle_old_view_php'); +/* + * Handle LSobject modify request + * + * @param[in] $request LSurlRequest The request + * + * @retval void +**/ +function handle_LSobject_modify($request) { + $object = get_LSobject_from_request( + $request, + true, // instanciate object + array('LSsession', 'canEdit') // Check access method + ); + if (!$object) + return; + + $LSobject = $object -> getType(); + $form = $object -> getForm('modify'); + if ($form->validate()) { + // Update LDAP object data + if ($object -> updateData('modify')) { + // Update successful + if (LSerror::errorsDefined()) { + LSsession :: addInfo(_("The object has been partially modified.")); + } + else { + LSsession :: addInfo(_("The object has been modified successfully.")); + } + if (isset($_REQUEST['ajax'])) { + LSsession :: displayAjaxReturn ( + array( + 'LSredirect' => "object/$LSobject/".$object -> getDn() + ) + ); + return true; + } + else { + if (!LSdebugDefined()) { + LSurl :: redirect("object/$LSobject/".$object -> getDn()); + } + } + } + else { + if (isset($_REQUEST['ajax'])) { + LSsession :: displayAjaxReturn ( + array( + 'LSformErrors' => $form -> getErrors() + ) + ); + return true; + } + } + } + else if (isset($_REQUEST['ajax']) && $form -> definedError()) { + LSsession :: displayAjaxReturn ( + array( + 'LSformErrors' => $form -> getErrors() + ) + ); + return true; + } + + // List user available actions for this LSobject + $LSview_actions = array( + array( + 'label' => _('View'), + 'url' => "object/$LSobject/".urlencode($object -> getDn()), + 'action' => 'view' + ), + ); + + if (LSsession :: canRemove($LSobject,$object -> getDn())) { + $LSview_actions[] = array( + 'label' => _('Delete'), + 'url' => 'remove.php?LSobject='.$LSobject.'&dn='.urlencode($object -> getDn()), + 'action' => 'delete' + ); + } + LStemplate :: assign('LSview_actions',$LSview_actions); + + // Define page title + LStemplate :: assign('pagetitle',_('Modify').' : '.$object -> getDisplayName()); + $form -> display("object/$LSobject/".urlencode($object -> getDn())."/modify"); + + // Set & display template + LSsession :: setTemplate('modify.tpl'); + LSsession :: displayTemplate(); +} +LSurl :: add_handler('#^object/(?P[^/]+)/(?P[^/]+)/modify/?$#', 'handle_LSobject_modify'); + +/* + * Handle old modify.php request for retro-compatibility + * + * @param[in] $request LSurlRequest The request + * + * @retval void + **/ +function handle_old_modify_php($request) { + if (!isset($_GET['LSobject']) || !isset($_GET['dn'])) + $url = null; + else + $url = "object/".$_GET['LSobject']."/".$_GET['dn']."/modify"; + LSerror :: addErrorCode('LSsession_26', 'modify.php'); + LSurl :: redirect($url); +} +LSurl :: add_handler('#^modify.php#', 'handle_old_modify_php'); + /* ************************************************************ * LSaddon views diff --git a/public_html/modify.php b/public_html/modify.php deleted file mode 100644 index 1fda74e1..00000000 --- a/public_html/modify.php +++ /dev/null @@ -1,140 +0,0 @@ - getType(); - $dn = LSsession :: getLSuserObjectDn(); - } - else { - $LSobject = $_GET['LSobject']; - } - } - - if (isset($_POST['LSform_objectdn'])) { - $dn = $_POST['LSform_objectdn']; - } - else if (isset($_GET['dn'])) { - $dn = urldecode($_GET['dn']); - } - - if ((isset($dn)) && (isset($LSobject)) ) { - // Création d'un LSobject - if (LSsession :: loadLSobject($LSobject)) { - if ( LSsession :: canEdit($LSobject,$dn) ) { - $object = new $LSobject(); - if ($object -> loadData($dn)) { - // Définition du Titre de la page - LStemplate :: assign('pagetitle',_('Modify').' : '.$object -> getDisplayName()); - $form = $object -> getForm('modify'); - if ($form->validate()) { - // MàJ des données de l'objet LDAP - if ($object -> updateData('modify')) { - if (LSerror::errorsDefined()) { - LSsession :: addInfo(_("The object has been partially modified.")); - } - else { - LSsession :: addInfo(_("The object has been modified successfully.")); - } - if (isset($_REQUEST['ajax'])) { - LSsession :: displayAjaxReturn ( - array( - 'LSredirect' => "object/$LSobject/".$object -> getDn() - ) - ); - exit(); - } - else { - if (!LSdebugDefined()) { - LSurl :: redirect("object/$LSobject/".$object -> getDn()); - } - else { - LSsession :: displayTemplate(); - } - } - } - else { - if (isset($_REQUEST['ajax'])) { - LSsession :: displayAjaxReturn ( - array( - 'LSformErrors' => $form -> getErrors() - ) - ); - } - else { - LSsession :: displayTemplate(); - } - } - } - else if (isset($_REQUEST['ajax']) && $form -> definedError()) { - LSsession :: displayAjaxReturn ( - array( - 'LSformErrors' => $form -> getErrors() - ) - ); - } - else { - $LSview_actions[] = array( - 'label' => _('View'), - 'url' => "object/$LSobject/".urlencode($object -> getDn()), - 'action' => 'view' - ); - - if (LSsession :: canRemove($LSobject,$object -> getDn())) { - $LSview_actions[] = array( - 'label' => _('Delete'), - 'url' => 'remove.php?LSobject='.$LSobject.'&dn='.urlencode($object -> getDn()), - 'action' => 'delete' - ); - } - - LStemplate :: assign('LSview_actions',$LSview_actions); - LSsession :: setTemplate('modify.tpl'); - $form -> display(); - LSsession :: displayTemplate(); - } - } - else { - LSerror :: addErrorCode('LSsession_11'); - } - } - else { - LSerror :: addErrorCode('LSsession_11'); - } - } - } - else { - LSerror :: addErrorCode('LSsession_12'); - } - -} -else { - LSsession :: setTemplate('login.tpl'); - LSsession :: displayTemplate(); -}