Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set/get default date and keep info for all pages in sessionset/get de… #29312

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

rycks
Copy link
Contributor

@rycks rycks commented Apr 10, 2024

All the time when you work on advanced accountancy module you have to set date start / end when you change page !

That is a really big pain when at the end of the day you realize that you loose more than one hour to change only date from page to pages all the time ...

The main idea of that PR is to put that sort of settings in temporary session

More details on french forum: https://www.dolibarr.fr/forum/t/module-comptabilite-avancee-dates-ergonomie/46153

…fault date and keep info for all pages in sessionfix comment
@eldy
Copy link
Member

eldy commented Apr 11, 2024

How does the value is reset ? It seems once value is saved in session, you will always get this value, but how to reset filter or delete var from session ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

hello @eldy , please have a look at function SESSIONGETPOSTINT ...

//getpost is always priority if set : that's the last user choice
$getpost=GETPOSTINT($key);

so if user choose a date that one is saved into session and used until he set an other value ... maybe the "unset" is the only "fail" is that what you mean ? but date is always set so it seems to be a nonsense problem no ?

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks i don't understand ! a GETPOST is just for the moment ! why you add the session ?

@eldy
Copy link
Member

eldy commented Apr 11, 2024

so if user choose a date that one is saved into session and used until he set an other value ... maybe the "unset" is the only "fail" is that what you mean ? but date is always set so it seems to be a nonsense problem no ?

I don't understand what you mean when you say "date is always set".
When I open the list of proposal, there is no filter by defaut. If i set a filter, my question is what happen if i empty the field date ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks the problem with your function, the $_SESSION is just for the current user and others ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

@eldy i made a little modification to handle "reset" values with reset button but if user make field empty we can't detect it ...

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

@hregis yes of course i choose some dates and that choice is only for me during the session ... just imagine people who works on accounting part of dolibarr and make review account by account, month per month ... please do it like if your are a accounter, the result is "fuck !!! i loose my time with dolibarr i have to re-enter 03/01/2023 31/03/2023 on each page, go out with your opensource software" ...

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks je te le fait à la française, on ne peut pas vérifier une valeur sur une "session" ! ne peut-on pas régler ce souci autrement ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

@hregis mais pourquoi on ne peut pas ? le develop que j'ai sous les yeux se comporte parfaitement bien avec cette PR SAUF pour le cas levé par eldy de "je vide la date" ... elle "reviendra" depuis la valeur session, sauf depuis mon dernier commit si on clique sur le bouton "x" en bout de ligne qui fait un reset de tous les champs de recherche ...

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks @eldy définir des dates par rapport à une session me parait absurde ! peut-être que je ne comprend pas ton soucis... mais ça me parait très personnel à ce que tu veux... et peut-être pas "universel"... est-ce qu'il n'y aurait pas un autre moyen de régler le soucis ? ou alors si je ne comprends pas j'en suis désolé !

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks cette fonction "SESSIONGETPOSTINT" me fait peur ;-)

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks @eldy déjà qu'entre GETPOSTINT() et GETPOST('xx', 'int) ont a des différences de résultats, alors imagine avec SESSIONGETPOSTINT() !! ;-)

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

