From 43da89992a2e2176443119172428bd2f7cb05f11 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 4 May 2020 11:13:59 +0200 Subject: [PATCH] Replace import.php by a LSurl route --- public_html/import.php | 84 ------------------ public_html/includes/routes.php | 64 ++++++++++++- .../lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo | Bin 55128 -> 55128 bytes .../lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po | 61 ++++++------- public_html/lang/ldapsaisie.pot | 59 ++++++------ public_html/templates/default/import.tpl | 3 +- 6 files changed, 126 insertions(+), 145 deletions(-) delete mode 100644 public_html/import.php diff --git a/public_html/import.php b/public_html/import.php deleted file mode 100644 index e92fd4a8..00000000 --- a/public_html/import.php +++ /dev/null @@ -1,84 +0,0 @@ -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(); diff --git a/public_html/includes/routes.php b/public_html/includes/routes.php index 67e6d27e..e9f4f33d 100644 --- a/public_html/includes/routes.php +++ b/public_html/includes/routes.php @@ -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[^/]+)/?$#', '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[^/]+)/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 * diff --git a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index 581b6e6e3af4f1bd13bb866e313b58089a9c2cee..56f0f7a320b0224becc695002a97839f036807e1 100644 GIT binary patch delta 19 bcmcbyj`_wq<_&EnEQVHwMw`1z&Lsf=SI-D= delta 19 bcmcbyj`_wq<_&EnECyC4CY!rT&Lsf=SLX\n" "Language-Team: LdapSaisie \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 %{displayName} ?" msgstr "Voulez-vous vraiment supprimer %{displayName} ?" @@ -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" diff --git a/public_html/lang/ldapsaisie.pot b/public_html/lang/ldapsaisie.pot index eec4fb6d..0b1bd681 100644 --- a/public_html/lang/ldapsaisie.pot +++ b/public_html/lang/ldapsaisie.pot @@ -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 %{displayName} ?" 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 "" diff --git a/public_html/templates/default/import.tpl b/public_html/templates/default/import.tpl index 0298cf34..be0d47d6 100644 --- a/public_html/templates/default/import.tpl +++ b/public_html/templates/default/import.tpl @@ -2,7 +2,8 @@ {if $pagetitle != ''}

{$pagetitle|escape:"htmlall"}

{/if}
-
+ +