Exemple #1
0
/**
 * Generate description for a membership plan.
 *
 * @param $sid The sid of the membership.
 * @return The description string.
 */
function member_membership_description($sid)
{
    // Get membership data
    $data = member_membership_data(array('sid' => $sid));
    $membership = $data[0];
    // Get member contact info
    $data = member_contact_data(array('cid' => $membership['cid']));
    $contact = $data[0];
    // Construct description
    $description = 'Membership : ';
    $description .= theme_contact_name($contact['cid']);
    $description .= ' : ' . $membership['plan']['name'];
    $description .= ' : Starting ' . $membership['start'];
    return $description;
}
Exemple #2
0
/**
 * Return a table structure representing contact info.
 *
 * @param $opts Options to pass to member_contact_data().
 * @return The table structure.
*/
function member_contact_table($opts)
{
    // Get contact data
    $data = member_contact_data($opts);
    $contact = $data[0];
    if (empty($contact) || count($contact) < 1) {
        return array();
    }
    // Initialize table
    $table = array("id" => '', "class" => '', "rows" => array(), "columns" => array());
    // Add columns
    $table['columns'][] = array("title" => 'Name', 'class' => '', 'id' => '');
    $table['columns'][] = array("title" => 'Email', 'class' => '', 'id' => '');
    $table['columns'][] = array("title" => 'Phone', 'class' => '', 'id' => '');
    $table['columns'][] = array("title" => 'Emergency contact', 'class' => '', 'id' => '');
    $table['columns'][] = array("title" => 'Emergency phone', 'class' => '', 'id' => '');
    // Add row
    $table['rows'][] = array(theme('contact_name', $contact), $contact['email'], $contact['phone'], $contact['emergencyName'], $contact['emergencyPhone']);
    return $table;
}
Exemple #3
0
/**
 * 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;
}
Exemple #4
0
/**
 * Return the form structure for editing a membership.
 *
 * @param $sid id of the membership to edit.
 * @return The form structure.
*/
function member_membership_edit_form($sid)
{
    // Ensure user is allowed to edit memberships
    if (!user_access('member_membership_edit')) {
        return NULL;
    }
    // Get membership data
    $data = member_membership_data(array('sid' => $sid));
    $membership = $data[0];
    if (empty($membership) || count($membership) < 1) {
        return array();
    }
    // Construct contact name
    $data = member_contact_data(array('cid' => $membership['cid']));
    $contact = $data[0];
    $name = theme_contact_name($contact['cid']);
    // Create form structure
    $form = array('type' => 'form', 'method' => 'post', 'command' => 'member_membership_update', 'hidden' => array('sid' => $sid, 'cid' => $membership['cid']), 'fields' => array(array('type' => 'fieldset', 'label' => 'Edit Membership Info', 'fields' => array(array('type' => 'readonly', 'label' => 'Name', 'value' => $name), array('type' => 'select', 'label' => 'Plan', 'name' => 'pid', 'options' => member_plan_options(), 'selected' => $membership['pid']), array('type' => 'text', 'label' => 'Start', 'name' => 'start', 'class' => 'date', 'value' => $membership['start']), array('type' => 'text', 'label' => 'End', 'name' => 'end', 'class' => 'date', 'value' => $membership['end']), array('type' => 'submit', 'value' => 'Update')))));
    return $form;
}
Exemple #5
0
/**
 * 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;
}