(sorry for non french people, it's to hard for me to explain that in english)

Le fond de la question est est-ce que t'as déjà passé tes journées à faire de la compta dans dolibarr ?

en bref, imagine que tu dois chercher un erreur qui se cache entre le 12 mars et le 18 mars sur un volume de 80 / 90 lignes d'écritures ... tu dois balayer les factures, les banques, le grand livre, les journaux etc. et à chaque fois il faut re-rentrer les dates où on ne peut même pas faire de copier/coller ...

les comptables passent leur vie à faire des revues de comptes et leurs outils sont vraiment infiniment plus ergonomiques, si on veut arrêter de passer pour des guignols il faudrait vraiment qu'on s'atelle à avoir un "utilisabilité de l'interface" pour ce genre de situations

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks ok je compatis, pauvres comptables... mais ça ne répond pas à ma question... en quoi SESSIONGETPOSTINT() va les aider ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

hé bien a partir du moment où on entre une date exemple 12/03/2023 et date de fin 17/03/2023 et qu'on applique cette recherche ensuite lorsqu'on passe sur la liste des factures cette période est automatiquement appliquée, on passe sur un journal de banque et ho magie c'est la même période qui s'applique automatiquement car sauvegardée dans la session en cours

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks ce sui me dérange c'est la session ! la session c'est éphémère sur l'utilisateur ! ce n'est pas commun !

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

mais c'est JUSTEMENT pour ça que c'est une session, une fois le pb trouvé je peux passer au problème suivant, tiens un probleme entre le 2 et le 20 avril ... et ainsi de suite jusqu'à ce que ta compta tombe juste et tu puisse faire un export FEC propre ...

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

mais tu peux retrouver cette approche dans de la gestion normale, on a un problème sur les expéditions entre le 2 et le 4 juin, tu veux faire des recherches de n'importe quelles pièces dans dolibarr entre le 2 et le 4 juin pourquoi devoir re-saisir cette période sur chaque page qui liste des documents ?

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks tu me parles de "dates" fixes en quoi la session rentre en jeu ? excuse moi, peut être que je n'arrive pas à percuter mais pour moi une session correspond plus à une personne à une date voir même plus précisément à un horaire... pas à une date fixe !

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks peut-être que de vouloir utiliser SESSIONGETPOSTINT() tu peux utiliser la table "llx_user_param" pour stocker ce que tu veux utiliser ?

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

heu régis ... en php $_SESSION permet de stocker une valeur dans la session en cours (voir cookies toussa toussa) ... donc lorsque je rentre 12/03/2023 dans la date de début de recherche de mes factures je sauvegarde cette information dans la session utilisateur pour que lorsqu'il change de page cette date soit automatiquement pré-remplie a la valeur ... je te fais un dessin

liste des factures du 1er au 5 janvier

image

je change de page, dolibarr de base a le champ date de vide je dois donc entrer à la main 01/01/2023 et 05/01/2023

image

alors que si la valeur est stockée dans la session magie c'est pré-rempli

image

maintenant tu vois mieux ? si on considère dolibarr en situation opérationnele avec des volumes de plusieurs centaines de pièces par jours c'est absolument indispensable ...

et au départ j'ai identifié le pb sur ma compta en cherchant pourquoi certains trucs ne tombent pas juste, je passe du grand libvre au journal des od puis journal de banque et à chaque fois il faut re-saisir les dates ... c'est absurde

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks "llx_user_param" pourrait permettre de stocker ça, car si pour n'importe quelles raisons ce que tu es en train de faire se coupe, tu garderas une trace ! car la session, quoi qu'il en soit sera perdue et tu perdras ce que tu as voulus garder en mémoire !

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks la session est éphémère !

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

mais ... non ... c'est une information ephémère, la session est vraiment faite pour ça, c'est l'archétype de l'utilisation d'une session php ...
une date de début / date de fin ça n'a aucun intérêt autre que l'instant présent, si pour une raison inconnue on "perds" la data on s'en fout il n'y a aucun enjeu ...

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks c'est toi qui me rend fou ! maintenant je le sais ! ;-)

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks un combat de coqs ! vivant dans le pays du poulet de Bresse ça me connait ! ;-)

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks si @eldy accepte SESSIONGETPOSTINT() alors il va falloir faire SESSIONGETPOSTSTRING() SESSIONGETPOSTARRAY() SESSIONGETPOSTOTHER() SESSIONGETPOSTSINGE()....

@rycks
Copy link
Contributor Author

rycks commented Apr 11, 2024

lorsque j'ai fait la PR j'ai été surpris de voir l'arrivée de GETPOSTINT alors que j'avais tout implémenté sur ma 18 avec le GETPOST(xxx, 'int') ... alors je me suis adapté

@eldy
Copy link
Member

eldy commented Apr 11, 2024

@hregis yes of course i choose some dates and that choice is only for me during the session ... just imagine people who works on accounting part of dolibarr and make review account by account, month per month ... please do it like if your are a accounter, the result is "fuck !!! i loose my time with dolibarr i have to re-enter 03/01/2023 31/03/2023 on each page, go out with your opensource software" ...

I see. Idea is good.
This is troubles i found. Once you have set a filter, no way to reset it, except by resetting all other fields. Another solution is to logout and login to retreive a stable state. A headache when you want to reset a field: Common method by emptying the field will no more work. Well it will works with some fields and no more for others (like the date).
The implementation seems also to generate conflicts with the feature "default value". I got also troubles with the feature "Go back to list" that restore filter we have before leaving a list (all of this is already using a similar method by setting data in session)

