Example #1
0
/**
 * Page hook.  Adds module content to a page before it is rendered.
 *
 * @param &$page_data Reference to data about the page being rendered.
 * @param $page_name The name of the page being rendered.
*/
function devel_page(&$page_data, $page_name)
{
    switch ($page_name) {
        case 'contact':
            // Capture contact id
            $cid = $_GET['cid'];
            if (empty($cid)) {
                return;
            }
            if (!user_access('contact_view')) {
                return;
            }
            $contact = crm_get_one('contact', array('cid' => $cid));
            // Add devel tab
            page_add_content_top($page_data, '<pre>' . print_r($contact, true) . '</pre>', 'Devel');
            break;
    }
}
/**
 * Return the delete key assigment form structure.
 *
 * @param $kid The kid of the key assignment to delete.
 * @return The form structure.
*/
function secrets_delete_form($name)
{
    // Ensure user is allowed to delete keys
    if (!user_access('secrets_delete')) {
        return NULL;
    }
    // Get secret data
    $secrets = crm_get_one('secrets', array('name' => $name));
    // Construct secret name
    $secret_name = $secrets['name'];
    // Create form structure
    $form = array('type' => 'form', 'method' => 'post', 'command' => 'secrets_delete', 'submit' => 'Delete', 'hidden' => array('name' => $secrets['name']), 'fields' => array(array('type' => 'fieldset', 'label' => 'Delete Secret', 'fields' => array(array('type' => 'message', 'value' => '<p>Are you sure you want to delete the secret  "' . $secret_name . '"? This cannot be undone.')))));
    return $form;
}
Example #3
0
/**
 * Return the form structure for an edit key assignment form.
 *
 * @param $kid The kid of the key assignment to edit.
 * @return The form structure.
*/
function key_edit_form($kid)
{
    // Ensure user is allowed to edit key
    if (!user_access('key_edit')) {
        return NULL;
    }
    // Get key data
    $data = crm_get_data('key', array('kid' => $kid));
    $key = $data[0];
    if (empty($key) || count($key) < 1) {
        return array();
    }
    // Get corresponding contact data
    $contact = crm_get_one('contact', array('cid' => $key['cid']));
    // Construct member name
    $name = theme('contact_name', $contact, true);
    // Create form structure
    $form = array('type' => 'form', 'method' => 'post', 'command' => 'key_update', 'hidden' => array('kid' => $kid), 'fields' => array(array('type' => 'fieldset', 'label' => 'Edit Key Info', 'fields' => array(array('type' => 'readonly', 'label' => 'Name', 'value' => $name), array('type' => 'text', 'class' => 'date', 'label' => 'Start', 'name' => 'start', 'value' => $key['start']), array('type' => 'text', 'class' => 'date', 'label' => 'End', 'name' => 'end', 'value' => $key['end']), array('type' => 'text', 'label' => 'Serial', 'name' => 'serial', 'value' => $key['serial']), array('type' => 'text', 'label' => 'Slot', 'name' => 'slot', 'value' => $key['slot']), array('type' => 'submit', 'value' => 'Update')))));
    return $form;
}
Example #4
0
/**
 * Return the delete mentor assigment form structure.
 *
 * @param $cid The cid of the protege to delete the mentor from.
 * @return The form structure.
*/
function mentor_delete_form($cid)
{
    // Ensure user is allowed to delete mentors
    if (!user_access('mentor_delete')) {
        return NULL;
    }
    // Get corresponding contact data
    $data = crm_get_data('contact', $opts = array('cid' => $cid));
    $contact = $data[0];
    // Construct member name
    $name = member_name($contact['firstName'], $contact['middleName'], $contact['lastName']);
    // Get list of current mentor cids.
    $mentor_cid = $contact['member']['mentorships']['mentor_cids'][0];
    // Construct mentor name (from member/protege)
    $mentor_contact = crm_get_one('contact', $opts = array('cid' => $mentor_cid));
    $mentor_name = theme('contact_name', $mentor_contact);
    // Create form structure
    $form = array('type' => 'form', 'method' => 'post', 'command' => 'mentor_delete', 'hidden' => array('cid' => $cid, 'mentor_cid' => $mentor_cid), 'fields' => array(array('type' => 'fieldset', 'label' => 'Delete Mentor', 'fields' => array(array('type' => 'message', 'value' => '<p>Are you sure you want to delete the member assignment "' . $mentor_name . '"? This cannot be undone.'), array('type' => 'submit', 'value' => 'Delete')))));
    return $form;
}
Example #5
0
/**
 * Respond to reset password request.
*/
function command_reset_password()
{
    global $config_host;
    global $config_base_path;
    global $config_email_from;
    global $config_site_title;
    // Send code to user by username
    $user = crm_get_one('user', array('filter' => array('username' => $_POST['username'])));
    if (empty($user)) {
        // Try email instead
        $user = crm_get_one('user', array('filter' => array('email' => $_POST['username'])));
    }
    if (empty($user)) {
        error_register('No such username/email.');
        return crm_url();
    }
    $contact = crm_get_one('contact', array('cid' => $user['cid']));
    $url = user_reset_password_url($user['username']);
    if (!empty($url)) {
        $to = $contact['email'];
        $subject = "[{$config_site_title}] Reset Password";
        $from = $config_email_from;
        $headers = "From: {$from}\r\n";
        $message = "To reset your password, visit the following url: {$url}";
        $res = mail($to, $subject, $message, $headers);
        // Notify user to check their email
        message_register('Instructions for resetting your password have been sent to your e-mail.');
    }
    return crm_url();
}
/**
 * Return themed html for prorated first month button.
 */
