Replace import.php by a LSurl route

This commit is contained in:
Benjamin Renard 2020-05-04 11:13:59 +02:00
parent 9bbd41468b
commit 43da89992a
6 changed files with 126 additions and 145 deletions

View file

@ -1,84 +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) ) {
if ( LSsession :: loadLSclass('LSimport')) {
$object = new $LSobject();
LStemplate :: assign('LSobject',$LSobject);
$ioFormats=$object->listValidIOformats();
if (is_array($ioFormats) && !empty($ioFormats)) {
LStemplate :: assign('ioFormats',$ioFormats);
if (LSimport::isSubmit()) {
$result=LSimport::importFromPostData();
LSdebug($result,1);
if(is_array($result)) {
LStemplate :: assign('result',$result);
}
}
}
else {
LStemplate :: assign('ioFormats',array());
LSerror :: addErrorCode('LSsession_16');
}
// Define page title
LStemplate :: assign('pagetitle',_('Import').' : '.$object->getLabel());
LSsession :: addCssFile('LSform.css');
LSsession :: addCssFile('LSimport.css');
LSsession :: setTemplate('import.tpl');
}
else {
LSerror :: addErrorCode('LSsession_05','LSimport');
}
}
else {
LSerror :: addErrorCode('LSsession_11');
}
}
else {
LSerror :: addErrorCode('LSldapObject_01');
}
}
else {
LSerror :: addErrorCode('LSsession_12');
}
}
else {
LSsession :: setTemplate('login.tpl');
}
LSsession :: displayTemplate();

View file

