Browse Source

Adds membership stats. An important addition.

Currently, searches ranges for volunteer specs for membership, and notes paid
member when they also qualify as a volunteer member.
devel
Jonathan Rosenbaum 9 years ago
parent
commit
92fe18644d
  1. 2
      css/stats.css
  2. 9
      js/stats.js
  3. 2
      stats.php
  4. 173
      stats/members.php

2
css/stats.css

@ -3,7 +3,7 @@
} }
#status_totals, #community_service_hours, #shops{ #status_totals, #community_service_hours, #shops, #members{
height: 36px; height: 36px;
width: 98px; width: 98px;
font-size: x-large; font-size: x-large;

9
js/stats.js

@ -50,4 +50,13 @@ $(function(){
e.preventDefault(); e.preventDefault();
}); });
$("#members").on("click keypress", function(e){
var range_display = range.pickmeup('get_date', true);
$.post("members.php", {range1: range_display[0], range2: range_display[1]}, function (data) {
$("body").html(data);
//range.pickmeup.date($range_display[0]);
});
e.preventDefault();
});
}); });

2
stats.php

@ -9,7 +9,7 @@
<p class="yb_heading3red">Membership</p> <p class="yb_heading3red">Membership</p>
<ul> <ul>
<li><a href="stats/members.php" >Members (Running 12 Month Period)</a></li> <li><a href="stats/members.php" >Members (Running 12 Month Period and Range)</a></li>
</ul> </ul>
<p class="yb_heading3red">Volunteer Shops</p> <p class="yb_heading3red">Volunteer Shops</p>

173
stats/members.php

