Replace modify.php by a LSurl route

This commit is contained in:
Benjamin Renard 2020-05-03 19:44:37 +02:00
parent c29c0dbe08
commit ed3d2cda59
3 changed files with 109 additions and 142 deletions

View file

@ -165,7 +165,7 @@ class LSsearchEntry {
if (LSsession :: canEdit($this -> LSobject,$this -> dn)) { if (LSsession :: canEdit($this -> LSobject,$this -> dn)) {
$this -> cache['actions'][]=array( $this -> cache['actions'][]=array(
'label' => _('Modify'), 'label' => _('Modify'),
'url' => 'modify.php?LSobject='.$this -> LSobject.'&dn='.urlencode($this -> dn), 'url' => 'object/'.$this -> LSobject.'/'.urlencode($this -> dn).'/modify',
'action' => 'modify' 'action' => 'modify'
); );
} }

View file

@ -386,7 +386,7 @@ function handle_LSobject_show($request) {
if ( LSsession :: canEdit($LSobject, $dn) ) { if ( LSsession :: canEdit($LSobject, $dn) ) {
$LSview_actions[] = array( $LSview_actions[] = array(
'label' => _('Modify'), 'label' => _('Modify'),
'url' =>'modify.php?LSobject='.$LSobject.'&dn='.urlencode($dn), 'url' => "object/$LSobject/".urlencode($dn)."/modify",
'action' => 'modify' 'action' => 'modify'
); );
} }
@ -462,6 +462,113 @@ function handle_old_view_php($request) {
} }
LSurl :: add_handler('#^view.php#', 'handle_old_view_php'); 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<LSobject>[^/]+)/(?P<dn>[^/]+)/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 * LSaddon views

View file

@ -1,140 +0,0 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
require_once 'core.php';
if(LSsession :: startLSsession()) {
if (isset($_POST['LSform_objecttype'])) {
$LSobject = $_POST['LSform_objecttype'];
}
else if (isset($_GET['LSobject'])) {
if ($_GET['LSobject'] == 'SELF') {
$LSobject = LSsession :: getLSuserObject() -> 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.'&amp;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();
}