diff --git a/registration-system/frameworks/commons.php b/registration-system/frameworks/commons.php index 88339cf27592ac797e7c8d498848d5b422d630bb..efac94f4cb981a7a5a3936ed98da2a6e1ed2c1bf 100644 --- a/registration-system/frameworks/commons.php +++ b/registration-system/frameworks/commons.php @@ -43,10 +43,15 @@ function comm_get_possible_dates($db, $fid){ function comm_isopen_fid($db_handle, $fid){ comm_verbose(3,"checking if fid ". $fid . " is open"); - return $db_handle->has("fahrten", array( - "AND" => array( - "fahrt_id"=>$fid, - "regopen"=>1))); + $cnt = $db_handle->count("bachelor", ["AND"=> + ["backstepped" => NULL, + "fahrt_id" => $fid]]); + $max = $db_handle->get("fahrten", "max_bachelor", ["fahrt_id" => $fid]); + $open = $db_handle->has('fahrten', ['AND' => ['fahrt_id'=>$fid, 'regopen'=>1]]); + + comm_verbose(3,"cnt: ".$cnt.", max: ".$max.", open: ".($open ? "yes" : "no")); + + return ( $open && $cnt < $max ); } function comm_generate_key($db_handle, $table, $col, $conditions){ diff --git a/registration-system/index.php b/registration-system/index.php index fb84849bde5d25449e3ef7308b63e749391708ad..56d846ae6e22505badf8351bbd160dab798f07c4 100644 --- a/registration-system/index.php +++ b/registration-system/index.php @@ -65,11 +65,7 @@ function index_show_content(){ } /*elseif(isset($_REQUEST['bid'])){ // Änderungsformular anzeigen, Anmeldung noch offen? index_show_formular($fid, $_REQUEST['bid']); } */ else { // leeres Formular anzeigen - $cnt = $index_db->count("bachelor", ["AND"=> - ["backstepped" => NULL, - "fahrt_id" => $fid]]); - $max = $index_db->get("fahrten", "max_bachelor", ["fahrt_id" => $fid]); - if ($index_db->has('fahrten', ['AND' => ['fahrt_id'=>$fid, 'regopen'=>1]]) && $cnt < $max) + if (comm_isopen_fid($index_db, $fid)) index_show_formular($fid); else { @@ -115,9 +111,7 @@ function index_form_to_db($data){ $index_db->exec("LOCK TABLES fahrten, bachelor WRITE"); // count should not be calculated in two scripts at once - $cnt = $index_db->count("bachelor", ["AND" => ["backstepped" => NULL, "fahrt_id" => $data['fahrt_id']]]); - - $insertOk = $cnt < $res['max_bachelor']; + $insertOk = comm_isopen_fid($index_db, $data['fahrt_id']); /*if ($cnt+1 >= $res['max_bachelor']) // registration is full already or after the following insert $index_db->update("fahrten", ["regopen" => 0], ["fahrt_id" => $config_current_fahrt_id]); */