moment_id);if (!$m) return false; $version=(int)$r->notice_version; // Serialize sends and re-read state so duplicate HTTP/admin requests cannot double-send. $lock='hgr-mail-'.md5(hgr_table('registrations').':'.$id); if ((int)$wpdb->get_var($wpdb->prepare('SELECT GET_LOCK(%s, 0)',$lock))!==1) return false; try { $r=hgr_registration($id);$version=(int)$r->notice_version; if ($r->notice_state==='sent') return true; $activity=get_the_title($m->activity_id);$status=hgr_statuses()[$r->status]; $people=implode("\n",array_map(fn($name)=>'- '.$name,json_decode($r->participants,true)?:[])); $details="Activiteit: $activity\nDatum: ".hgr_local_time($m->starts_at)."\nLocatie: $m->location\nContactpersoon: $r->contact_name\nE-mail: $r->contact_email\nTelefoon: $r->phone\nOrganisatie: $r->organization\nAantal deelnemers: $r->seats\nStatus: $status\n\nDeelnemers:\n$people\n"; $link=admin_url('admin.php?page=hg-registrations&tab=registrations®istration_id='.$id); $customer_sent=(int)$r->customer_notice_version===$version; if (!$customer_sent) { $customer_sent=wp_mail(hgr_settings()['recipient'],"[$activity] Inschrijving #$id — $status",$details."\nBehandelen in WordPress: $link\n"); if ($customer_sent) $wpdb->update(hgr_table('registrations'),['customer_notice_version'=>$version],['id'=>$id,'notice_version'=>$version]); } $intro=match($r->status){'reserved'=>'Je aanvraag is ontvangen. De plaatsen zijn gereserveerd; de organisatie bevestigt je deelname afzonderlijk.','confirmed'=>'Je deelname is bevestigd.','declined'=>'Je aanvraag is afgewezen. De gereserveerde plaatsen zijn vrijgegeven.','cancelled'=>'Je inschrijving is geannuleerd. De plaatsen zijn vrijgegeven.'}; $participant_sent=(int)$r->participant_notice_version===$version; if (!$participant_sent) { $participant_sent=wp_mail($r->contact_email,"[$activity] $status — inschrijving #$id",$intro."\n\n".$details); if ($participant_sent) $wpdb->update(hgr_table('registrations'),['participant_notice_version'=>$version],['id'=>$id,'notice_version'=>$version]); } $sent=$customer_sent && $participant_sent; $wpdb->update(hgr_table('registrations'),['notice_state'=>$sent?'sent':'failed'],['id'=>$id,'notice_version'=>$version]); return $sent; } finally { $wpdb->get_var($wpdb->prepare('SELECT RELEASE_LOCK(%s)',$lock)); } }