@ -2,6 +2,12 @@
require_once('../Connections/YBDB.php'); require_once('../Connections/YBDB.php');
require_once('../Connections/database_functions.php'); require_once('../Connections/database_functions.php');
$page_individual_history_log = INDIVIDUAL_HISTORY_LOG;
// Needs to volunteer at least this amount of defined hours before being considered a member
$membership_hours = MEMBERSHIP_HOURS;
$membership_days = MEMBERSHIP_DAYS;
$purchased_membership_days = PURCHASED_MEMBERSHIP_DAYS;
mysql_select_db($database_YBDB, $YBDB); mysql_select_db($database_YBDB, $YBDB);
@ -33,24 +39,71 @@ if (isset($_POST['range1'])) {
$today = $range2; $today = $range2;
} }
/*
$query = "SELECT COUNT(shop_id) as total_shops from shops
WHERE (date >= DATE_SUB(CURDATE(),INTERVAL $days_range1 DAY) AND date <= DATE_SUB(CURDATE(), INTERVAL $days_range2 DAY));"; SELECT contact_id, full_name, email, phone, sort_visits, sort_hours FROM
$shop_totals_sql = mysql_query($query, $YBDB) or die(mysql_error()); (SELECT contacts.contact_id, CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
contacts.email AS email, contacts.phone AS phone,
$query = "SELECT shop_type, COUNT(shop_id) AS shop_totals from shops COUNT(shop_hours.contact_id) as sort_visits,
LEFT JOIN shop_types ON shops.shop_type = shop_types.shop_type_id ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS sort_hours
WHERE (date >= DATE_SUB(CURDATE(),INTERVAL $days_range1 DAY) AND date <= DATE_SUB(CURDATE(), INTERVAL $days_range2 DAY)) FROM shop_hours
GROUP BY shop_type ORDER BY shop_totals DESC;"; LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id
$shop_totals_by_types_sql = mysql_query($query, $YBDB) or die(mysql_error()); LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
WHERE (time_in > DATE_SUB(CURDATE(),INTERVAL 12 MONTH))
AND shop_user_roles.volunteer = 1 GROUP BY contact_id) AS members
WHERE sort_hours >= 8 AND sort_visits >= 2
GROUP by contact_id ORDER by sort_hours DESC, sort_visits DESC;
SELECT contacts.contact_id,
CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
CONCAT(first_name, ' ', last_name) AS normal_full_name,
contacts.email AS email, contacts.phone AS phone,
transaction_log.date as sort_hours
FROM transaction_log
LEFT JOIN contacts ON transaction_log.sold_to = contacts.contact_id
WHERE (SUBSTRING_INDEX(date, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
AND SUBSTRING_INDEX(date, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
AND (transaction_type="Memberships" AND paid=1);
*/
// Membership via volunteering
$query = "SELECT contact_id, full_name, normal_full_name, email, phone, sort_visits, sort_hours FROM
(SELECT contacts.contact_id, CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
CONCAT(first_name, ' ', last_name) AS normal_full_name,
contacts.email AS email, contacts.phone AS phone,
COUNT(shop_hours.contact_id) as sort_visits,
ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS sort_hours
FROM shop_hours
LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL $days_range1 DAY)
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL $days_range2 DAY))
AND shop_user_roles.volunteer = 1 GROUP BY contact_id) AS members
WHERE sort_hours >= $membership_hours AND sort_visits >= $membership_days
GROUP by contact_id ORDER by sort_hours DESC, sort_visits DESC;";
$members = mysql_query($query, $YBDB) or die(mysql_error());
$num_member_rows = mysql_num_rows($members);
// Purchased Membership
$purchase_query = "SELECT contacts.contact_id,
CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
CONCAT(first_name, ' ', last_name) AS normal_full_name,
contacts.email AS email, contacts.phone AS phone,
transaction_log.date as sort_hours
FROM transaction_log
LEFT JOIN contacts ON transaction_log.sold_to = contacts.contact_id
WHERE (SUBSTRING_INDEX(date, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL $purchased_membership_days DAY)
AND SUBSTRING_INDEX(date, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY))
AND (transaction_type='Memberships' AND paid=1);";
$purchased_membership = mysql_query($purchase_query, $YBDB) or die(mysql_error());
?> ?>
<?php include("../include_header_stats.html"); ?>
Under Construction
<!-- <?php include("../include_header_stats.html"); ?>
<table class="stats"> <table class="stats">
<tr valign="top"> <tr valign="top">
@ -59,25 +112,26 @@ Under Construction
<td> <td>
<table border="1" cellpadding="1" cellspacing="0"> <table border="1" cellpadding="1" cellspacing="0">
<tr bgcolor="#99CC33" class="yb_standardCENTERbold"> <tr bgcolor="#99CC33" class="yb_standardCENTERbold">
<td colspan="4" height="25">Totals for Shop Openings</td> <td colspan="4" height="25">Membership</td>
</tr> </tr>
<tr valign="top" bgcolor="#99CC33" class="yb_standardCENTER"> <tr valign="top" bgcolor="#99CC33" class="yb_standardCENTER">
<td width="relative">Type<br /></td> <td width="relative"><?php echo $num_member_rows; ?> Members<br /></td>
<td width="relative">Totals<br /></td> <td width="relative">Visits<br /></td>
</tr> <td width="relative">Hours<br /></td>
<?php while ($result = mysql_fetch_assoc($shop_totals_by_types_sql)) { //do {
?>
<tr>
<td class="yb_standardRIGHTred"><?php echo $result['shop_type'] ?></td>
<td class="yb_standardRIGHT"><?php echo number_format($result['shop_totals'],0); ?></td>
</tr> </tr>
<?php <?php
} // end WHILE count of recordset ?> $purchased = mysql_fetch_assoc($purchased_membership);
<?php while ($result = mysql_fetch_assoc($shop_totals_sql)) { //do { while ($result = mysql_fetch_assoc($members)) {
//do {
?> ?>
<tr> <tr>
<td></td> <?php if($purchased['contact_id'] === $result['contact_id']) { ?>
<td class="yb_standardRIGHT"><?php echo number_format($result['total_shops'],0); ?></td> <td class="yb_standardRIGHTred"><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a>&nbsp;(paid)</td>
<?php } else { ?>
<td class="yb_standardRIGHTred"><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a></td>
<?php } ?>
<td class="yb_standardRIGHT"><?php echo number_format($result['sort_visits'],0); ?></td>
<td class="yb_standardRIGHT"><?php echo number_format($result['sort_hours'],0); ?></td>
</tr> </tr>
<?php <?php
} // end WHILE count of recordset ?> } // end WHILE count of recordset ?>
@ -85,7 +139,6 @@ Under Construction
</tr> </tr>
</table> </table>
-->
<br \><br \> <br \><br \>
@ -94,12 +147,70 @@ Under Construction
<br \> <br \>
<form method="post" name="range_query"> <form method="post" name="range_query">
<input id="shops" type="submit" value="Submit" tabindex="14"> <input id="members" type="submit" value="Submit" tabindex="14">
</form> </form>
<h3>Contact Information</h3>
<b>Email Address:</b>&nbsp;
<?php
mysql_free_result($members);
$members = mysql_query($query, $YBDB) or die(mysql_error());
$c = 1;
while ($result = mysql_fetch_assoc($members)) {
if ($result['email']) {
if ($c < $num_member_rows) {
echo $result['normal_full_name'] . " &lt;" . $result['email'] . "&gt;, ";
} else {
echo $result['normal_full_name'] . " &lt;" . $result['email'] . "&gt;";
}
}
$c++;
?>
<?php } // end WHILE count of recordset ?>
<p></p>
<b>Phone Numbers for Members Without Email Addresses</b><br \>
<?php
mysql_free_result($members);
$members = mysql_query($query, $YBDB) or die(mysql_error());
$c = 1;
while ($result = mysql_fetch_assoc($members)) {
if ( $result['phone'] && !$result['email'] ) {
if ($c < $num_member_rows) {
echo $result['normal_full_name'] . ", " . $result['phone'] . "<br />";
} else {
echo $result['normal_full_name'] . ", " . $result['phone'];
}
}
$c++;
?>
<?php } // end WHILE count of recordset ?>
<p></p>
<u><b>CSV</b></u><br \>
<b>Name, Phone, Email</b><br \>
<?php
mysql_free_result($members);
$members = mysql_query($query, $YBDB) or die(mysql_error());
$c = 1;
while ($result = mysql_fetch_assoc($members)) {
if ($c < $num_member_rows) {
echo $result['normal_full_name'] . ", " . $result['phone'] . ", ". $result['email'] . "<br \>";
} else {
echo $result['normal_full_name'] . ", " . $result['phone'] . ", ". $result['email'];
}
$c++;
?>
<?php } // end WHILE count of recordset ?>
<?php include("../include_footer.html"); ?> <?php include("../include_footer.html"); ?>
<?php <?php
mysql_free_result($shop_totals_sql); mysql_free_result($members);
mysql_free_result($shop_totals_by_types_sql);
?> ?>

Loading…
Cancel
Save