05-17-2019, 10:40 AM
(05-16-2019, 03:45 AM)Carlo Wrote:(05-15-2019, 01:45 PM)mudmin Wrote:(05-14-2019, 07:21 PM)Carlo Wrote: Hi Dan...Let me see if I can get these in order....
Maybe I did not explain properly what I meant...
As I said, I installed US without big problems, thanks to your install procedure.
The first thing that I had to consider was the fact that I installed it on an already existing project.
I already had an existing index.php on my main page.
So I had two choices: either copy the content of my index into yours or not use yours. I chose the latter.
I hope this was not the origin of my troubles.
When I navigate to pages that are not protected there are no problems, since the site is acting as it was before installing US.
But when I tried to navigate to a "protected" page, I got into the current problem.
Please do consider that I can manage MySQL sufficiently and I have some little experience with PHP but, nevertheless, I am unable to follow the intricacies of your code. (or any other code that appears complex to me, for what it counts).
This is what I want to achieve and I was hoping to do it with the three lines of code that you suggest putting on top of each protected page.
My assumptions are that when you navigate to a protected page, US checks if you are logged and, if not, prompts you to login.
It will then ascertain what kind of clearance you have and according to that will allow you to view that page or redirect you somewhere else, unless you are an Admin in which case you are presented with the dashboard. (talking of which, it seems that only English is available for such page).
Is there a way to change the last of the three lines required with something that says, in pseudo English, the following?
IF
you are an Adim, get to the Dashboard
ELSE
IF
logged and authorised to view the page, proceed.
ELSE
Redirect to a page of mu choice
Such redirection should be or might be different for each protected page.
In other words, I would like to be able to indicate for each protected page a destination page of my choice according to my desire.
Is this feasible?
And if yes, what kind of code should I put on top of each protected page?
Because this
[font=Consolas, monospace]require_once '../users/init.php'; //make sure this path is correct!
[/font]
require_once $abs_us_root.$us_url_root.'users/includes/template/prep.php';
[font=Consolas, monospace]if (!securePage($_SERVER['PHP_SELF'])){die();}[/font]
does not do that, unless the lack of the initial index.php were not the real problem.
Is my question now any clearer? Please consider that I am not native English so my choice of words may be somehow inappropriate to descrive the situation.
Back to the Dashboard.
To me is not a big problem: I can manage fine the English descriptions that are there with ease.
Bur I was wondering about that, for non English speakers or for anyone who is more familiar with his own language.
I sort of thought of a solution but, before venturing into the code, I would love to get your opinion.
I thought of changing the structure of the pages where language is involved with the following (an example):
//User Settings
$lang = array_merge($lang,array(
"SET_PIN" => _("Reset PIN"),
"SET_WHY" => _("Why can't I change this?"),
"SET_PW_MATCH" => _("Must match the New Password"),
At that point, adding a simple .po .mo files in the appropriate folder as required by PHP's gettext function, should do the trick.
Once the .po file is created, you may add all the other sentences that need translation in any US pages, by simply changing the sentence to be translated with something like (as an example)
BEFORE
<!-- Force Password Reset -->
<div class="form-group">
<label for="force_pr">Original sentence in English <a href="#!" tabindex="-1" title="Note" data-trigger="focus" class="nounderline" data-toggle="popover" data-content="When a user is created from the admin panel, force their password to be reset upon login, this will also send them a password reset link on manual creation no matter what password you enter on the form. If you enable this, the force_pr value in your users database for this user will be 1 when created. Default: No."><i class="fa fa-question-circle"></i></a></label>
AFTER
<!-- Force Password Reset -->
<div class="form-group">
<label for="force_pr"><? echo _("Original sentence in English") ?><a href="#!" tabindex="-1" title="Note" data-trigger="focus" class="nounderline" data-toggle="popover" data-content="When a user is created from the admin panel, force their password to be reset upon login, this will also send them a password reset link on manual creation no matter what password you enter on the form. If you enable this, the force_pr value in your users database for this user will be 1 when created. Default: No."><i class="fa fa-question-circle"></i></a></label>
Thus getting the translation in your chosen language for each and every instance in US, working on a single .po file (one for each language provided).
Naturally all this will require some extra general settings like a couple of lines of code for the environmental changes required, but that should be a walk in the park...
If you think that the above is feasible, I can dedicate my time to operate the required changes in the html sections and provide you with the resulting code for your view and tests. If it works as I expect, you can use it freely.
Let me know, if you please, the solution to my needs if it is not meaning for you too much effort and what do you think about the "language" solution.
Thank you in advance for your time and assistance.
Best,
Carlo
P.S. I attached some files for Italian as an example (which I doubt you will need). I had to add a false .php extension to upload the .mo and .po files. I hope this is not against the Forum rules.
You're fine not using our index.php but you probably want some of the things that are in it (like init.php, some of the stuff in prep.php) and possibly the footer.
My assumptions are that when you navigate to a protected page, US checks if you are logged and, if not, prompts you to login.
This is true if the following conditions are met.
1. The page has this line with the proper path require_once 'users/init.php';
2. The page has if (!securePage($_SERVER['PHP_SELF'])){die();}
3. The folder that the page is in is covered in the z_us_root.php file
4. The page shows up when you view it in the "pages" section of the dashboard.
IF
you are an Adim, get to the Dashboard
ELSE
IF
logged and authorised to view the page, proceed.
ELSE
Redirect to a page of mu choice
This logic would automatically redirect admins to the dashboard instead of letting them see the protected page. If that's what you want, the logic would be like this
Code://get rid of the securePage line
//add this...
if(isset($user) && $user->isLoggedIn()){
if(hasPerm([2],$user->data()->id)){//admin
Redirect::to($us_url_root.'users/admin.php');
}elseif(!hasPerm([1],$user->data()->id)){
Redirect::to($us_url_root.'users/whatver.php');
}
}else{
Redirect::to($us_url_root.'users/login.php');
}
What that does is...if the user is not logged in, redirect them to login. If they're admin, redirect to dashboard. If they do NOT have one of the permissions specified in that [1] (you can separate multiple perms by comma) Redirect them to whatever.php
I haven't tested this but you can try instead of Redirect::to($us_url_root.'users/login.php');
Code:$urlRootLength=strlen($us_url_root);
$page=substr($uri,$urlRootLength,strlen($uri)-$urlRootLength);
$dest=encodeURIComponent("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
Redirect::to($us_url_root.'users/login.php?dest='.$dest);
Admin language is expected to be a part of version 5.0. Front end language was just released a few months ago, so we're working on making sure everything is right before doing backend.
Gettext is not a viable solution for our application because it doesn't work universally across all servers. We have tested this. I don't LOVE our solution, but it does have the same fallback option as gettext and it works a lot better for what we're doing.
Sorry for the slow response. I've been on vacation and I'm answering messages as fast as I can.
We don't have Italian right now, I would love to offer it!
Hi Dan...
Here is your it-IT.php with the same structure of en-US.php
I checked it twice and I hope I haven't skipped any accented vowels.
Enjoy.
Dear Dan,
In order to avoid any mistake due to my previous small changes in code, I re-installed us from scratch, prior to test your suggestions.
While doing that, I checked the it-IT.php file and there were two lines amiss.
As we say here in Italy, the mother of the imbeciles is always pregnant...
My bad...
Please find attached the correct it.IT.php file with my apologies.
When you will need to translate into Italian other sections of us, please let me know and I'll make myself available with pleasure.
Best,
Carlo