'; # process the form input if ($form['submitted']) { # wrong input if (!isset($table[$form['date']][$form['time']][$form['computer']])) { $error_message = '

Invalid time slot. Please correct it and submit again.

'; $error_message .= $form['date'].' '.$form['time'].' '.$form['computer']; } # missing name elseif (!$form['name']) { $error_message = '

You did not enter your name. Please enter it and submit again.

'; } # used slot elseif ($table[$form['date']] [$form['time']] [$form['computer']]) { $error_message = '

That time slot is already taken. Please choose another one.

'; } # everything's okay, let's add this to the table else { add_to_table($form['date'], $form['time'], $form['computer'], $form['name']); # reload this page, to avoid re-submitting the form when clicking F5 header("Location: ."); exit; } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?> CS4706 - Sign-up page for the Linux computers in the Speech Lab

CS4706 - Sign-up page for the Linux computers in the Speech Lab

Instructions




 
Date Time .cs
Slot:   Your name:
0) { # append $MY_NUMBER to the lock file $fh = fopen(LOCKFILE, 'a'); fwrite($fh, $MY_NUMBER."\n"); fclose($fh); # now read the lock file $lines = file(LOCKFILE); $first_number = rtrim($lines[0]); # it's our turn, succeeded! if ($MY_NUMBER == $first_number) return; # otherwise, let's wait 0.5 seconds and retry. usleep(500000); print $first_number; # decrease the number of attempts $attempts--; } # write (not append) $MY_NUMBER to the lock file $fh = fopen(LOCKFILE, 'w'); fwrite($fh, $MY_NUMBER."\n"); fclose($fh); } # unlocks the table function unlock_table() { # empties the lock file. $fh = fopen(LOCKFILE, 'w'); fwrite($fh, ""); fclose($fh); } # initializes the table with '' in all cells function initialize_table(&$table) { global $DATES, $TIMES, $COMPUTERS; foreach ($DATES as $date) { foreach ($TIMES as $time) { foreach ($COMPUTERS as $computer) { $table[$date][$time][$computer] = ''; } } } } # says whether $date should be shown or not function show_this_date($date) { global $show_all; if ($show_all) return TRUE; # only show dates between now and N weeks in the future. if (strtotime("23:59 $date") < time()) return FALSE; if (strtotime("00:00 $date") > time()+60*60*24*7*N_WEEKS) return FALSE; return TRUE; } ?>