@ -169,7 +169,7 @@ function handle_LSobject_search($request) {
if ($object -> listValidIOformats()) {
$LSview_actions['import'] = array (
'label' => _('Import'),
'url' => 'import.php?LSobject='.$LSobject,
'url' => "object/$LSobject/import",
'action' => 'import'
);
}
@ -246,6 +246,68 @@ function handle_LSobject_search($request) {
}
LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/?$#', 'handle_LSobject_search');
/*
* Handle LSobject import request
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_LSobject_import($request) {
$object = get_LSobject_from_request($request, true);
if (!$object)
return;
$ioFormats = array();
$result = null;
if ( LSsession :: loadLSclass('LSimport')) {
$ioFormats = $object->listValidIOformats();
if (is_array($ioFormats) && !empty($ioFormats)) {
if (LSimport::isSubmit()) {
$result = LSimport::importFromPostData();
LSdebug($result, 1);
}
}
else {
$ioFormats = array();
LSerror :: addErrorCode('LSsession_16');
}
}
else {
LSerror :: addErrorCode('LSsession_05','LSimport');
}
// Define page title & template variables
LStemplate :: assign('pagetitle',_('Import').' : '.$object->getLabel());
LStemplate :: assign('LSobject', $object -> getType());
LStemplate :: assign('ioFormats', $ioFormats);
LStemplate :: assign('result', $result);
// Set & display template
LSsession :: setTemplate('import.tpl');
LSsession :: addCssFile('LSform.css');
LSsession :: addCssFile('LSimport.css');
LSsession :: displayTemplate();
}
LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/import/?$#', 'handle_LSobject_import');
/*
* Handle old import.php request for retro-compatibility
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_old_import_php($request) {
if (!isset($_GET['LSobject']))
$url = null;
else
$url = "object/".$_GET['LSobject']."/import";
LSerror :: addErrorCode('LSsession_26', 'import.php');
LSurl :: redirect($url);
}
LSurl :: add_handler('#^import.php#', 'handle_old_import_php');
/*
* Handle LSobject create request
*

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2020-05-04 10:44+0200\n"
"PO-Revision-Date: 2020-05-04 11:12+0200\n"
"Last-Translator: Benjamin Renard <brenard@zionetrix.net>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n"
@ -44,6 +44,7 @@ msgstr "Niveau"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/import.php:59
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:171
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:281
msgid "Import"
msgstr "Importer"
@ -65,7 +66,7 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsmoothbox.php:39
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsession.php:1359
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSform.php:68
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:607
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:669
#: /home/brenard/dev/ldapsaisie_clean3/public_html/custom_action.php:83
msgid "Validate"
msgstr "Valider"
@ -565,8 +566,8 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:68
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_supannLabeledValue.php:62
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:167
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:388
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:546
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:450
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:608
msgid "Modify"
msgstr "Modifier"
@ -1376,8 +1377,8 @@ msgstr "Attention"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:69
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:85
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:183
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:404
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:538
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:466
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:600
msgid "Delete"
msgstr "Supprimer"
@ -1388,7 +1389,7 @@ msgstr "Aucun objet."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSrelation.php:267
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:165
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:343
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:405
msgid "New"
msgstr "Nouveau"
@ -2003,7 +2004,7 @@ msgid "LSlog : Fail to load logging handler %{handler}."
msgstr "LSlog : Impossible de charger l'handler %{handler}."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSerror.php:102
#: templates/default/import.tpl:27
#: templates/default/import.tpl:28
msgid "Errors"
msgstr "Erreurs"
@ -2016,12 +2017,12 @@ msgid "Unknown error : %{error}"
msgstr "Erreur inconnu : %{error}"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:159
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:530
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:592
msgid "View"
msgstr "Voir"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:175
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:396
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:458
msgid "Copy"
msgstr "Copier"
@ -2051,35 +2052,35 @@ msgstr "Accueil"
msgid "Reset"
msgstr "Réinitialiser"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:302
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:364
msgid "Data entry form"
msgstr "Masque de saisie"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:308
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:370
msgid "Object has been added."
msgstr "L'objet a été ajouté."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:435
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:497
msgid "My account"
msgstr "Mon compte"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:488
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:550
msgid "The object has been partially modified."
msgstr "L'objet a été partiellement modifié."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:491
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:553
msgid "The object has been modified successfully."
msgstr "L'objet a bien été modifié."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:595
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:657
msgid "%{objectname} has been successfully deleted."
msgstr "%{objectname} a bien été supprimé."
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:604
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:666
msgid "Deleting : %{objectname}"
msgstr "Suppression : %{objectname}"
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:605
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:667
msgid "Do you really want to delete <strong>%{displayName}</strong> ?"
msgstr "Voulez-vous vraiment supprimer <strong>%{displayName}</strong> ?"
@ -2122,11 +2123,11 @@ msgstr "Attributs / Profils"
msgid "Details"
msgstr "Détails"
#: templates/default/import.tpl:8
#: templates/default/import.tpl:9
msgid "File"
msgstr "Fichier"
#: templates/default/import.tpl:11
#: templates/default/import.tpl:12
msgid "Format"
msgstr "Format"
@ -2135,7 +2136,7 @@ msgstr "Format"
msgid "Global search"
msgstr "Recherche globale"
#: templates/default/import.tpl:69
#: templates/default/import.tpl:70
msgid "Imported objects"
msgstr "Objets importés"
@ -2148,15 +2149,15 @@ msgstr "Légende :"
msgid "Nb / page :"
msgstr "Nb / page :"
#: templates/default/import.tpl:74
#: templates/default/import.tpl:75
msgid "No imported object"
msgstr "Aucun objet importé"
#: templates/default/import.tpl:42
#: templates/default/import.tpl:43
msgid "No value"
msgstr "Aucune valeur"
#: templates/default/import.tpl:17
#: templates/default/import.tpl:18
msgid "Only validate data"
msgstr "Validation des données uniquement"
@ -2190,7 +2191,7 @@ msgstr "Rafraîchir mes droits d'accès"
msgid "Relations / Profiles"
msgstr "Relations / Profils"
#: templates/default/import.tpl:25
#: templates/default/import.tpl:26
msgid "Result"
msgstr "Résultat"
@ -2206,23 +2207,23 @@ msgstr "Leurs relations avec les autres objets"
msgid "This object type has no configured relation."
msgstr "Ce type d'objet n'a aucune relation de configurée."
#: templates/default/import.tpl:14
#: templates/default/import.tpl:15
msgid "Update objects if exists"
msgstr "Mise à jour des objets existants"
#: templates/default/import.tpl:79
#: templates/default/import.tpl:80
msgid "Updated objects"
msgstr "Objets mis à jour"
#: templates/default/import.tpl:20
#: templates/default/import.tpl:21
msgid "Valid"
msgstr "Valider"
#: templates/default/import.tpl:15 templates/default/import.tpl:18
#: templates/default/import.tpl:16 templates/default/import.tpl:19
msgid "no"
msgstr "non"
#: templates/default/import.tpl:15 templates/default/import.tpl:18
#: templates/default/import.tpl:16 templates/default/import.tpl:19
msgid "yes"
msgstr "oui"

View file

@ -22,6 +22,7 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/import.php:59
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:171
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:281
msgid "Import"
msgstr ""
@ -39,7 +40,7 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsmoothbox.php:39
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsession.php:1359
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSform.php:68
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:607
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:669
#: /home/brenard/dev/ldapsaisie_clean3/public_html/custom_action.php:83
msgid "Validate"
msgstr ""
@ -474,8 +475,8 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:68
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_supannLabeledValue.php:62
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:167
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:388
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:546
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:450
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:608
msgid "Modify"
msgstr ""
@ -1153,8 +1154,8 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:69
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSformElement_select_object.php:85
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:183
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:404
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:538
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:466
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:600
msgid "Delete"
msgstr ""
@ -1165,7 +1166,7 @@ msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSrelation.php:267
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:165
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:343
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:405
msgid "New"
msgstr ""
@ -1699,7 +1700,7 @@ msgid "LSlog : Fail to load logging handler %{handler}."
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSerror.php:102
#: templates/default/import.tpl:27
#: templates/default/import.tpl:28
msgid "Errors"
msgstr ""
@ -1712,12 +1713,12 @@ msgid "Unknown error : %{error}"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:159
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:530
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:592
msgid "View"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/class/class.LSsearchEntry.php:175
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:396
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:458
msgid "Copy"
msgstr ""
@ -1743,35 +1744,35 @@ msgstr ""
msgid "Reset"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:302
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:364
msgid "Data entry form"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:308
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:370
msgid "Object has been added."
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:435
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:497
msgid "My account"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:488
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:550
msgid "The object has been partially modified."
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:491
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:553
msgid "The object has been modified successfully."
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:595
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:657
msgid "%{objectname} has been successfully deleted."
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:604
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:666
msgid "Deleting : %{objectname}"
msgstr ""
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:605
#: /home/brenard/dev/ldapsaisie_clean3/public_html/includes/routes.php:667
msgid "Do you really want to delete <strong>%{displayName}</strong> ?"
msgstr ""
@ -1810,11 +1811,11 @@ msgstr ""
msgid "Details"
msgstr ""
#: templates/default/import.tpl:8
#: templates/default/import.tpl:9
msgid "File"
msgstr ""
#: templates/default/import.tpl:11
#: templates/default/import.tpl:12
msgid "Format"
msgstr ""
@ -1823,7 +1824,7 @@ msgstr ""
msgid "Global search"
msgstr ""
#: templates/default/import.tpl:69
#: templates/default/import.tpl:70
msgid "Imported objects"
msgstr ""
@ -1836,15 +1837,15 @@ msgstr ""
msgid "Nb / page :"
msgstr ""
#: templates/default/import.tpl:74
#: templates/default/import.tpl:75
msgid "No imported object"
msgstr ""
#: templates/default/import.tpl:42
#: templates/default/import.tpl:43
msgid "No value"
msgstr ""
#: templates/default/import.tpl:17
#: templates/default/import.tpl:18
msgid "Only validate data"
msgstr ""
@ -1878,7 +1879,7 @@ msgstr ""
msgid "Relations / Profiles"
msgstr ""
#: templates/default/import.tpl:25
#: templates/default/import.tpl:26
msgid "Result"
msgstr ""
@ -1894,22 +1895,22 @@ msgstr ""
msgid "This object type has no configured relation."
msgstr ""
#: templates/default/import.tpl:14
#: templates/default/import.tpl:15
msgid "Update objects if exists"
msgstr ""
#: templates/default/import.tpl:79
#: templates/default/import.tpl:80
msgid "Updated objects"
msgstr ""
#: templates/default/import.tpl:20
#: templates/default/import.tpl:21
msgid "Valid"
msgstr ""
#: templates/default/import.tpl:15 templates/default/import.tpl:18
#: templates/default/import.tpl:16 templates/default/import.tpl:19
msgid "no"
msgstr ""
#: templates/default/import.tpl:15 templates/default/import.tpl:18
#: templates/default/import.tpl:16 templates/default/import.tpl:19
msgid "yes"
msgstr ""

View file

@ -2,7 +2,8 @@
{if $pagetitle != ''}<h1 id='LSview_title'>{$pagetitle|escape:"htmlall"}</h1>{/if}
<div class='LSform'>
<form action='import.php?LSobject={$LSobject|escape:"url"}' method='post' enctype="multipart/form-data">
<form action='object/{$LSobject|escape:"url"}/import' method='post' enctype="multipart/form-data">
<input type='hidden' name='LSobject' value='{$LSobject}'/>
<input type='hidden' name='validate' value='LSimport'/>
<dl class='LSform'>
<dt class='LSform'><label for='importfile'>{tr msg='File'}</label></dt>