erdcck
Posts: 17
|
Posted: 08/04/2014, 5:06 AM |
|
Dear friends
How to restrict user logon 09:00 and 18:30.
my code but not working
$db = new clsDBmyprintDB();
global $CCSLocales;
$current_time = date('H:i:s');
$worktime_error = ($CCSLocales->GetText("worktime_error"));
$worktimebegin = CCDLookUp("work_begin_time", "companies", "company_id=".CCGetSession("company_id") ,$db);
$worktimeend = CCDLookUp("work_end_time", "companies", "company_id=".CCGetSession("company_id") ,$db);
if ($current_time > $worktimebegin && $worktimeend < $current_time ) {
$Component->SetValue("$worktime_error");
}
{
|
|
|
saseow
Posts: 744
|
Posted: 08/05/2014, 12:19 AM |
|
With dates I always work with timestamps. e.g.:
$cur_date= time();
Then use the strtotime PHP function to change the values you have stored in the database to change those to timestamps. You can then simply check for larger or smaller as you are doing.
So, to get the timestamp for 9am use something like:
$starttime = strtotime("2005-10-16 09:00:00");
Then get the end time and current time as per above.
Have a look at http://php.net/datetime which has all the info you need.
|
|
|
erdcck
Posts: 17
|
Posted: 08/05/2014, 7:02 AM |
|
Dear saseow thank you so much everything is fine but adderror not showing :)
working code :
$db = new clsDBmyprintDB();
global $CCSLocales;
global $Redirect;
$current_time = strtotime(date('H:i:s'));
$worktimebegin = strtotime(CCDLookUp("work_begin_time", "companies", "company_id=".CCGetSession("company_id") ,$db));
$worktimeend = strtotime(CCDLookUp("work_end_time", "companies", "company_id=".CCGetSession("company_id") ,$db));
if ((($current_time > $worktimebegin) && ($current_time < $worktimeend)) or CCGetSession("GroupID") > 3) {
}
else {
$Redirect = "index.php?Logout=yes";
$Login->Errors->addError($CCSLocales->GetText("worktime_error"));
}
$db->close();
|
|
|
saseow
Posts: 744
|
Posted: 08/05/2014, 9:42 PM |
|
I am presuming that your login page is called index.php. Because you are redirecting to it you will not be able to add errors.
The simplest way to do this would be to redirect to a page that has a message stating why they cannot login at the current time and to clear the login session vars before showing the page.
|
|
|
erdcck
Posts: 17
|
Posted: 08/06/2014, 2:21 AM |
|
Quote saseow:
I am presuming that your login page is called index.php. Because you are redirecting to it you will not be able to add errors.
The simplest way to do this would be to redirect to a page that has a message stating why they cannot login at the current time and to clear the login session vars before showing the page.
Dear saseow, you are right, thank you again.
|
|
|
|