Skip to content
Snippets Groups Projects
Commit bb83ad30 authored by Tim Repke's avatar Tim Repke
Browse files

clean up commons.php

parent 02b57d55
No related branches found
No related tags found
No related merge requests found
...@@ -25,72 +25,6 @@ function comm_from_mysqlDate($date){ ...@@ -25,72 +25,6 @@ function comm_from_mysqlDate($date){
return date('d.m.Y', strtotime($date)); return date('d.m.Y', strtotime($date));
} }
function comm_get_possible_dates($db, $fid){
$dates = $db->get("fahrten", ["von", "bis"], ["fahrt_id" => $fid]);
$end = new DateTime($dates['bis']);
$period = new DatePeriod(
new DateTime($dates['von']),
new DateInterval('P1D'),
$end->modify( '+1 day' )
);
$ret = [];
foreach($period as $d){
array_push($ret, $d->format("d.m.Y"));
}
return $ret;
}
/*
* returns TRUE iff registration is allowed
*/
function comm_isopen_fid($db_handle, $fid){
$ret = comm_isopen_fid_helper($db_handle, $fid);
return $ret == 0;
}
/*
* returns value depending on registration status
* 0 = registration open (slots available)
* 1 = all slots taken -> waitlist open
* 2 = registration closed!
*/
function comm_isopen_fid_helper($db_handle, $fid){
comm_verbose(3,"checking if fid ". $fid . " is open");
$open = $db_handle->has('fahrten', ['AND' => ['fahrt_id'=>$fid, 'regopen'=>1]]);
if(!$open)
return 2;
$cnt = $db_handle->count("bachelor", ["AND"=>
["backstepped" => NULL,
"fahrt_id" => $fid]]);
$max = $db_handle->get("fahrten", "max_bachelor", ["fahrt_id" => $fid]);
$wl = $db_handle->count('waitlist', ['AND' =>
["transferred" => NULL,
"fahrt_id" => $fid]]);
comm_verbose(3,"cnt: ".$cnt.", max: ".$max.", open: ".($open ? "yes" : "no"));
if ( $cnt < $max && $wl == 0 )
return 0;
return 1;
}
function comm_generate_key($db_handle, $check, $conditions){
again:
$bytes = openssl_random_pseudo_bytes(8);
$hex = bin2hex($bytes);
comm_verbose(3,"generated hex for test: ".$hex);
foreach($check as $table => $col){
if($db_handle->has($table, array("AND"=>[$col => $hex]))) goto again;
}
comm_verbose(2,"generated hex: ".$hex);
return $hex;
}
/* /*
* sends mail * sends mail
* *
...@@ -99,10 +33,8 @@ function comm_generate_key($db_handle, $check, $conditions){ ...@@ -99,10 +33,8 @@ function comm_generate_key($db_handle, $check, $conditions){
* *
* returns true/false depending on success * returns true/false depending on success
*/ */
function comm_send_mail($db_handle, $addr, $cont, $from = NULL, $bcc = NULL){ function comm_send_mail($addr, $cont, $from = NULL, $bcc = NULL){
global $config_current_fahrt_id, $config_mailtag; global $config_mailtag;
if(is_null($from))
$from = $db_handle->get("fahrten", "kontakt", array("fahrt_id"=>$config_current_fahrt_id));
$subj = "Wichtige Information"; $subj = "Wichtige Information";
$mess = $cont; $mess = $cont;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment