mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-23 02:19:07 +01:00
Replace create.php by a LSurl route
This commit is contained in:
parent
06455db4f3
commit
c29c0dbe08
5 changed files with 136 additions and 150 deletions
|
@ -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'])) {
|
||||
$LSobject = $_GET['LSobject'];
|
||||
}
|
||||
|
||||
if (isset($LSobject)) {
|
||||
// LSObject creation
|
||||
if (LSsession ::loadLSobject($LSobject)) {
|
||||
if ( LSsession :: canCreate($LSobject) ) {
|
||||
$object = new $LSobject();
|
||||
|
||||
if (isset($_GET['load']) && $_GET['load']!='') {
|
||||
$form = $object -> getForm('create',urldecode($_GET['load']));
|
||||
}
|
||||
else {
|
||||
if (isset($_GET['LSrelation']) && isset($_GET['relatedLSobject']) && isset($_GET['relatedLSobjectDN'])) {
|
||||
if (LSsession :: loadLSobject($_GET['relatedLSobject']) && LSsession :: loadLSclass('LSrelation')) {
|
||||
$obj = new $_GET['relatedLSobject']();
|
||||
if ($obj -> loadData(urldecode($_GET['relatedLSobjectDN']))) {
|
||||
$relation = new LSrelation($obj, $_GET['LSrelation']);
|
||||
if ($relation -> exists()) {
|
||||
$attr = $relation -> getRelatedEditableAttribute();
|
||||
if (isset($object -> attrs[$attr])) {
|
||||
$value = $relation -> getRelatedKeyValue();
|
||||
if (is_array($value)) $value=$value[0];
|
||||
$object -> attrs[$attr] -> data = array($value);
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSrelations_06',array('relation' => $relation -> getName(),'LSobject' => $obj -> getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_24');
|
||||
}
|
||||
}
|
||||
}
|
||||
$form = $object -> getForm('create');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['LSform_dataEntryForm'])) {
|
||||
$form -> applyDataEntryForm((string)$_REQUEST['LSform_dataEntryForm']);
|
||||
LStemplate :: assign('LSform_dataEntryForm',(string)$_REQUEST['LSform_dataEntryForm']);
|
||||
}
|
||||
|
||||
LStemplate :: assign('listAvailableDataEntryForm',LSform :: listAvailableDataEntryForm($LSobject));
|
||||
LStemplate :: assign('DataEntryFormLabel',_('Data entry form'));
|
||||
|
||||
if ($form->validate()) {
|
||||
// Data update for LDAP object
|
||||
if ($object -> updateData('create')) {
|
||||
if (!LSerror::errorsDefined()) {
|
||||
LSsession :: addInfo(_("Object has been added."));
|
||||
}
|
||||
if (isset($_REQUEST['ajax'])) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSredirect' => "object/$LSobject/".urlencode($object -> getDn())
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
if (!LSdebugDefined()) {
|
||||
LSurl :: redirect("object/$LSobject/".urlencode($object -> getDn()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($_REQUEST['ajax'])) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSformErrors' => $form -> getErrors()
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
LSsession :: displayTemplate();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isset($_REQUEST['ajax']) && $form -> definedError()) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSformErrors' => $form -> getErrors()
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
// Define page title
|
||||
LStemplate :: assign('pagetitle',_('New').' : '.$object -> getLabel());
|
||||
LSsession :: setTemplate('create.tpl');
|
||||
$form -> display();
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_11');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSldapObject_01');
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_12');
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
LSsession :: setTemplate('login.tpl');
|
||||
}
|
||||
LSsession :: displayTemplate();
|
|
@ -75,13 +75,14 @@ class LSform {
|
|||
}
|
||||
|
||||
/**
|
||||
* Affiche le formualaire
|
||||
* Display the form
|
||||
*
|
||||
* @param[in] $LSform_action string|null The form action attribute value (optional, default: $_SERVER['PHP_SELF'])
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @retval void
|
||||
*/
|
||||
public function display(){
|
||||
public function display($LSform_action=null){
|
||||
if ($this -> idForm == 'view') {
|
||||
self :: loadDependenciesDisplayView($this -> $ldapObject);
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ class LSform {
|
|||
)
|
||||
);
|
||||
|
||||
LStemplate :: assign('LSform_action',$_SERVER['PHP_SELF']);
|
||||
LStemplate :: assign('LSform_action', ($LSform_action?$LSform_action:$_SERVER['PHP_SELF']));
|
||||
$LSform_header = "\t<input type='hidden' name='validate' value='LSform'/>\n
|
||||
\t<input type='hidden' name='idForm' id='LSform_idform' value='".$this -> idForm."'/>\n
|
||||
\t<input type='hidden' name='LSform_objecttype' id='LSform_objecttype' value='".$this -> ldapObject -> getType()."'/>\n
|
||||
|
|
|
@ -265,7 +265,7 @@ class LSrelation {
|
|||
if ($relation -> canCreate()) {
|
||||
$return['actions'][] = array(
|
||||
'label' => _('New'),
|
||||
'url' => 'create.php?LSobject='.$relationConf['LSobject'].'&LSrelation='.$relationName.'&relatedLSobject='.$object->getType().'&relatedLSobjectDN='.urlencode($object -> getValue('dn')),
|
||||
'url' => 'object/'.$relationConf['LSobject'].'/create?LSrelation='.$relationName.'&relatedLSobject='.$object->getType().'&relatedLSobjectDN='.urlencode($object -> getValue('dn')),
|
||||
'action' => 'create'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ class LSsearchEntry {
|
|||
if ($this -> LSsearch -> canCopy) {
|
||||
$this -> cache['actions'][] = array(
|
||||
'label' => _('Copy'),
|
||||
'url' =>'create.php?LSobject='.$this -> LSobject.'&load='.urlencode($this -> dn),
|
||||
'url' => 'object/'.$this -> LSobject.'/create?load='.urlencode($this -> dn),
|
||||
'action' => 'copy'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -79,14 +79,19 @@ LSurl :: add_handler('#^image/(?P<image>[^/]+)$#', 'handle_image', false);
|
|||
*
|
||||
* @param[in] $request LSurlRequest The request
|
||||
* @param[in] $instanciate boolean Instanciate and return an object (optional, default: true)
|
||||
* @param[in] $check_access callable|null Permit to specify check access method (optional, default: LSsession :: canAccess())
|
||||
*
|
||||
* @retval LSobject|boolean The instanciated LSobject (or True if $instanciate=false), or False
|
||||
* on error/access refused
|
||||
*/
|
||||
function get_LSobject_from_request($request, $instanciate=true) {
|
||||
function get_LSobject_from_request($request, $instanciate=true, $check_access=null) {
|
||||
$LSobject = $request -> LSobject;
|
||||
$dn = (isset($request -> dn)?$request -> dn:null);
|
||||
|
||||
// Handle $check_access parameter
|
||||
if (is_null($check_access))
|
||||
$check_access = array('LSsession', 'canAccess');
|
||||
|
||||
// Handle SELF redirect
|
||||
if ( $LSobject == 'SELF' ) {
|
||||
$LSobject = LSsession :: getLSuserObject() -> getType();
|
||||
|
@ -96,12 +101,12 @@ function get_LSobject_from_request($request, $instanciate=true) {
|
|||
|
||||
// If $dn, check user access to this LSobject
|
||||
if ($dn) {
|
||||
if (!LSsession :: canAccess($LSobject, $dn)) {
|
||||
if (!call_user_func($check_access, $LSobject, $dn)) {
|
||||
LSerror :: addErrorCode('LSsession_11');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!LSsession :: in_menu($LSobject) && !LSsession :: canAccess($LSobject)) {
|
||||
else if (!LSsession :: in_menu($LSobject) && !call_user_func($check_access, $LSobject)) {
|
||||
LSerror :: addErrorCode('LSsession_11');
|
||||
return false;
|
||||
}
|
||||
|
@ -158,7 +163,7 @@ function handle_LSobject_search($request) {
|
|||
if(LSsession :: canCreate($LSobject)) {
|
||||
$LSview_actions['create'] = array (
|
||||
'label' => _('New'),
|
||||
'url' => 'create.php?LSobject='.$LSobject,
|
||||
'url' => "object/$LSobject/create",
|
||||
'action' => 'create'
|
||||
);
|
||||
if ($object -> listValidIOformats()) {
|
||||
|
@ -241,6 +246,126 @@ function handle_LSobject_search($request) {
|
|||
}
|
||||
LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/?$#', 'handle_LSobject_search');
|
||||
|
||||
/*
|
||||
* Handle LSobject create request
|
||||
*
|
||||
* @param[in] $request LSurlRequest The request
|
||||
*
|
||||
* @retval void
|
||||
**/
|
||||
function handle_LSobject_create($request) {
|
||||
$object = get_LSobject_from_request(
|
||||
$request,
|
||||
true, // instanciate object
|
||||
array('LSsession', 'canCreate') // Check access method
|
||||
);
|
||||
if (!$object)
|
||||
return;
|
||||
|
||||
$LSobject = $object -> getType();
|
||||
|
||||
if (isset($_GET['load']) && $_GET['load']!='') {
|
||||
$form = $object -> getForm('create', urldecode($_GET['load']));
|
||||
}
|
||||
else {
|
||||
if (isset($_GET['LSrelation']) && isset($_GET['relatedLSobject']) && isset($_GET['relatedLSobjectDN'])) {
|
||||
if (LSsession :: loadLSobject($_GET['relatedLSobject']) && LSsession :: loadLSclass('LSrelation')) {
|
||||
$obj = new $_GET['relatedLSobject']();
|
||||
if ($obj -> loadData(urldecode($_GET['relatedLSobjectDN']))) {
|
||||
$relation = new LSrelation($obj, $_GET['LSrelation']);
|
||||
if ($relation -> exists()) {
|
||||
$attr = $relation -> getRelatedEditableAttribute();
|
||||
if (isset($object -> attrs[$attr])) {
|
||||
$value = $relation -> getRelatedKeyValue();
|
||||
if (is_array($value)) $value=$value[0];
|
||||
$object -> attrs[$attr] -> data = array($value);
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSrelations_06',array('relation' => $relation -> getName(),'LSobject' => $obj -> getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode('LSsession_24');
|
||||
}
|
||||
}
|
||||
}
|
||||
$form = $object -> getForm('create');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['LSform_dataEntryForm'])) {
|
||||
$form -> applyDataEntryForm((string)$_REQUEST['LSform_dataEntryForm']);
|
||||
LStemplate :: assign('LSform_dataEntryForm', (string)$_REQUEST['LSform_dataEntryForm']);
|
||||
}
|
||||
|
||||
LStemplate :: assign('listAvailableDataEntryForm', LSform :: listAvailableDataEntryForm($LSobject));
|
||||
LStemplate :: assign('DataEntryFormLabel', _('Data entry form'));
|
||||
|
||||
if ($form->validate()) {
|
||||
// Data update for LDAP object
|
||||
if ($object -> updateData('create')) {
|
||||
if (!LSerror::errorsDefined()) {
|
||||
LSsession :: addInfo(_("Object has been added."));
|
||||
}
|
||||
if (isset($_REQUEST['ajax'])) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSredirect' => "object/$LSobject/".urlencode($object -> getDn())
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
if (!LSdebugDefined())
|
||||
LSurl :: redirect("object/$LSobject/".urlencode($object -> getDn()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($_REQUEST['ajax'])) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSformErrors' => $form -> getErrors()
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isset($_REQUEST['ajax']) && $form -> definedError()) {
|
||||
LSsession :: displayAjaxReturn (
|
||||
array(
|
||||
'LSformErrors' => $form -> getErrors()
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
// Define page title
|
||||
LStemplate :: assign('pagetitle',_('New').' : '.$object -> getLabel());
|
||||
$form -> display("object/$LSobject/create");
|
||||
|
||||
// Set & display template
|
||||
LSsession :: setTemplate('create.tpl');
|
||||
LSsession :: displayTemplate();
|
||||
}
|
||||
LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/create/?$#', 'handle_LSobject_create');
|
||||
|
||||
/*
|
||||
* Handle old create.php request for retro-compatibility
|
||||
*
|
||||
* @param[in] $request LSurlRequest The request
|
||||
*
|
||||
* @retval void
|
||||
**/
|
||||
function handle_old_create_php($request) {
|
||||
if (!isset($_GET['LSobject']))
|
||||
$url = null;
|
||||
else
|
||||
$url = "object/".$_GET['LSobject']."/create";
|
||||
LSerror :: addErrorCode('LSsession_26', 'create.php');
|
||||
LSurl :: redirect($url);
|
||||
}
|
||||
LSurl :: add_handler('#^create.php#', 'handle_old_create_php');
|
||||
|
||||
/*
|
||||
* Handle LSobject show request
|
||||
*
|
||||
|
@ -269,7 +394,7 @@ function handle_LSobject_show($request) {
|
|||
if (LSsession :: canCreate($LSobject)) {
|
||||
$LSview_actions[] = array(
|
||||
'label' => _('Copy'),
|
||||
'url' =>'create.php?LSobject='.$LSobject.'&load='.urlencode($dn),
|
||||
'url' => "object/$LSobject/create?load=".urlencode($dn),
|
||||
'action' => 'copy'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue