diff($past); $chosen_date = $today; $days_range1 = $interval->days; $days_range2 = 0; // Do some ajax stuff if (isset($_POST['range1'])) { $range1 = $_POST['range1']; $range2 = $_POST['range2']; $choice1 = new DateTime($range1); $interval = $today_date->diff($choice1); $days_range1 = $interval->days; $choice2 = new DateTime($range2); $interval = $today_date->diff($choice2); $days_range2 = $interval->days; $year_ago = $range1; $today = $range2; } $query = "SELECT shop_user_role, COUNT(DISTINCT shop_hours.contact_id) as unique_volunteers, COUNT(shop_hours.contact_id) as volunteer_visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS volunteer_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 OR shop_user_roles.other_volunteer = 1) GROUP BY shop_user_role ORDER BY volunteer_hours DESC;"; $volunteers_sql = mysql_query($query, $YBDB) or die(mysql_error()); $query = "SELECT COUNT(DISTINCT shop_hours.contact_id) as unique_volunteers, COUNT(shop_hours.contact_id) as volunteer_visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS volunteer_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 OR shop_user_roles.other_volunteer = 1);"; $total_volunteers_sql = mysql_query($query, $YBDB) or die(mysql_error()); $query = "SELECT shop_user_role, COUNT(DISTINCT shop_hours.contact_id) as unique_visitors, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS 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 (time_in >= DATE_SUB(CURDATE(),INTERVAL $days_range1 DAY) AND time_in <= DATE_SUB(CURDATE(), INTERVAL $days_range2 DAY)) AND (shop_user_roles.volunteer = 0 AND shop_user_roles.other_volunteer = 0) GROUP BY shop_user_role ORDER BY hours DESC;"; $visitors_sql = mysql_query($query, $YBDB) or die(mysql_error()); $query = "SELECT COUNT(DISTINCT shop_hours.contact_id) as unique_visitors, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS 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 = 0 AND shop_user_roles.other_volunteer = 0);"; $total_visitors_sql = mysql_query($query, $YBDB) or die(mysql_error()); $query = "SELECT COUNT(DISTINCT shop_hours.contact_id) as unique_vv, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS 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 >= 0 OR shop_user_roles.other_volunteer >= 0);"; $total_sql = mysql_query($query, $YBDB) or die(mysql_error()); ?>
Volunteers
Shop Roles
Unique Volunteers
Volunteer Visits
Volunteer Hours
       
Total Volunteers
Unique Volunteers
Volunteer Visits
Volunteer Hours
     


Visitors
Shop Roles
Unique Visitors
Visits
Hours
       
Total Visitors
Unique Visitors
Visits
Hours
     


Total Volunteers and Visitors
Unique
Visits
Hours
     


Date Range: