rubberchicken
rubberchicken

Reputation: 1322

php - lock out days in a week for timesheet

im trying to lock out a whole week if someone submits their timesheet for that week so they cannot edit/add new times to that week thats already submitted.

i currently have a checksubmit function which returns 1 if someone submitted a timesheet for that week (checks $submitendweek which would be saturday of ending week ie: 2013-01-05)

im very new to programming and the language php/mysql so i apologize for lack of php knowledge.

this is what im temporarily using but is very disgusting and doesn't catch the days of previous month ... like the 30th or 31st.

$submitted = checksubmit($contextUser, $year, $month, $curDay);
$submitted1 = checksubmit($contextUser, $year, $month, $curDay+1);
$submitted2 = checksubmit($contextUser, $year, $month, $curDay+2);
$submitted3 = checksubmit($contextUser, $year, $month, $curDay+3);
$submitted4 = checksubmit($contextUser, $year, $month, $curDay+4);
$submitted5 = checksubmit($contextUser, $year, $month, $curDay+5);
$submitted6 = checksubmit($contextUser, $year, $month, $curDay+6);
if ($submitted || $submitted1 || $submitted2 || $submitted3 || $submitted4 || $submitted5 || $submitted6) {
print "submitted already";
...more
} else {
print "submit button";
...more 
}

Upvotes: 1

Views: 148

Answers (1)

Austin Brunkhorst
Austin Brunkhorst

Reputation: 21130

A for loop will help you out here.

$submitted = false;

for($i = 0; $i < 7; $i++) {
    if(checksubmit($contextUser, $year, $month, $curDay + $i)) {
        print 'submitted already';

        // one was sumbitted

        $submitted = true;
        break;
    }
}

if(!$sumbitted) {
    print 'submit button';

    // none were submitted this week
}

Upvotes: 1

Related Questions