2008-02-12 18:59:44 +01:00
|
|
|
<?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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
require_once 'core.php';
|
2008-02-12 18:59:44 +01:00
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
if(LSsession :: startLSsession()) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
if (isset($_POST['LSform_objecttype'])) {
|
|
|
|
$LSobject = $_POST['LSform_objecttype'];
|
|
|
|
}
|
|
|
|
else if (isset($_GET['LSobject'])) {
|
|
|
|
$LSobject = $_GET['LSobject'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($LSobject)) {
|
2009-02-03 01:51:27 +01:00
|
|
|
// LSObject creation
|
2009-01-24 18:45:14 +01:00
|
|
|
if (LSsession ::loadLSobject($LSobject)) {
|
|
|
|
if ( LSsession :: canCreate($LSobject) ) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$object = new $LSobject();
|
|
|
|
|
2012-09-03 10:22:18 +02:00
|
|
|
if (isset($_GET['load']) && $_GET['load']!='') {
|
2012-05-03 14:39:01 +02:00
|
|
|
$form = $object -> getForm('create',urldecode($_GET['load']));
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-08-02 12:00:11 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
$form = $object -> getForm('create');
|
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
|
|
|
|
if (isset($_REQUEST['LSform_dataEntryForm'])) {
|
|
|
|
$form -> applyDataEntryForm((string)$_REQUEST['LSform_dataEntryForm']);
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_dataEntryForm',(string)$_REQUEST['LSform_dataEntryForm']);
|
2010-11-17 19:00:09 +01:00
|
|
|
}
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('listAvailableDataEntryForm',LSform :: listAvailableDataEntryForm($LSobject));
|
|
|
|
LStemplate :: assign('DataEntryFormLabel',_('Data entry form'));
|
2010-11-17 19:00:09 +01:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($form->validate()) {
|
2009-02-03 01:51:27 +01:00
|
|
|
// Data update for LDAP object
|
2008-10-14 15:27:46 +02:00
|
|
|
if ($object -> updateData('create')) {
|
2009-01-21 18:37:02 +01:00
|
|
|
if (!LSerror::errorsDefined()) {
|
2009-02-12 13:38:56 +01:00
|
|
|
LSsession :: addInfo(_("Object has been added."));
|
2008-10-14 15:27:46 +02:00
|
|
|
}
|
2008-11-10 00:24:46 +01:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: displayAjaxReturn (
|
2008-11-10 00:24:46 +01:00
|
|
|
array(
|
2012-05-03 12:39:08 +02:00
|
|
|
'LSredirect' => 'view.php?LSobject='.$LSobject.'&dn='.urlencode($object -> getDn())
|
2008-11-10 00:24:46 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
exit();
|
2008-10-14 15:27:46 +02:00
|
|
|
}
|
2008-11-10 00:24:46 +01:00
|
|
|
else {
|
2009-01-21 18:08:09 +01:00
|
|
|
if (!LSdebugDefined()) {
|
2012-05-03 12:39:08 +02:00
|
|
|
LSsession :: redirect('view.php?LSobject='.$LSobject.'&dn='.urlencode($object -> getDn()));
|
2008-11-10 00:24:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-02-12 11:04:50 +01:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
|
|
|
LSsession :: displayAjaxReturn (
|
|
|
|
array(
|
|
|
|
'LSformErrors' => $form -> getErrors()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSsession :: displayTemplate();
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-10 00:24:46 +01:00
|
|
|
else if (isset($_REQUEST['ajax']) && $form -> definedError()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: displayAjaxReturn (
|
2008-11-10 00:24:46 +01:00
|
|
|
array(
|
|
|
|
'LSformErrors' => $form -> getErrors()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
exit();
|
|
|
|
}
|
2009-02-03 01:51:27 +01:00
|
|
|
// Define page title
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('pagetitle',_('New').' : '.$object -> getLabel());
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setTemplate('create.tpl');
|
2008-02-12 18:59:44 +01:00
|
|
|
$form -> display();
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_01');
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSsession_12');
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: setTemplate('login.tpl');
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: displayTemplate();
|
2019-03-11 22:42:20 +01:00
|
|
|
|