function getRFIDWhitelist() { global $con; $whiteList = array(); //get everyone's plan prices and balances and check here $balances = payment_accounts(); foreach ($balances as $cid => $bal) { //now get this member's monthly plan amount $memberData = member_data(array("cid" => $cid)); $planAmount = $memberData[0]["membership"][0]["plan"]["price"]; $firstName = $memberData[0]["contact"]["firstName"]; $lastName = $memberData[0]["contact"]["lastName"]; $memberBalance = $bal['value'] / 100; if ($memberBalance <= $planAmount * 2 || $memberBalance == 0) { //this member has paid their dues. Add to whitelist. //get their key serial and add that too! $query = "SELECT serial FROM `key` WHERE char_length(serial) > 5 and cid = " . $cid; $result = mysqli_query($con, $query) or die(json_encode(array("getRFIDWhitelistQueryERROR" => mysqli_error($con)))); $r = mysqli_fetch_assoc($result); $serial = $r["serial"]; if ($serial != NULL) { $whiteList[] = array("firstName" => $firstName, "lastName" => $lastName, "serial" => $serial); } } } return $whiteList; }
/** * @return A comma-separated list of user emails. * @param $opts - Options to pass to member_data(). */ function member_email_report($opts) { $result = array(); $data = member_data($opts); foreach ($data as $row) { $email = trim($row['contact']['email']); if (!empty($email)) { $result[] = $email; } } return join($result, ', '); }
/** * Return table structure for all active voting members. * * @return The table structure. */ function member_voting_report_table() { // Ensure user is allowed to view members if (!user_access('member_view')) { return NULL; } // Get member data $members = member_data(array('filter' => array('voting' => true, 'active' => true))); // Create table structure $table = array('id' => '', 'class' => 'member-voting-report', 'rows' => array()); // Add columns $table['columns'] = array(); if (user_access('member_view')) { $table['columns'][] = array('title' => 'Name', 'class' => 'name'); $table['columns'][] = array('title' => 'Present', 'class' => 'check'); $table['columns'][] = array('title' => 'A', 'class' => ''); $table['columns'][] = array('title' => 'B', 'class' => ''); $table['columns'][] = array('title' => 'C', 'class' => ''); $table['columns'][] = array('title' => 'D', 'class' => ''); $table['columns'][] = array('title' => 'E', 'class' => ''); } // Loop through member data foreach ($members as $member) { // Add user data $row = array(); if (user_access('member_view')) { $name = $member['contact']['lastName'] . ', ' . $member['contact']['firstName']; if (!empty($member['contact']['middleName'])) { $name .= ' ' . $member['contact']['middleName']; } $row[] = $name; $row[] = ' '; $row[] = ' '; $row[] = ' '; $row[] = ' '; $row[] = ' '; $row[] = ' '; } // Add row to table $table['rows'][] = $row; } // Return table return $table; }
/** * Return data for one or more mentor assignments. * * @param $opts An associative array of options, possible keys are: * 'cid' If specified, returns mentor contacts assigned to this cid, * and the proteges assigned to this cid; * @return An array with each element representing a mentor assignment. */ function mentor_data($opts = array()) { if (array_key_exists('cid', $opts)) { foreach ($opts['cid'] as $cid) { } } // Create map from cids to contact names if necessary // TODO: Add filters for speed if ($join_contact) { $contacts = member_contact_data(); $cidToContact = array(); foreach ($contacts as $contact) { $cidToContact[$contact['cid']] = $contact; } } if ($join_member) { $members = member_data(); $cidToMember = array(); foreach ($members as $member) { $cidToMember[$member['cid']] = $member; } } // Query database $sql = "\r\n SELECT\r\n `cid`\r\n , `mentor_cid`\r\n FROM `mentor`\r\n WHERE 1"; if (!empty($opts['cid'])) { if (is_array($opts['cid'])) { $terms = array(); foreach ($opts['cid'] as $cid) { $esc_cid = mysql_real_escape_string($cid); $terms[] = "'{$cid}'"; } $sql .= " AND `cid` IN (" . implode(', ', $terms) . ") "; $sql .= " OR `mentor_cid` IN (" . implode(', ', $terms) . ") "; } else { $esc_cid = mysql_real_escape_string($opts['cid']); $sql .= " AND `cid`='{$esc_cid}'"; $sql .= " OR `mentor_cid`='{$esc_cid}'"; } } if (!empty($opts['mentor_cid'])) { $esc_cid = mysql_real_escape_string($opts['mentor_cid']); $sql .= " AND `mentor_cid`='{$esc_cid}'"; } //TODO: specify an order? (ORDER BY... ASC) $res = mysql_query($sql); if (!$res) { die(mysql_error()); } // Store data in mentorships array $mentorships = array(); $row = mysql_fetch_assoc($res); while (!empty($row)) { $mentorship = array('cid' => $row['cid'], 'mentor_cid' => $row['mentor_cid']); $mentorships[] = $mentorship; $row = mysql_fetch_assoc($res); } // At this point, the mentorships might not be in unique rows. // in other words, there might be multiple entries with the same cid // we should match up multiple mentors/proteges that are related to // the same cid $mentor_data = array(); foreach ($mentorships as $mentorship) { if (!empty($mentor_data[$mentorship['cid']])) { //this is a new cid. Create an array. $mentor_data[$mentorship['cid']] = array('mentor_cids' => array(), 'protege_cids' => array()); } //populate array with mentor_cid (it should be created by now if it previously // didn't exist.) $mentor_data[$mentorship['cid']]['mentor_cids'][] = $mentorship['mentor_cid']; //now do the opposite. that is to say, assign the protege to the mentor_cid //of course, this involves creating the mentor_cid if it doesn't exist yet if (!empty($mentor_data[$mentorship['mentor_cid']])) { //this is a new cid. Create an array. $mentor_data[$mentorship['cid']] = array('mentor_cids' => array(), 'protege_cids' => array()); } //populate the mentor's array with protege cid. $mentor_data[$mentorship['mentor_cid']]['protege_cids'][] = $mentorship['cid']; } // Return data return $mentor_data; }
/** * Return the form structure to delete a member. * * @param $cid The cid of the member to delete. * @return The form structure. */ function member_delete_form($cid) { // Ensure user is allowed to delete members if (!user_access('member_delete')) { return NULL; } // Get member data $data = member_data(array('cid' => $cid)); $member = $data[0]; // Construct member name if (empty($member) || count($member) < 1) { return array(); } // Create form structure $form = array('type' => 'form', 'method' => 'post', 'command' => 'member_delete', 'hidden' => array('cid' => $member['contact']['cid']), 'fields' => array(array('type' => 'fieldset', 'label' => 'Delete Member', 'fields' => array(array('type' => 'message', 'value' => '<p>Are you sure you want to delete the member "' . theme_contact_name($member['cid']) . '"? This cannot be undone.'), array('type' => 'checkbox', 'label' => 'Delete all contact info?', 'name' => 'deleteContact', 'checked' => true), array('type' => 'submit', 'value' => 'Delete'))))); return $form; }
/** * Return the text of an email notifying administrators that a user has been created. * @param $cid The contact id of the new member. */ function theme_member_created_email($cid) { // Get info on the logged in user $data = member_contact_data(array('cid' => user_id())); $admin = $data[0]; $adminName = theme_contact_name($admin['cid']); // Get info on member $data = member_data(array('cid' => $cid)); $member = $data[0]; $contact = $member['contact']; $name = theme_contact_name($contact['cid']); // Get info on member's plan $data = member_membership_data(array('cid' => $cid, $filter => array('active' => true))); $date = $data[0]['start']; $plan = $data[0]['plan']['name']; $output = "<p>Contact info:<br/>\n"; $output .= "Name: {$name}<br/>\n"; $output .= "Email: {$contact['email']}<br/>\n"; $output .= "Phone: {$contact['phone']}\n</p>\n"; $output .= "<p>Membership info:<br/>\n"; $output .= "Plan: {$plan}<br/>\n"; $output .= "Start date: {$date}\n</p>\n"; $output .= "<p>Entered by: {$adminName}</p>\n"; return $output; }