Esempio n. 1
0
function fillUserName(&$form, &$form_state)
{
    $UID = dbSearchUserByEmail($form_state['values']['primaryEmail']);
    // if this user isn't registered with CROMA, just ignore this call
    if ($UID == false) {
        return;
    }
    $userProfile = dbGetUserProfile($UID);
    if ($userProfile == false) {
        drupal_set_message('This user is invalid. Please inform this user to set up a profile.', 'error');
    } else {
        $firstName = $userProfile['firstName'];
        $lastName = $userProfile['lastName'];
        $form['fields']['name']['firstName']['#value'] = $firstName;
        $form['fields']['name']['lastName']['#value'] = $lastName;
    }
    $form['fields']['name']['firstName']['#attributes']['disabled'] = 'disabled';
    $form['fields']['name']['lastName']['#attributes']['disabled'] = 'disabled';
    $form_state['rebuild'] = TRUE;
    return $form['fields']['name'];
}
Esempio n. 2
0
function applyForTeamForm()
{
    global $user;
    $params = drupal_get_query_parameters();
    $profile = dbGetUserProfile($user->uid);
    if (isset($params['url'])) {
        $form['back'] = array('#markup' => "<a href=\"?q={$params['url']}\"><button type=\"button\">Cancel</button></a>");
    }
    $form['fields'] = array('#type' => 'fieldset', '#title' => t('Apply to Join a Team'));
    $form['fields']['tableHeader'] = array('#markup' => '<table>');
    $form['fields']['number'] = array('#prefix' => '<tr><td>', '#type' => 'textfield', '#title' => t('Team Number:'), '#suffix' => '</td><td>', '#ajax' => array('callback' => 'fillTeamName', 'keypress' => true, 'wrapper' => 'div_team_name_wrapper'));
    // this form will be filled in via AJAX
    $form['fields']['teamName'] = array('#prefix' => '<div id="div_team_name_wrapper">', '#type' => 'textfield', '#title' => t('Team Name:'), '#disabled' => true, '#suffix' => '</div>');
    // this form is filled in from previous data
    $form['fields']['personName'] = array('#prefix' => '</td></tr><tr><td>', '#type' => 'textfield', '#title' => t('Your Name:'), '#default_value' => "{$profile['firstName']} {$profile['lastName']}", '#disabled' => true, '#suffix' => '</td>');
    // user email is filled in, but still editable
    $form['fields']['email'] = array('#prefix' => '<td>', '#type' => 'textfield', '#title' => t('Your Email:'), '#default_value' => dbGetUserPrimaryEmail($user->uid), '#suffix' => '</td></tr>');
    $defaultMessage = "Hi, I'd like to join your team!";
    $form['fields']['message'] = array('#prefix' => '<tr><td colspan="2">', '#type' => 'textarea', '#title' => t('Personal Message:'), '#default_value' => $defaultMessage, '#suffix' => '</td></tr>');
    $form['fields']['submit'] = array('#prefix' => '<tr><td colspan="2" style="text-align:right">', '#type' => 'submit', '#value' => t('Submit'), '#suffix' => '</td></tr>');
    $form['fields']['tableFooter'] = array('#markup' => '</table>');
    return $form;
}
Esempio n. 3
0
function viewUsersForTeam($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    if (isset($params['TID'])) {
        $TID = $params['TID'];
    } else {
        $TID = getCurrentTeam()['TID'];
    }
    if (teamIsIneligible($TID) || !isMyTeam($TID)) {
        drupal_set_message('You do not have permission to access that page.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    $form_state['TID'] = $TID;
    $canManageTeamMembers = hasPermissionForTeam('manageTeamMembers', $TID);
    $canManageTeamOwners = hasPermissionForTeam('manageTeamOwners', $TID);
    $markup = '<table><tr><td colspan="3">';
    if (isset($params['query'])) {
        $persons = dbSearchUsersFromTeam($TID, $params['query']);
    } else {
        $type = isset($params['type']) ? $params['type'] : '';
        // filter by type (student vs mentor vs alumni)
        $persons = dbGetUsersFromTeam($TID, $type);
    }
    if (empty($persons)) {
        drupal_set_message('No users found.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    } else {
        if (isset($params['query'])) {
            $markup .= '<h1>Search Results (' . count($persons) . ' matches)</h1></td>';
        } else {
            $markup .= '<h1>' . count($persons) . ' users on Team ' . dbGetTeamNumber($TID) . '</h1></td>';
        }
    }
    // create page header, table, and pending users/view all button
    $markup .= '<td colspan="3" style="text-align:right">';
    if ($canManageTeamMembers) {
        if (!empty(dbGetUsersAwaitingApproval($TID))) {
            $markup .= '<a href="?q=viewUsersToBeApproved&TID=' . $TID;
            $markup .= '"><button type="button">View Pending Users</button></a>';
        } else {
            $markup .= '<button type="button" disabled>No Pending Users</button>';
        }
        $markup .= '<a href="?q=addTeamMember&TID=' . $TID;
        $markup .= '&destination=' . current_path();
        $markup .= '"><button type="button">Add User</button></a>';
    }
    if (isset($params['type'])) {
        $markup .= '<a href="?q=showUsersForTeam&TID=' . $TID;
        $markup .= '"><button type="button">View All</button></a>';
    }
    $markup .= '</td></tr></table>';
    // sets up the table to display name, role, and grade of every user on the certain team
    $markup .= '<table class="infoTable"><th>Name</th>';
    $markup .= '<th>Email</td></th>';
    $markup .= '<th>Team Role</td></th>';
    $markup .= '<th>CROMA Role</th>';
    // if user is an admin, they see a new column where they can change the role of other team members
    if ($canManageTeamMembers) {
        $markup .= '<th>Admin Functions</th>';
    } else {
        $markup .= '<th></th>';
    }
    $form['tableHeader'] = array('#markup' => $markup);
    $i = 0;
    foreach ($persons as $person) {
        $form_state["UID-{$i}"] = $person['UID'];
        $markup = '<tr><td><a href="?q=viewUser&UID=' . $person["UID"] . ' ">';
        // hyperlinks the name so every name is linked to its user profile
        $markup .= $person["firstName"] . " " . $person["lastName"] . '</a></td>';
        $form["name-{$i}"] = array('#markup' => $markup);
        $email = dbGetUserPrimaryEmail($person['UID']);
        $markup = "<td><a href=\"mailto:{$email}\" target=\"_top\">{$email}</a></td>";
        $form["email-{$i}"] = array('#markup' => $markup);
        $markup = '<td>' . ucfirst(dbGetUserProfile($person['UID'])['type']) . '</td>';
        $form["isStudent-{$i}"] = array('#markup' => $markup);
        $RID = dbGetRIDForTeam($person['UID'], $TID);
        $teamOwnerRID = dbGetRID('teamOwner');
        $personIsTeamOwner = $RID == $teamOwnerRID;
        // allow current user to change roles (but not change the role of the team owner)
        if ($canManageTeamMembers && !$personIsTeamOwner) {
            // if the person in question doesn't have a role
            if (!$RID) {
                $RID = 0;
            }
            $roles = dbGetAllRoles();
            $roles[0] = 'Team Member';
            // if current user can't create team owners
            if (!$canManageTeamOwners) {
                unset($roles[$teamOwnerRID]);
            }
            // make sure the roles are still in order
            ksort($roles);
            $form["RID-{$i}"] = array('#prefix' => '<td class="roleSelector">', '#type' => 'select', '#default_value' => $RID, '#options' => $roles, '#suffix' => '</td>', '#ajax' => array('event' => 'change', 'callback' => 'callback', 'wrapper' => 'confirm-div', 'method' => 'replace'));
        } else {
            // if the current user can't change the role
            if ($RID == 0) {
                $role = 'Member';
            } else {
                $role = dbGetRoleName($RID);
            }
            $form["role-{$i}"] = array('#prefix' => '<td>', '#markup' => $role, '#suffix' => '</td>');
        }
        // if the person in question is the current user
        if ($person['UID'] == $user->uid) {
            // if the person is the team owner -- transfer ownership
            if ($personIsTeamOwner) {
                $markup = "<td><a href=\"?q=transferTeamOwnership&TID={$TID}\">";
                $markup .= "<button type=\"button\">Transfer Ownership</button></a></td>";
            } else {
                // allow user to leave team
                $markup = "<td><a href=\"?q=leaveTeam/{$TID}\">";
                $markup .= "<button type=\"button\">Leave Team</button></a></td>";
            }
            // if the current user can remove users
        } else {
            if ($canManageTeamMembers && !$personIsTeamOwner) {
                $markup = "<td><a href=\"?q=kickUserFromTeam/{$person['UID']}/{$TID}\">";
                $markup .= "<button type=\"button\" onclick=\"if(!confirm('Are you sure you want to remove this user from your team?')){return false;}\">Kick User</button></a></td>";
            } else {
                // or just some random person
                $markup = '<td></td>';
            }
        }
        $form["adminFunctions-{$i}"] = array('#markup' => $markup);
        $form["rowFooter-{$i}"] = array('#markup' => '</tr>');
        $i++;
    }
    // end of foreach
    $form_state['numUsers'] = $i;
    $form['tableFooter'] = array('#markup' => '</table>');
    if ($canManageTeamMembers) {
        $form['buttons'] = array('#prefix' => '<div id="confirm-div" style="visibility:hidden">', '#suffix' => '</div>');
        $form['buttons']['confirm'] = array('#type' => 'submit', '#value' => 'Confirm');
    }
    return $form;
}
Esempio n. 4
0
function profileForm($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    $new = true;
    if (isset($params["UID"])) {
        // editing a user other than the current one
        $UID = $params['UID'];
    } else {
        // user is editing him/her own profile
        $UID = $user->uid;
    }
    $data = dbGetUserProfile($UID);
    if (empty($data)) {
        // if the UID passed did not have any user data associated with it
    } else {
        $new = false;
        // editing a user which already exists
    }
    // beginning the form
    $form = array();
    $form['fields'] = array('#type' => 'fieldset', '#title' => t('Edit: User Info'));
    $form['fields']['tableHeader'] = array('#markup' => '<table>');
    // checking permissions
    $canEdit = false;
    $sharedTeams = getSharedTeams($UID);
    if (!empty($sharedTeams)) {
        foreach ($sharedTeams as $TID) {
            if (hasPermissionForTeam('manageTeamMembers', $TID)) {
                $canEdit = true;
                break;
            }
        }
    }
    // if the user is viewing his/her own profile, he/she should be able to edit it
    if ($user->uid == $UID) {
        $canEdit = true;
    }
    if (!$canEdit) {
        drupal_set_message("You don't have permission to edit this user.", 'error');
        return;
    }
    if (!$new) {
        // if the profile is not new
        $form['fields']['back'] = array('#prefix' => '<left>', '#limit_validation_errors' => array(), '#submit' => array('backToProfile'), '#type' => 'submit', '#value' => '⇦ Cancel Changes', '#attributes' => array('OnSubmit' => 'if(!confirm("Back?")){return false;}'), '#suffix' => '</left>');
    }
    $form['fields']['firstName'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('First Name'), '#default_value' => $new ? '' : $data['firstName'], '#suffix' => '</td>');
    $form['fields']['lastName'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Last Name'), '#default_value' => $new ? '' : $data['lastName'], '#suffix' => '</td></tr>');
    $form['fields']['primaryEmail'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#markup' => "Primary Email <br>" . $user->mail, '#suffix' => '</td>');
    if (!$new) {
        $secondaryEmail = dbGetSecondaryEmailForUser($UID);
    }
    $form['fields']['secondaryEmail'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Secondary Email'), '#default_value' => $new ? '' : $secondaryEmail, '#suffix' => '</td></tr>');
    $form['fields']['gender'] = array('#prefix' => '<tr><td colspan="2" style="text-align:center">', '#type' => 'radios', '#options' => array('Male' => 'Male', 'Female' => 'Female', 'Other' => 'Other'), '#title' => t('Gender'), '#default_value' => $new ? '' : $data['gender'], '#suffix' => '</td>');
    $form['fields']['type'] = array('#prefix' => '<td colspan="2" style="text-align:center">', '#type' => 'radios', '#options' => array('student' => 'Student', 'mentor' => 'Mentor', 'alumni' => 'Alumni'), '#title' => t('Type'), '#default_value' => $new ? '' : $data['type'], '#suffix' => '</td>');
    $form['fields']['grade'] = array('#prefix' => '<td colspan="2" style="text-align:center">', '#type' => 'select', '#options' => array('1' => '1st', '2' => '2nd', '3' => '3rd', '4' => '4th', '5' => '5th', '6' => '6th', '7' => '7th', '8' => '8th', '9' => '9th', '10' => '10th', '11' => '11th', '12' => '12th', '0' => 'N/A'), '#title' => t('Grade'), '#default_value' => $new ? '' : $data['grade'], '#chosen' => true, '#suffix' => '</td></tr>');
    $form['fields']['phone'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Phone Number'), '#default_value' => $new ? '' : $data['phone'], '#placeholder' => 'Format: XXXXXXXXXX', '#suffix' => '</td>');
    $form['fields']['position'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Team Position'), '#default_value' => $new ? '' : $data['position'], '#placeholder' => "i.e. Chairman's Presenter", '#suffix' => '</td></tr>');
    $form['fields']['bio'] = array('#prefix' => '<tr><td colspan="6">', '#type' => 'textarea', '#title' => t('Short Bio'), '#default_value' => $new ? '' : $data['bio'], '#suffix' => '</td></tr>');
    // end of inputting info into the form
    $form['fields']['tabling'] = array('#markup' => '</td></tr><tr>');
    $form['fields']['tabling2'] = array('#markup' => '<td colspan="3"></td>');
    $form['fields']['submit'] = array('#prefix' => '<td colspan="3" style="text-align:right">', '#type' => 'submit', '#value' => t('Save'), '#suffix' => '</td>');
    $form['footer'] = array('#markup' => '</tr></table>');
    return $form;
}
Esempio n. 5
0
function viewMedia()
{
    global $user;
    if (dbGetTeamsForUser($user->uid) == false) {
        drupal_set_message("You don't have a team assigned.", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    $params = drupal_get_query_parameters();
    if (!isset($params['OID'])) {
        drupal_set_message('No outreach selected.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    $OID = $params['OID'];
    $markup = '';
    $outreachName = dbGetOutreachName($OID);
    // create header, table
    $markup .= "<table><tr><td><h1>Media for \"{$outreachName}\" </h1></td>";
    $markup .= '<td style="text-align:right">';
    // upload media button
    $markup .= "<a href=\"?q=uploadMedia&OID={$OID}\"><button>Upload Media</button></a></td></tr></table>";
    $media = dbGetMediaForOutreach($OID);
    // create table
    $markup .= '<table class="infoTable"><tr><th>Image</th><th>Name</th><th><Info</th><th>Uploaded By</th><th></th><th></th>';
    // if media for outreach is not empty
    if (!empty($media)) {
        // displays all media for the outreach
        foreach ($media as $m) {
            $url = generateURL($m['FID']);
            $MID = $m['MID'];
            $UIDofMID = dbGetUserForMedia($MID);
            $profile = dbGetUserProfile($UIDofMID);
            $markup .= '<tr><td><a href=' . $url . '><img src="' . $url . '" width="150px" height="150px"></a></td>';
            $markup .= '<td>' . $m['title'] . '</td>';
            $markup .= '<td>' . wordwrap(chopString($m['description'], 30), 15, "<br>\n", TRUE) . '</td>';
            $markup .= "<td>" . $profile['firstName'] . ' ' . $profile['lastName'] . "</td>";
            $markup .= "<td><a href=\"?q=mediaForm&MID={$MID}&OID={$OID}\"><button><img class=\"editIcon\" src=\"/images/icons/editThumbnailWhite.png\"></button></a></td>";
            // allow user to delete media if he/she was the one to upload it
            if (isMyMedia($MID)) {
                $markup .= "<td><a href=\"?q=removeMedia/{$MID}\"><button><img class=\"trashIcon\" src=\"/images/icons/trashWhite.png\"></button></a></td>";
            } else {
                $markup .= "<td></td>";
            }
        }
        $markup .= '</tr></table>';
    } else {
        // if there is no media assigned to the outreach
        $markup .= "<tr>";
        $markup .= '<td style="text-align:center" colspan="10"><em>[None]</em></td>';
        $markup .= "</tr>";
    }
    $markup .= "</table>";
    return array('#markup' => $markup);
}
Esempio n. 6
0
function viewUserProfileSummary()
{
    global $user;
    $params = drupal_get_query_parameters();
    if (isset($params["UID"])) {
        $UID = $params["UID"];
    } else {
        $UID = $user->uid;
    }
    $profile = dbGetUserProfile($UID);
    // create table, display user name
    $markup = '<table id="miniViewUser" style="margin:102px 0px 0px 0px"><tr><td colspan="6" style="text-align:center"><h2><b>' . $profile['firstName'] . ' ' . $profile['lastName'] . '</b></h2></td>';
    $markup .= '<tr><td colspan="6" style="text-align:center">';
    // display picture if user has one
    if (!empty($profile['FID'])) {
        $FID = $profile['FID'];
        $file = file_load($FID);
        $uri = $file->uri;
        $variables = array('style_name' => 'profile', 'path' => $uri, 'width' => '150', 'height' => '150');
        $image = theme_image_style($variables);
        $markup .= $image;
    } else {
        // default picture displayed
        $markup .= '<img src="/images/defaultPics/user.png">';
    }
    $markup .= '</td></tr><tr>';
    // my profile button to view full user profile
    $markup .= '<td colspan="3" style="text-align:left"><a href="?q=viewUser';
    $markup .= '&UID=' . $UID . '">';
    $markup .= '<div class="help tooltip4"><button type="button">My Profile</button>';
    // my teams button to manage teams for user
    $markup .= '<span id="helptext"; class="helptext tooltiptext4">';
    $markup .= 'Click here to view/edit your user profile and to manage your teams.';
    $markup .= '</span></div></a>';
    $markup .= '</td>';
    $markup .= '<td colspan="3" style="text-align:right"><a href= "?q=manageUserTeams">';
    $markup .= '<div class="help tooltip3"><button type="button">My Teams</button><span id="helptext"; class="helptext tooltiptext3">Click here to create, apply to, or leave a team.</span></div></a></td>';
    $markup .= '</tr></div></table>';
    return array('#markup' => $markup);
}
Esempio n. 7
0
function viewPeopleForEvent()
{
    global $user;
    $params = drupal_get_query_parameters();
    $TID = getCurrentTeam()['TID'];
    if (teamIsIneligible($TID)) {
        drupal_set_message('Your team does not have permission to access this page.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    if (dbGetTeamsForUser($user->uid) == NULL) {
        drupal_set_message("You don't have a team assigned.", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    if (isset($params['OID']) && $params['OID'] > 0) {
        $OID = $params['OID'];
        $outreach = dbGetOutreach($OID);
        // if the outreach is invalid
        if ($outreach == false) {
            drupal_set_message('Invalid outreach event. Click <a href="?q=teamDashboard">here</a> to navigate back to events in Team Dashboard.', 'error');
            return;
        }
        // begin header
        $markup = '<div align="left">' . "<br><h1><b> Users Signed Up For: {$outreach['name']}</b></h1></div>";
        $ppl = dbGetPplSignedUpForEvent($OID);
        if ($ppl == false) {
            $markup .= '<tr><td><h4>No people signed up for outreach: ' . $outreach['name'] . '</h4></td></tr>';
        } else {
            // Begin Displaying Info Body
            $markup .= '<table class="infoTable">';
            $markup .= '<tr><th>Name</th>';
            $markup .= '<th>Email</th>';
            $markup .= '<th>Time Slot(s)</th></tr>';
            foreach ($ppl as $UID) {
                $profile = dbGetUserProfile($UID);
                $markup .= '<tr><td><a href="?q=viewUser&UID=' . $profile["UID"] . ' ">';
                $markup .= $profile["firstName"] . " " . $profile["lastName"] . '</a></td>';
                // display the user's email
                $email = dbGetUserPrimaryEmail($UID);
                $markup .= "<td><a href=\"mailto:{$email}\" target=\"_top\">{$email}</a></td>";
                $timeSlots = dbGetUserSignUpType($UID, $OID);
                $markup .= '<td>';
                foreach ($timeSlots as $timeSlot) {
                    switch ($timeSlot) {
                        case 'prep':
                            $markup .= 'Preparation<br>';
                            break;
                        case 'atEvent':
                            $markup .= 'At Event<br>';
                            break;
                        case 'followUp':
                            $markup .= 'Follow Up<br>';
                            break;
                        case 'writeUp':
                            $markup .= 'Write Up<br>';
                            break;
                        case 'owner':
                            $markup .= 'Owner<br>';
                            break;
                        default:
                            break;
                    }
                }
                $markup .= '</td>';
            }
        }
        $markup .= '</table>';
        $retArray = array();
        $retArray['#markup'] = $markup;
        return $retArray;
    } else {
        drupal_set_message('Invalid outreach event. Click <a href="?q=teamDashboard">here</a> to navigate back to events in Team Dashboard.', 'error');
    }
}