changeset 103:c6b9041078ec

Add hard limit option for attendees, and add feature of using "0" to disable hard and soft limit completely.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 21 Oct 2013 14:52:06 +0300
parents 53b35cb4111b
children c7b1eb993240
files attendees.inc.php createdb.php index.php msite.inc.php register.inc.php
diffstat 5 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/attendees.inc.php	Mon Oct 21 13:45:11 2013 +0300
+++ b/attendees.inc.php	Mon Oct 21 14:52:06 2013 +0300
@@ -1,5 +1,5 @@
 <?
-if (stChkSetting("allowRegister"))
+if (stCheckRegistrationAvailable())
 {
 ?>
 <div class="reglink">
@@ -8,15 +8,13 @@
 <?
 }
 
-//echo "<h1>Current attendees</h1>\n";
-$maxAttendees = stGetSetting("maxAttendees");
-$numAttendees = 0;
-if (($res = $db->query("SELECT COUNT(*) FROM attendees")) !== FALSE)
-  $numAttendees = $res->fetchColumn();
+echo "<p>Total of <b>".$numAttendees.
+ "</b> people registered to attend";
 
-echo "<p>Total of <b>".$numAttendees.
- "</b> people registered to attend (<b>".
- $maxAttendees."</b> max).</p>\n";
+if ($maxAttendeesHard > 0)
+ echo " (<b>".$maxAttendeesHard."</b> max)";
+
+echo ".</p>\n";
 
 ?>
 <table class="attendees">
@@ -33,7 +31,8 @@
 {
   foreach ($res as $item)
   {
-    stPrintAttendee($item, $row++, FALSE, ($index > $maxAttendees) ? " overbooked" : "");
+    $over = $maxAttendeesSoft > 0 && $index > $maxAttendeesSoft;
+    stPrintAttendee($item, $row++, FALSE, $over ? " overbooked" : "");
     $index--;
   }
 }
--- a/createdb.php	Mon Oct 21 13:45:11 2013 +0300
+++ b/createdb.php	Mon Oct 21 14:52:06 2013 +0300
@@ -13,7 +13,8 @@
 
 // The defaults we put in
 $siteDefaults = array(
-  "maxAttendees"     => array(VT_INT, 60, "Maximum attendees (soft limit)"),
+  "maxAttendeesHard" => array(VT_INT, 60, "Maximum attendees (HARD limit, 0 = no limit)"),
+  "maxAttendeesSoft" => array(VT_INT, 50, "Maximum attendees (soft limit, 0 = no limit)"),
 
   "userTimeout"      => array(VT_INT, 120, "User pages (voting, entry submission) timeout in minutes"),
   "admTimeout"       => array(VT_INT, 15, "Administration interface timeout in minutes"),
--- a/index.php	Mon Oct 21 13:45:11 2013 +0300
+++ b/index.php	Mon Oct 21 14:52:06 2013 +0300
@@ -49,6 +49,9 @@
 
 if (stGetSetting("showAttendees"))
 echo "  <a href=\"attendees\">Attendees</a>\n";
+else
+if (stChkSetting("allowRegister"))
+echo "  <a href=\"register\">Register</a>\n";
 
 if (stGetSetting("allowVoting"))
 echo "  <a href=\"vote\">Vote</a>\n";
--- a/msite.inc.php	Mon Oct 21 13:45:11 2013 +0300
+++ b/msite.inc.php	Mon Oct 21 14:52:06 2013 +0300
@@ -526,4 +526,15 @@
 }
 
 
+function stCheckRegistrationAvailable()
+{
+  global $maxAttendeesHard, $maxAttendeesSoft, $numAttendees;
+
+  $maxAttendeesHard = stGetSetting("maxAttendeesHard");
+  $maxAttendeesSoft = stGetSetting("maxAttendeesSoft");
+  if (($numAttendees = stFetchSQLColumn("SELECT COUNT(*) FROM attendees")) === FALSE)
+    $numAttendees = 0;
+
+  return stChkSetting("allowRegister") && ($maxAttendeesHard <= 0 || $numAttendees < $maxAttendeesHard);
+}
 ?>
\ No newline at end of file
--- a/register.inc.php	Mon Oct 21 13:45:11 2013 +0300
+++ b/register.inc.php	Mon Oct 21 14:52:06 2013 +0300
@@ -81,13 +81,26 @@
   return $res;
 }
 
+stCheckRegistrationAvailable();
+
 // Check if registration is enabled
 if (!stChkSetting("allowRegister"))
 {
 ?>
 <h1>Sorry, registration disabled!</h1>
 <p>
-Registration to the event is not available at this time.
+Registration to the event is not enabled at this time.
+</p>
+<?
+}
+else
+if ($maxAttendeesHard > 0 && $numAttendees >= $maxAttendeesHard)
+{
+?>
+<h1>Sorry, registration disabled!</h1>
+<p>
+Registration to the event is not available at this time due to
+number of attendees limit having been reached. <b>:(</b>
 </p>
 <?
 }