Add dinner count

Change-Id: If5b5074a012ad75fe34547a6d12d40986adb5a89
diff --git a/db_backend.php b/db_backend.php
index d028241..9e4bec5 100644
--- a/db_backend.php
+++ b/db_backend.php
@@ -92,6 +92,19 @@
         }
     }
 
+    function dinner_count()
+    {
+        $sql = "SELECT COUNT(*) FROM person WHERE conference_dinner";
+        try {
+            $stmt = $this->pdo->prepare($sql);
+            $stmt->execute();
+            $row = $stmt->fetch(PDO::FETCH_ASSOC);
+            return $row['COUNT(*)'];
+        } catch (PDOException $pe) {
+            trigger_error('Could not connect to MySQL database. ' . $pe->getMessage(), E_USER_ERROR);
+        }
+    }
+
     function get_persons($filter)
     {
         $sql = "SELECT *, NULL as invoice FROM person " . ($filter?  "WHERE " . $filter : '');   
diff --git a/index.php b/index.php
index 9f75d0c..8a142dc 100755
--- a/index.php
+++ b/index.php
@@ -19,6 +19,7 @@
 include $TEMPLATE . "strings.php";
 $log = new Logger('signup');
 $log->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/signup.log', 0, Logger::DEBUG));
+$dinners_left = $MAX_DINNERS - (new DB($log))->dinner_count();
 
 if (!$DEBUG)    error_reporting(0);
 else error_reporting(1);
@@ -115,6 +116,7 @@
 
 function register_page($error = false)
 {
+    global $log, $dinners_left;
     $TEMPLATE = template_path();
     include 'config.php';
     if ($error)
diff --git a/templates/register.htm b/templates/register.htm
index e3a4425..9f55338 100644
--- a/templates/register.htm
+++ b/templates/register.htm
@@ -506,8 +506,11 @@
 
     <div class="form-outline mb-3">
         <label class="form-label fw-bold" for="conference_dinner">Conference Dinner</label>
+        <div id="dinnerHelp2" class="form-text">
+            <?php if ($dinners_left > 0) echo "$dinners_left places left"; else echo "Sorry, already fully booked"; ?>.
+        </div>
         <div class="form-group form-check">
-            <input type="checkbox" class="form-check-input" name="conference_dinner" id="conference_dinner" <?php echo isset($_POST[ 'conference_dinner']) ? 'checked' : '' ?> oninput="update_total_due()" value="conference_dinner">
+            <input <?php if ($dinners_left <=0) echo "disabled"; ?> type="checkbox" class="form-check-input" name="conference_dinner" id="conference_dinner" <?php echo isset($_POST[ 'conference_dinner']) ? 'checked' : '' ?> oninput="update_total_due()" value="conference_dinner">
             <label class="form-check-label fs-4" for="conference_dinner">I will be attending the <a href="#"  data-container="body" style="text-decoration: underline; color: black; cursor: help;" html="true" data-bs-html="true" data-bs-toggle="tooltip" title="
                 <h1>ICLC-10 Conference Dinner (Buffet)</h1>
                  <h2>Starters</h2>