function theme_amazon_payment_first_month($cid)
{
    if (!function_exists('billing_revision')) {
        return 'Prorated dues payment requires billing module.';
    }
    $contact = crm_get_one('contact', array('cid' => $cid));
    // Calculate fraction of the billing period
    $mship = end($contact['member']['membership']);
    $date = getdate(strtotime($mship['start']));
    $period = billing_days_in_period($date);
    $day = $date['mday'];
    $fraction = ($period - $day + 1.0) / $period;
    // Get payment amount
    $due = payment_parse_currency($mship['plan']['price']);
    $due['value'] = ceil($due['value'] * $fraction);
    $html .= $due['value'];
    // Create button
    $html = "<fieldset><legend>First month prorated dues</legend>";
    $params = array('referenceId' => $cid, 'amount' => $due['code'] . ' ' . payment_format_currency($due, false), 'description' => 'CRM Dues Payment');
    $amount = payment_format_currency($due);
    $html .= "<p><strong>First month's dues:</strong> {$amount}</p>";
    if ($due['value'] > 0) {
        $html .= theme('amazon_payment_button', $cid, $params);
    }
    $html .= '</fieldset>';
    return $html;
}
Example #7
0
/**
 * Delete the payment identified by $pmtid.
 * @param $pmtid The payment id.
 */
function payment_delete($pmtid)
{
    $payment = crm_get_one('payment', array('pmtid' => $pmtid));
    $payment = module_invoke_api('payment', $payment, 'delete');
    // Query database
    $esc_pmtid = mysql_real_escape_string($pmtid);
    $sql = "\n        DELETE FROM `payment`\n        WHERE `pmtid`='{$esc_pmtid}'";
    $res = mysql_query($sql);
    if (!$res) {
        crm_error(mysql_error());
    }
    if (mysql_affected_rows() > 0) {
        message_register('Deleted payment with id ' . $pmtid);
    }
}
/**
 * Generate payments contacts table
 *
 * @param $opts an array of options passed to the paypal_payment_contact_data function
 * @return a table (array) listing the contacts represented by all payments
 *   and their associated paypal email
 */