So we must find a better solution. I think we should introduce something more clear for end user, that we can call "The Permanent filter" for example.
No doubt that for such a feature we must use the SESSION. This is the only solution to keep track of the data between invoice, intervention or any list that use a date.
However, including this as a silently no visible feature inside the GETPOST generates also troubles (method to reset filter will vary depending if the field is date or not, broken default filters, broken persistent filter when using the Back to list, but also when searching a data into another browser tab for another range, forces to clean the setup on the second tab, making the original filter lost on the main page we were working on, making the solution worse when working with several tabs, more trouble may appears, this one are just what i discovered in few tests). So we must enhance this.
This is an idea to provide the feature we need:
In the top bar, we may have a button "Permanent filter" to open a popup like for "bookmarks". We can set start and end date filter in this popup to have thel saved into session. The same popup will allow to reset permanent filters. But this will need more work (and time)
So for a fast availability, this is what we can do:

  • Validate this PR that introduce the SESSIONGETPOST. I will rename it GETPOSTSESSION (because priority is in name GET, then POST then SESSION).
  • Second step is to enhance the SESSIONGETPOST(). Because this may take time to have a perfect implementation, we can have, quickly, a hidden option that allow to switch between the suggested implementation or in the future a variant that will be able to use the permanent filter selection...

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

@rycks tu as gagné ! ;-) @eldy à dû respirer un gaz euphorisant qui a dû te donner raison dans un sens ! ;-)
je n'ai rien compris à ce qu'il a dit mais... demain est un autre jour ! ;-)

@hregis
Copy link
Contributor

hregis commented Apr 11, 2024

je sais que je ne suis pas quelqu'un qu'on voudrait que je sois ou que je devrais être... peut importe... si vous avez des choses à me reprocher alors je saurais écouter ce que vous avez à me reprocher... si vous m'aimez alors je saurais apprécier votre amour... mais si vous n'avez rien à dire alors je n'aurais rien à vous répondre... tout ça tombe dans l'absurde car nous vivons dans un monde absurde ! où on se fait poignarder pour un rien, où on se fait tuer pour un rien... tu veux vivre ? alors... ! Absurde !

@rycks
Copy link
Contributor Author

rycks commented Apr 13, 2024

@eldy may i share that solution i've used into an other project in the past :

  1. catch "onchange" event or "onblur" (better) on <input ... onblur=""> (date) tags
  2. use a jquery/other ajax on that event like jQuery('#setsessionvalue').load('ajax/update_session_value.php?key=value');
  3. server side a ajax/update_session_value.php make the "set" job even if user make an "empty value" because we can compare "current value in session" and "new value set by user"

then with that solution no need to have a "permanent search values popup & code" like you imagine in your prev message and that was easy for users to understand : nothing to explain, i set a date the date keep its value, i change it, i reset it that's all

@eldy
Copy link
Member

eldy commented Apr 13, 2024

More complex to implement but looks better, more user friendly.

And what do you think about storing the filter in cookies (with a lifetime that is session) instead of session ?

@rycks
Copy link
Contributor Author

rycks commented Apr 13, 2024

@eldy ok here is a solution for that with an ajax call ... i'm open to change php ajax file name, and other things :)

@rycks
Copy link
Contributor Author

rycks commented Apr 13, 2024

could you please help me to find what's PHAN "error" ?

@rycks
Copy link
Contributor Author

rycks commented Apr 19, 2024

@eldy like @lvessiller-opendsi may i make a self-candidature to become a little jedi ?

@eldy
Copy link
Member

eldy commented Apr 19, 2024

@eldy like @lvessiller-opendsi may i make a self-candidature to become a little jedi ?

Sure, let's talk about this during the devcamp...

@rycks
Copy link
Contributor Author

rycks commented Apr 29, 2024

@eldy what do i have to do for that PR ?


// Load Dolibarr environment
require '../../main.inc.php';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must add here
top_httphead('application/json');

otherwise, the http mime typewill be set to text/html instead of application/json

if(old.value != e.value) {
//then call ajax to update session value
//and set new value on old for next time
jQuery.ajax({url: '<?php print DOL_URL_ROOT.'/core/ajax/update_session_value.php?';?>' + e.id + '=' + e.value});
Copy link
Member

@eldy eldy May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you made a modification of data (even if it is inside the session), you must add a parameter action=updatesession for example and also a token=... as parameter here.
You should be able to get the CSRF token in javacript with

let token = document.getElementsByTagName('anti-csrf-currenttoken');

Adding an action=... is required for each url call that modify data (in database, on disk or session). It is used to trigger CSRF check. Adding the token is required to have CSRF check valid.
In v20, increasing the security level of MAIN_SECURITY_CSRF_WITH_TOKEN to value 3 will become recommended and without this, call will fails.

*/

/**
* \file htdocs/core/ajax/price.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

htdocs/core/ajax/update_session_value.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants