CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Disable fields according to current date and more. [Solved]

Print topic Send  topic

Author Message
oceandeep

Posts: 17
Posted: 12/26/2014, 8:38 AM

Hello,

I'm working on an app that controls the attendance of some employees for 2 weeks (from mon to sun) and I hope you guys can help me get an important feature right. I have a page with a master/detail form with the following structure:
1- Record: Table: gral_att, Fields: Department, begining_date, end_date, curr_date.
2-Ed. Grid Table: desc_att, Fields: emp_cod, emp_name, w1_m ("week1_monday", and 6 others with similar names for every day of week 1), w2_m ("week2_monday", and 6 others with similar names for every day of week 2), Total_hours.

The grid looks something like this:

# | cod | name | M | T | W | T | F | S | S | M | T | W | T | F | S | S | Total

As I said, this works for periods of 2 weeks, determined by begining_date and end_date. In the 14 fields for days, the users will write the amount of hours an employee worked in that day. This should be done after everyday and the user shouldn't be allowed to write anything in the days that have not passed yet, for this I would like the app automatically disables the correct fields of days by taking current day and checking if it belongs to the date range given and assign it a number/id or something that points it like the 1st, 2nd, 3rd,......, day of the 14 days. So if its the 5th day, from the 6th to 14th are disabled. To try to explain a bit more what I need:

1. Identify current day and evaluate if it belongs to a given date range.

2. If it belongs to it, give it a number from 1 to 14 to associate with the 14 fields in the grid. Then, I could use that to disable or enable the correct fields. Ex:
begining date: 01-01-2015, end date: 01-14-2015, current date: 01-02-2015. If I could give a number to curr date, it would be 2; then 12 fields would be disabled except the first two.

3. Disable/enable the 14 fields accordingly.

Ok, this is weird I know, but I hope you can give me a hand here since I've run out of ideas.

Thanks for reading and have a nice day.
View profile  Send private message
eratech


Posts: 513
Posted: 12/27/2014, 11:06 PM

oceandeep,

If you have a good idea that the 2-week period won't fall either side of 1-Jan, you could use PHP's date() function and return the day of the year:

$dayofyear_today = date('z') + 1;

and work out the difference between the day of the year for start_date and end_date, but you need to convert the dates into time objects (this counts days since 1970 so won't be a problem over 1-Jan like above would)

  
$dbstartdate = <reference to your DB or field>  
$dbenddate = <reference to your DB or field>  
$start = strtotime($dbstartdate);  
$end = strtotime($dbenddate);  
  
$days_between = ceil(abs($end - $start) / 86400);

Getting the parts of the start and end dates are seen in the Tip from MichaelMacdonald:
http://forums.yessoftware.com/posts.php?post_id=123940

However, that is a lot of Custom Code PHP, and I don't like Custom Code as it makes me think too much. :-)

So, you might consider doing some of the work by the SQL Database to determine the 'column' of 'today' and set the inputbox readonly. This has the advantage of working regardless of years as it counts the Days since Year 0.

In the BeforeShow of the Editable Grid, do a DLookup to find which column 'today' is from the beginning_date:

select:  " (TO_DAYS(CURDATE()) - TO_DAYS(beginning_date))"  
domain: "gral_att"  
criteria: "id = ".CCToSQL(CCGetFromGet(id,0))  
convert to: Integer  
store: Variable  
name: todaycolumn  

Then in the BeforeShow Event (Serverside) of each Textbox, compare the textbox 'column' to the variable $todaycolumn and turn it 'readonly' with an Component Attribute on the Textbox

  
globals $todaycolumn;  
$thiscol = 1; // then 2, 3, 4 etc  
if ($thiscol <= $todaycolumn) {  
       $Component->Attributes->SetValue('readonly', '');  
} else {  
       $Component->Attributes->SetValue('readonly', 'readonly');  
}  

(If unsure of how to use, them, search the Help Manual for the bolded headings)

Cheers

Eric
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message
oceandeep

Posts: 17
Posted: 01/02/2015, 10:02 AM

Hello Eric,

I didn't respond you before because of work but I want to thank you for your help, both of your suggestions work! At the end I used the second one, with the Component Attributes. It was easier :-D.

Thanks a lot!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.