function paypal_payment_contact_table($opts)
{
    $data = crm_get_data('paypal_payment_contact', $opts);
    // Initialize table
    $table = array("id" => '', "class" => '', "rows" => array(), "columns" => array());
    // Check for permissions
    if (!user_access('payment_view')) {
        error_register('User does not have permission to view payments');
        return;
    }
    // Add columns
    $table['columns'][] = array("title" => 'Full Name');
    $table['columns'][] = array("title" => 'Paypal Email');
    // Add ops column
    if (!$export && (user_access('payment_edit') || user_access('payment_delete'))) {
        $table['columns'][] = array('title' => 'Ops', 'class' => '');
    }
    // Add rows
    foreach ($data as $union) {
        $row = array();
        //first column is the full name associated with the union['cid']
        $memberopts = array('cid' => $union['cid']);
        $contact = crm_get_one('contact', array('cid' => $union['cid']));
        $contactName = '';
        if (!empty($contact)) {
            $contactName = theme('contact_name', $contact, true);
        }
        $row[] = $contactName;
        // Second column is union['paypal_email']
        $row[] = $union['paypal_email'];
        if (!$export && (user_access('payment_edit') || user_access('payment_delete'))) {
            // Construct ops array
            $ops = array();
            // Add edit op
            // TODO
            // Add delete op
            if (user_access('payment_delete')) {
                $ops[] = '<a href=' . crm_url('delete&type=paypal_payment_contact&id=' . $contact['cid']) . '>delete</a>';
            }
            // Add ops row
            $row[] = join(' ', $ops);
        }
        // Save row array into the $table structure
        $table['rows'][] = $row;
    }
    return $table;
}
/**
 * Return a table structure for a table of service links.
 *
 * @param $opts The options to pass to service_data().
 * @return The table structure.
*/
function services_table($opts)
{
    // Determine settings
    $export = false;
    foreach ($opts as $option => $value) {
        switch ($option) {
            case 'export':
                $export = $value;
                break;
        }
    }
    // Get contact info
    $contacts = crm_get_one('contact', $opts);
    // Initialize table
    $table = array("id" => '', "class" => '', "rows" => array(), "columns" => array());
    // Add columns
    if (user_access('services_view') || $opts['cid'] == user_id()) {
        if ($export) {
            $table['columns'][] = array("title" => 'cid', 'class' => '', 'id' => '');
        }
        $table['columns'][] = array("title" => 'Service', 'class' => '', 'id' => '');
        $table['columns'][] = array("title" => 'ServiceID', 'class' => '', 'id' => '');
    }
    // Add ops column
    if (!$export && (user_access('services_edit') || user_access('services_delete') || $opts['cid'] == user_id())) {
        $table['columns'][] = array('title' => 'Ops', 'class' => '');
    }
    // Add rows
    // Slack info
    $row = array();
    $slackID = services_getSlackID($contacts['email']);
    if (user_access('services_view') || user_access('services_edit') || $opts['cid'] == user_id()) {
        // Add cells
        if ($export) {
            $row[] = $contacts['cid'];
        }
        $row[] = 'Slack';
        $row[] = $slackID;
        if (!$export && (user_access('services_edit') || user_access('services_delete')) || $opts['cid'] == user_id()) {
            // Construct ops array
            $ops = array();
            // Add edit op
            if (user_access('services_edit') || $opts['cid'] == user_id()) {
                $ops[] = '<form action="https://i3detroit.slack.com/api/users.admin.invite" method="post">
                 <input type="hidden" name="token" value=' . variable_get('slack_token', '') . '>
                 <input type="hidden" name="email" value="' . $contacts['email'] . '">
                 <input type="hidden" name="first_name" value="' . $contacts['firstName'] . '">
                 <input type="hidden" name="last_name" value="' . $contacts['lastName'] . '">
                 <input type="hidden" name="set_active" value="true">
                 <input type="submit" value="Invite">';
            }
            // There's no delete function in API yet, so can't show a delete button
            // Add ops row
            $row[] = join(' ', $ops);
        }
        $table['rows'][] = $row;
    }
    // End Slack
    // Wiki Account
    // End Wiki
    return $table;
}
Example #10
0
/**
 * Return the text of an email welcoming a new member.
 * @param $cid The contact id of the new member.
 * @param $confirm_url The url for the new user to confirm their email.
 */
function theme_member_welcome_email($cid, $confirm_url)
{
    $contact = crm_get_one('contact', array('cid' => $cid));
    $vars = array('type' => 'welcome', 'confirm_url' => $confirm_url, 'username' => $contact['user']['username']);
    return template_render('email', $vars);
}
Example #11
0
/**
 * Theme a contact's name.
 * 
 * @param $contact The contact data structure or cid.
 * @param $link True if the name should be a link (default: false).
 * @param $path The path that should be linked to.  The cid will always be added
 *   as a parameter.
 *
 * @return the name string.
 */
function theme_contact_name($contact, $link = false, $path = 'contact')
{
    if (!is_array($contact)) {
        $contact = crm_get_one('contact', array('cid' => $contact));
    }
    $first = $contact['firstName'];
    $middle = $contact['middleName'];
    $last = $contact['lastName'];
    $name = "{$last}, {$first}";
    if (!empty($middle)) {
        $name .= " {$middle}";
    }
    if ($link) {
        $url_opts = array('query' => array('cid' => $contact['cid']));
        $name = crm_link($name, $path, $url_opts);
    }
    return $name;
}