Example #1
0
function applyForTeamForm_validate($form, &$form_state)
{
    $team = dbGetTeamByNumber($form_state['values']['number']);
    if (empty($team)) {
        form_set_error('teamName', 'Please select a valid team.');
    } else {
        if (isMyTeam($team['TID'])) {
            form_set_error('teamName', 'You are already on this team!');
        } else {
            $TID = $team['TID'];
            $form_state['TID'] = $TID;
        }
    }
}
Example #2
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;
}
Example #3
0
function viewTeam()
{
    global $user;
    $UID = $user->uid;
    $params = drupal_get_query_parameters();
    $array = array();
    // checks to see if the user has a team
    if (isset($params['TID'])) {
        $TID = $params['TID'];
    } else {
        drupal_set_message("No team selected.", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    // checks to see if the user is on the team (keeping in mind that team owners can
    // see their team application
    if (dbGetTeamOwner($TID) != $UID && (!isMyTeam($TID) || teamIsIneligible($TID))) {
        drupal_set_message('You do not have permission to access this page.', 'error');
        return;
    }
    $team = dbGetTeam($TID);
    $markup = '';
    $markup .= '<div style="float:left; width:38%">';
    // create team header and table
    $markup .= '<table style="margin:0px 0px 10px 0px;"><tr>';
    $markup .= '<td style="padding:0px 14px 10px 14px;"><div align="left"><h2 style="margin:0px 0px 7px 0px;"><b>';
    // if the team has a type
    if ($team['type'] != "Other") {
        $markup .= "{$team['type']} {$team['number']} - {$team['name']}";
    } else {
        $markup .= "Team {$team['number']} - {$team['name']}";
    }
    $markup .= '</b></h2></div></td></tr></table>';
    // create table
    $markup .= '<table id="photoAndEdit"><tr><td style="padding:0px;">';
    // if the user can edit team picture
    if (hasPermissionForTeam('editTeam', $TID)) {
        $markup .= '<div align="right">';
        $markup .= '<a href= "?q=editThumbnail';
        $markup .= '&TID=' . $TID . '&FID=' . $team['FID'] . '">';
        $markup .= '<span title="Edit Photo"><button><img class="editIcon" src="/images/icons/editThumbnailWhite.png"></button></span></a>';
        $markup .= '</div>';
    } else {
        // otherwise show just a disabled button
        $markup .= '<div align="right">';
        $markup .= '<span title="Edit Photo"><button type="button" disabled><img class="editIcon" src="/images/icons/editThumbnailWhite.png"></button></span>';
        $markup .= '</div>';
    }
    $markup .= '</td></tr><tr><td style="padding:0px;">';
    // if the team has a picture then display
    if (!empty($team['FID'])) {
        $url = generateURL($team['FID']);
        $markup .= '<div align="center"><img src="' . $url . '" style="max-width:150px; width:auto; height:auto; padding: 5px 0px 5px 0px">';
        // default team picture
    } else {
        $markup .= '<div align="center"><img src= "/images/defaultPics/team.png" style="max-width:200px; width:auto; height:auto; padding: 15px 0px 15px 0px">';
    }
    $markup .= '</div></td></tr></table></div>';
    $teams = dbGetTeamsForUser($UID);
    $markup .= '<div align="right">';
    // if the user can permission to manage outreach
    if (!teamIsIneligible($TID) && hasPermissionForTeam('manageOutreachTags', $TID)) {
        $markup .= '<a href="?q=teamModeratorPage">';
        $markup .= '<div class="help tooltip4">';
        $markup .= '<button>Moderators</button>';
        $markup .= '<span id="helptext"; class="helptext tooltiptext4">';
        $markup .= 'Click here to view ideas, write-ups, and hours awaiting approval.';
        $markup .= '</span></div></a>';
    } else {
        $markup .= '<div class="help tooltip4">';
        $markup .= '<button type="button" disabled>Moderators</button>';
        $markup .= '<span id="helptext"; class="helptext tooltiptext4">';
        $markup .= 'Click here to view ideas, write-ups, and hours awaiting approval.';
        $markup .= '</span></div>';
    }
    // if the user can manage the outreach settings (currently only tags)
    if (!teamIsIneligible($TID) && hasPermissionForTeam('manageOutreachTags', $TID)) {
        $markup .= '<a href="?q=teamOutreachSettings">';
        $markup .= '<button>Settings</button></a>';
    } else {
        $markup .= '<button type="button" disabled>Settings</button>';
    }
    // if the user has permission to manage hours
    if (!teamIsIneligible($TID) && hasPermissionForTeam('editAnyHours', $TID)) {
        $markup .= '<a href= "?q=offsetHours';
        $markup .= '&TID=' . $team['TID'] . '">';
        $markup .= '<div class="help tooltip4">';
        $markup .= '<button type="button"><img class="hoursIcon" src="/images/icons/clockWhite.png"></button>';
        $markup .= '<span id="helptext"; class="helptext tooltiptext4">';
        $markup .= 'Click here to enter old team hours from previous years.';
        $markup .= '</span></div></a>';
    } else {
        $markup .= '<div class="help tooltip4">';
        $markup .= '<button type="button" disabled><img class="hoursIcon" src="/images/icons/clockWhite.png"></button>';
        $markup .= '<span id="helptext"; class="helptext tooltiptext4">';
        $markup .= 'Click here to enter old team hours from previous years.';
        $markup .= '</span></div>';
    }
    // if the user can edit the team
    if (hasPermissionForTeam('editTeam', $TID)) {
        $markup .= '<a href= "?q=teamForm&url=viewTeam';
        $markup .= '&TID=' . $team['TID'] . '">';
        $markup .= '<button type="button"><img class="editIcon" src="/images/icons/editWhite.png"></button></a>';
    } else {
        $markup .= '<button type="button" disabled><img class="editIcon" src="/images/icons/editWhite.png"></button></a>';
    }
    // if the user can delete the team
    if (hasPermissionForTeam('deleteTeam', $TID)) {
        $markup .= '<a href= "?q=deleteTeamPage';
        $markup .= '&TID=' . $team['TID'] . '">';
        $markup .= '<button type="button"><img class="trashIcon" src="/images/icons/trashWhite.png"></button></a>';
    } else {
        $markup .= '<button type="button" disabled><img class="trashIcon" src="/images/icons/trashWhite.png"></button></a>';
    }
    $markup .= '</div>';
    // begin displaying info
    $markup .= '<div style="width:60%; float:right; padding-left:10px">';
    $teams = dbGetTeamsForUser($UID);
    $numOutreaches = dbGetNumOutreachForTeam($TID);
    // create table
    $markup .= '<table id="miniViewTeam" style="margin:16px 0px 0px 0px"><tr><td><b>';
    if ($numOutreaches != 0) {
        $markup .= '<a href="?q=outreach&allTeamOutreach">Outreaches: </a></b>';
    } else {
        $markup .= 'Outreaches: </b>';
    }
    $markup .= $numOutreaches . '</td>';
    $markup .= '<td><b>Total Number of Hours: </b>' . dbGetHoursForTeam($TID) . '</td></tr>';
    $markup .= '<tr><td><b><a href="?q=showUsersForTeam';
    $numStudents = dbGetNumStudentsForTeam($team['TID']);
    $numMentors = dbGetNumMentorsForTeam($team['TID']);
    $markup .= '&TID=' . $team['TID'] . '&type=student">Students: </a></b>' . dbGetNumStudentsForTeam($team['TID']) . '</td>';
    $markup .= '<td><b><a href="?q=showUsersForTeam';
    $markup .= '&TID=' . $team['TID'] . '&type=mentor">Mentors: </a></b>' . dbGetNumMentorsForTeam($team['TID']) . '</td></tr>';
    $markup .= '<tr><td><b>City: </b>' . $team['city'] . '</td>';
    $markup .= '<td><b>State: </b>' . $team['state'] . '</td></tr>';
    $markup .= '<tr><td><b>Country: </b>' . $team['country'] . '</td>';
    $markup .= '<td><b>Rookie Year: </b>' . $team['rookieYear'] . '</td></tr>';
    if ($team['rookieYear'] == NULL) {
        $team['rookieYear'] = '[none]';
    }
    $markup .= '</table></div>';
    return array('#markup' => $markup);
}
Example #4
0
function hoursForm($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    $new = isset($form_state['new']) ? $form_state['new'] : true;
    // checking that you are on a team
    if (dbGetTeamsForUser($user->uid) == NULL) {
        drupal_set_message("You don't have a team assigned.", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    if (isset($params['HID'])) {
        $new = false;
        // editing an existing hours record
        $form_state['new'] = $new;
        // update form_state to reflect this
    }
    // setting values...
    // creating a new record
    if ($new) {
        if (isset($form_state['OID'])) {
            $OID = $form_state['OID'];
        } else {
            $OID = $params['OID'];
            $form_state['OID'] = $OID;
        }
        $UID = $user->uid;
        // editing an existing hours record
    } else {
        if (isset($form_state['HID'])) {
            $HID = $form_state['HID'];
        } else {
            $HID = $params['HID'];
            $form_state['HID'] = $HID;
        }
        $hour = dbGetHour($HID);
        $UID = $hour['UID'];
        $OID = $hour['OID'];
        $form_state['OID'] = $OID;
        if ($hour['isApproved']) {
            drupal_set_message('Note that this hour will have to be re-approved once changes are made.', 'error');
        }
    }
    // checking that you are accessing this page with a valid outreach
    if (!isset($OID) && !isset($params['HID'])) {
        drupal_set_message("No outreach selected.", 'error');
        return;
    }
    // checking that you are associated with the team for which this outreach belongs to
    $TID = dbGetTeamForOutreach($OID);
    if (!isMyTeam($TID)) {
        $teamName = dbGetTeamName($TID);
        drupal_set_message("You are no longer on the team associated with this outreach ({$teamName}).", 'error');
        return;
    }
    // checks if you have permission to edit hours
    if (!(hasPermissionForTeam('editAnyHours', dbGetTeamForOutreach($OID)) || isMyOutreach($OID) || dbIsUserSignedUp($user->uid, $OID))) {
        drupal_set_message("You don't have permission to log hours for this outreach.", 'error');
        return;
    }
    if (isset($form_state['OID']) || isset($params['HID'])) {
        $outreachData = dbGetOutreach($OID);
        //begins form
        $form['fields'] = array('#prefix' => '<div id="rows-div">', '#type' => 'fieldset', '#title' => t("Enter Hours For Outreach: \"{$outreachData['name']}\""), '#suffix' => '</div>');
        $users = dbGetUsersListFromTeam($TID);
        $users['0'] = '[none]';
        if (hasPermissionForTeam('editAnyHours', $TID)) {
            $form['fields']['UID'] = array('#prefix' => '<td>', '#type' => 'select', '#title' => t('User:'******'#options' => $users, '#attributes' => array('style' => 'width:200px'), '#default_value' => $UID, '#chosen' => true, '#suffix' => '</td>');
        }
        $form['fields']['tableHeader'] = array('#markup' => '<table>');
        if (empty($form_state['numRows'])) {
            $form_state['numRows'] = 1;
        }
        if (!hasPermissionForTeam('editAnyHours', $TID)) {
            $signUpInfo = dbGetUserSignUpInfo($UID, $OID);
            $numSignUps = count($signUpInfo);
            $signUpCountLoop = 0;
            $type = array();
            foreach ($signUpInfo as $info) {
                if ($numSignUps > 1 && $signUpCountLoop != $numSignUps - 1 && $form_state['numRows'] != $numSignUps) {
                    $form_state['numRows']++;
                }
                if ($info['type'] == 'prep') {
                    $type[$signUpCountLoop] = array('prep' => 'Preparation');
                } else {
                    if ($info['type'] == 'atEvent') {
                        $type[$signUpCountLoop] = array('atEvent' => 'At Event');
                    } else {
                        if ($info['type'] == 'writeUp') {
                            $type[$signUpCountLoop] = array('writeUp' => 'Write-Up');
                        } else {
                            if ($info['type'] == 'followUp') {
                                $type[$signUpCountLoop] = array('followUp' => 'Follow Up');
                            } else {
                                if ($info['type'] == 'other') {
                                    $type[$signUpCountLoop] = array('prep' => 'Other');
                                }
                            }
                        }
                    }
                }
                $signUpCountLoop++;
            }
        }
        // looping through the rows
        for ($i = 0; $i < $form_state['numRows']; $i++) {
            $rowMarkUp = "<tr id=\"row-{$i}\"";
            $rowMarkUp .= '>';
            $form['fields']["rowHeader-{$i}"] = array('#markup' => $rowMarkUp);
            $form['fields']["numberOfHours-{$i}"] = array('#prefix' => '<td  colspan="1" style="text-align:left;width:20%;">', '#type' => 'textfield', '#title' => t('Number Of Hours:'), '#suffix' => '</td>', '#default_value' => $new ? '' : $hour['numberOfHours']);
            if (hasPermissionForTeam('editAnyHours', $TID)) {
                $types = array('prep' => 'Preparation', 'atEvent' => 'At Event', 'writeUp' => 'Write-Up', 'followUp' => 'Follow Up', 'other' => 'Other');
            } else {
                $types = $type[$i];
            }
            $form['fields']["type-{$i}"] = array('#prefix' => '<td colspan="1" style="text-align:left; width:20%;">', '#type' => 'radios', '#title' => t('Type:'), '#options' => $types, '#suffix' => '</td>', '#default_value' => $new ? '' : $hour['type']);
            $form['fields']["description-{$i}"] = array('#prefix' => '<td colspan="3" style="text-align:left; width:50%;">', '#type' => 'textarea', '#title' => t('Description:'), '#suffix' => '</td>', '#default_value' => $new ? '' : $hour['description']);
            if ($i == $form_state['numRows'] - 1) {
                $form['fields']["addRowButton-{$i}"] = array('#prefix' => '<td colspan="1" style="width:5%">', '#type' => 'submit', '#submit' => array('addHourRow'), '#value' => '+', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyHourRows_callback', 'wrapper' => 'rows-div'), '#suffix' => '</td>');
                $form['fields']["removeRowButton-{$i}"] = array('#prefix' => '<td colspan="1" style="width:5%">', '#type' => 'submit', '#submit' => array('removeHourRow'), '#value' => '-', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyHourRows_callback', 'wrapper' => 'rows-div'), '#suffix' => '</td>');
            }
            $form['fields']['rowFooter'] = array('#markup' => '</tr>');
            // end of for loop
        }
        $form['fields']['submit'] = array('#prefix' => '<tr><td colspan="7" style="text-align:right">', '#type' => 'submit', '#value' => t('Submit'), '#suffix' => '</td></tr>');
        $form['fields']['tableFooter'] = array('#markup' => '</table>');
    }
    return $form;
}
Example #5
0
function viewOutreachEvent()
{
    global $user;
    $UID = $user->uid;
    $params = drupal_get_query_parameters();
    if (isset($params['OID']) && $params['OID'] > 0) {
        $OID = $params['OID'];
        $outreach = dbGetOutreach($OID);
        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;
        }
        $TID = $outreach['TID'];
        if (!isMyTeam($TID)) {
            drupal_set_message('You do not have permission to access this page.', 'error');
            return;
        }
        // if the outreach status is outreach and the event is over, then turn the status to write up
        if ($outreach['status'] == "isOutreach") {
            outreachToWriteUp($OID);
        }
        // determine if the user can physically sign up
        $canSignUp = !dbIsOutreachOver($OID) && ($outreach['status'] == 'isOutreach' || $outreach['status'] == 'doingWriteUp');
        $markup = '';
        $markup .= '<div style="float:left; width:38%">';
        $markup .= '<table style="margin:0px 0px 10px 0px;"><tr>';
        $markup .= '<td style="padding:0px 14px 10px 14px;"><div align="left"><h2 style="margin:0px 0px 7px 0px;"><b>';
        // display outreach name
        $markup .= "{$outreach['name']}";
        $markup .= '</b></h2></div></td></tr>';
        $markup .= '<tr><td>';
        $markup .= showOutreachStatusIcon($outreach['status']);
        // displays the icon for a public outreach
        $markup .= $outreach['isPublic'] ? '<span title="Public"><img class="eventPrivacyIcon" src="/images/icons/publicBlue.png"></span>' : '<span title="Private"><img class="eventPrivacyIcon" src="/images/icons/privateBlue.png"></span>';
        // displays the icon for a cancelled outreach
        $markup .= $outreach['cancelled'] ? '<span title="Event Cancelled"><img class="eventCancelledIcon" src="/images/icons/cancelledRed.png"' : '';
        $markup .= '</td></tr></table>';
        $markup .= '<table id="photoAndEdit"><tr><td style="padding:0px;">';
        // cannot edit photo if user doesn't have the correct permissions
        if (!isMyOutreach($OID) && !hasPermissionForTeam('editAnyOutreach', getCurrentTeam()['TID'])) {
            $markup .= '<div align="right">';
            $markup .= '<span title="Edit Photo"><button type="button" disabled><img class="editIcon" src="/images/icons/editThumbnailWhite.png"></button></span>';
            $markup .= '</div>';
        } else {
            // edit photo if user has permissions
            $markup .= '<div align="right">';
            $markup .= '<a href= "?q=editThumbnail';
            $markup .= '&OID=' . $OID . '&FID=' . $outreach['FID'] . '">';
            $markup .= '<span title="Edit Photo"><button type="button"><img class="editIcon" src="/images/icons/editThumbnailWhite.png"></button></a></span>';
            $markup .= '</div>';
        }
        $markup .= '</td></tr><tr><td style="padding:0px;">';
        // default picture for outreach
        if (!empty($outreach['FID'])) {
            $FID = dbGetOutreachThumbnail($OID);
            $url = generateURL($FID);
            $markup .= '<div align="center"><img src="' . $url . '" style="max-width:150px; width:auto; height:auto; padding: 5px 0px 5px 0px">';
        } else {
            $markup .= '<div align="center"><img src="/images/defaultPics/team.png" style="max-width:200px; width:auto; height:auto; padding: 15px 0px 15px 0px">';
        }
        $markup .= '</div></td></tr></table></div>';
        $markup .= '<div align="right">';
        // if the status is write-up, then allow a user to submit a write up
        if ($outreach['status'] == 'doingWriteUp' && !$outreach['isWriteUpSubmitted']) {
            $markup .= '<a href="?q=writeupform&OID=' . $outreach['OID'] . '"><button>Write Up</button></a>';
        } else {
            if ($outreach['isWriteUpSubmitted'] && hasPermissionForTeam('approveIdeas', $TID) && $outreach['status'] == 'doingWriteUp') {
                $markup .= '<a href="?q=writeupform&OID=' . $outreach['OID'] . '&approving"><button>Approve Write Up</button></a>';
            }
        }
        // if the status is idea, then allow a user with permissions to approve or reject the idea
        if ($outreach['status'] == 'isIdea' && hasPermissionForTeam('approveIdeas', $TID)) {
            $markup .= '<a href="?q=approveIdea/' . $outreach['OID'] . '/' . $TID . '"><button>Approve</button></a>';
            $markup .= '<a href="?q=rejectIdea/' . $outreach['OID'] . '/' . $TID . '"><button>Reject</button></a>';
        }
        // notifications button
        if (!isMyOutreach($OID) && !hasPermissionForTeam('editAnyOutreach', getCurrentTeam()['TID'])) {
            $markup .= '<button type="button" disabled>Notifications</button>';
        } else {
            $markup .= '<a href="?q=manageNotifications&OID=' . $outreach['OID'] . '"><button>Notifications</button></a>';
        }
        // manage sign-ups button
        if (!dbIsOutreachCancelled($OID)) {
            if (dbIsUserSignedUp($UID, $OID)) {
                if (dbIsOutreachOver($OID)) {
                    $markup .= '<a href="?q=signUp&OID=' . $OID . '"><div class="help tooltip4"><button type="button" disabled>Edit Sign Up</button><span id="helptext"; class="helptext tooltiptext4">You cannot edit your sign up for this event because it is already over.</span></div></a>';
                } else {
                    $markup .= '<a href="?q=signUp&OID=' . $OID . '"><div class="help tooltip4"><button type="button">Edit Sign Up</button><span id="helptext"; class="helptext tooltiptext4">Click here to edit your sign up for this event.</span></div></a>';
                }
            } else {
                if (dbIsOutreachOver($OID) || $outreach['status'] == 'isIdea') {
                    $markup .= '<a href="?q=signUp&OID=' . $OID . '"><div class="help tooltip4"><button type="button" disabled>Sign Up</button><span id="helptext"; class="helptext tooltiptext4">You cannot sign up for this event because it is already over.</span></div></a>';
                } else {
                    $markup .= '<a href="?q=signUp&OID=' . $OID . '"><div class="help tooltip4"><button type="button">Sign Up</button><span id="helptext"; class="helptext tooltiptext4">Click here to sign up for this event.</span></div></a>';
                }
            }
        } else {
            $markup .= '<a href="?q=signUp&OID=' . $OID . '"><div class="help tooltip4"><button type="button" disabled>Sign Up</button><span id="helptext"; class="helptext tooltiptext4">You cannot sign up for this event because it is cancelled.</span></div></a>';
        }
        // hours button
        if (!dbIsOutreachCancelled($OID)) {
            $markup .= '<a href= "?q=viewHours';
            $markup .= '&OID=' . $OID . '">';
            $markup .= '<button type="button" ';
            $markup .= $outreach['status'] == 'isIdea' ? ' disabled' : '';
            $markup .= '>Hours</button></a>';
        } else {
            // if outreach is cancelled
            $markup .= '<button type="button" disabled';
            $markup .= $outreach['status'] == 'isIdea' ? ' disabled' : '';
            $markup .= '>Hours</button>';
        }
        // view media button
        $markup .= '<a href="?q=viewMedia';
        $markup .= '&OID=' . $OID . '">';
        $markup .= '<button type="button"';
        $markup .= $outreach['status'] == 'isIdea' ? ' disabled' : '';
        $markup .= '>Media</button></a>';
        // edit outreach button
        if (!isMyOutreach($OID) && !hasPermissionForTeam('editAnyOutreach', getCurrentTeam()['TID'])) {
            $markup .= '<button type="button" disabled><img class="editIcon" src="/images/icons/editWhite.png"></button>';
        } else {
            $markup .= '<a href= "?q=outreachForm';
            $markup .= '&OID=' . $OID . '">';
            $markup .= '<button type="button"><img class="editIcon" src="/images/icons/editWhite.png"></button></a>';
        }
        $markup .= '</div>';
        $markup .= '<div style="width:60%; float:right; padding-left:10px">';
        $hasPointOfContact = false;
        if (!(empty($outreach['co_organization']) && empty($outreach['co_firstName']) && empty($outreach['co_email']) && empty($outreach['co_phoneNumber']))) {
            $hasPointOfContact = true;
        }
        // account for cases where no info is present
        if ($outreach['description'] == null) {
            $outreach['description'] = '[none]';
        }
        if ($outreach['type'] == null || $outreach['type'] == '') {
            $outreach['type'] = '[none]';
        }
        if ($outreach['status'] == null) {
            $outreach['status'] = '[none]';
        }
        if ($outreach['co_organization'] == null) {
            $outreach['co_organization'] = '[none]';
        }
        if ($outreach['co_position'] == null) {
            $outreach['co_position'] = '[none]';
        }
        if ($outreach['co_firstName'] == null) {
            $outreach['co_firstName'] = '[none]';
        }
        if ($outreach['co_email'] == null) {
            $outreach['co_email'] = '[none]';
        }
        if ($outreach['co_phoneNumber'] == null) {
            $outreach['co_phoneNumber'] = '[none]';
        }
        if ($outreach['city'] == null) {
            $outreach['city'] = '[none]';
        }
        if ($outreach['state'] == null) {
            $outreach['state'] = '[none]';
        }
        if ($outreach['address'] == null) {
            $outreach['address'] = '[none]';
        }
        if ($outreach['country'] == null) {
            $outreach['country'] = '[none]';
        }
        if ($outreach['totalAttendance'] == null) {
            $outreach['totalAttendance'] = 0;
        }
        if ($outreach['testimonial'] == null) {
            $outreach['testimonial'] = '[none]';
        }
        $team = dbGetTeam($outreach['TID']);
        // begin displaying info body
        $markup .= '<table id="miniViewTeam" style="margin:16px 0px 0px 0px"><tr><td><h3><b><u>General<u></b></h3></td></tr>';
        $owner = dbGetOutreachOwner($OID);
        $markup .= "<tr><td colspan='3'><b>Owner: </b>" . dbGetUserName($owner) . "</a></td>";
        $markup .= "<td colspan='3'><b>Team: </b>{$team['number']}</td></tr>";
        $markup .= '<tr><td colspan="3"><b>Tags: </b>';
        $tags = dbGetTagsForOutreach($OID);
        if (!empty($tags)) {
            dpm($tags);
            $first = true;
            $length = count($tags);
            $i = 1;
            foreach ($tags as $OTID => $tagName) {
                $markup .= '<a href="?q=outreach&tag=' . $OTID . '">' . $tagName . '</a>';
                if ($i < $length) {
                    $markup .= ', ';
                }
                $i++;
            }
            // if there aren't any tags
        } else {
            $markup .= '[none]';
        }
        $markup .= '</td></tr>';
        $times = dbGetTimesForOutreach($OID);
        // display time if the outreach status isn't an idea
        if ($outreach['status'] != 'isIdea') {
            if (!empty($times)) {
                foreach ($times as $time) {
                    $startTime = date(TIME_FORMAT, dbDateSQL2PHP($time['startTime']));
                    $endTime = date(TIME_FORMAT, dbDateSQL2PHP($time['endTime']));
                    $markup .= '<tr><td colspan="3"><b>Start Date: </b>' . $startTime . '</td>';
                    $markup .= '<td colspan="3"><b>End Date: </b>' . $endTime . '</td></tr>';
                }
            }
        }
        $markup .= '<tr><td colspan="5" style="word-break:break-word"><b>Description: </b>';
        $markup .= wordwrap($outreach['description'], 70, "<br />\n");
        $markup .= '</td></tr>';
        // if the outreach has contact information
        if ($hasPointOfContact) {
            $markup .= '<tr><td><h3><b><u>Contact Info<u></b></h3></td></tr>';
            $markup .= '<tr><td colspan="3"><b>Host Organization: </b>';
            $markup .= strip_tags($outreach['co_organization'], ALLOWED_TAGS) . '</td>';
            $markup .= '<td colspan="3"><b>Contact Name: </b>';
            $markup .= strip_tags($outreach['co_firstName'] . ' ' . $outreach['co_lastName'], ALLOWED_TAGS) . '</td></tr>';
            $markup .= '<tr><td colspan="3"><b>Contact Email: </b>' . strip_tags($outreach['co_email'], ALLOWED_TAGS) . '</td>';
            $phoneNumber = dbFormatPhoneNumber($outreach['co_phoneNumber']);
            $markup .= '<td colspan="3"><b>Contact Number: </b>' . $phoneNumber . '</td></tr>';
            $markup .= '<tr><td colspan="6"><b>Address: </b>' . strip_tags($outreach['address'], ALLOWED_TAGS) . ', ' . strip_tags($outreach['city'], ALLOWED_TAGS) . ', ' . strip_tags($outreach['state'], ALLOWED_TAGS) . '</td></tr>';
            $markup .= '</tr>';
        } else {
            $markup .= '<tr><td><h3><b><u>Contact Info<u></b></h3></td></tr>';
            $markup .= '<tr><td colspan="6"><b>Address: </b>' . strip_tags($outreach['address'], ALLOWED_TAGS) . ', ' . strip_tags($outreach['city'], ALLOWED_TAGS) . ', ' . strip_tags($outreach['state'], ALLOWED_TAGS) . '</td></tr>';
            $markup .= '</tr>';
        }
        $markup .= '<tr><td><h3><b><u>Statistics<u></b></h3></td></tr>';
        $markup .= '<tr>';
        if ($outreach['status'] != 'isIdea') {
            $numPpl = dbGetNumPplSignedUpForEvent($OID);
            $markup .= '<td colspan="3"><b>';
            // only show the link if people are signed up
            if ($numPpl != 0) {
                $markup .= '<a href="?q=outreachList&OID=' . $OID . '"target="_blank">';
            }
            $markup .= 'People Signed Up: </b>';
            // end the link
            if ($numPpl != 0) {
                $markup .= '</a>';
            }
            $markup .= $numPpl . '</td>';
            // view total hours for the outreach
            $markup .= '<td colspan="3"><b>Total Hours: </b><a href="?q=viewHours&OID=' . $OID . '">' . dbGetHoursForOutreach($OID) . '</a></td></tr>';
            //if the outreach status is idea
        } else {
            $markup .= '<td colspan="3">';
            $markup .= '<b>People Signed Up: </b>';
            $markup .= 'None';
            $markup .= '</td></tr>';
        }
        $markup .= '</table></div>';
        // if the outreach has an approved write-up
        if ($outreach['isWriteUpApproved'] && $outreach['status'] == 'locked') {
            $writeUp = empty($outreach["writeUp"]) ? '[None]' : $outreach["writeUp"];
            $totalAttendance = empty($outreach["totalAttendance"]) ? '[Not Filled Out]' : $outreach["totalAttendance"];
            $testimonial = empty($outreach["testimonial"]) ? '[None]' : $outreach["testimonial"];
            $markup .= '<div style="float:left; width:38%;"><table id="miniViewTeam" style="margin:16px 0px 0px 0px"><tr><td><h3><b><u>Write Up<u></b></h3></td>';
            $markup .= '<td><a href="?q=writeupform&OID=' . $outreach['OID'] . '&approved"><button> View</button></a></td></tr>';
            $markup .= '<tr><td><b>Write Up:</b></td></tr>';
            $markup .= '<tr><td>' . $writeUp . '</td></tr>';
            $markup .= '<tr><td><b>Total Attendance:</b></td></tr>';
            $markup .= '<tr><td>' . $totalAttendance . '</td></tr>';
            $markup .= '<tr><td><b>Testimonials/Comments:</b></td></tr>';
            $markup .= '<tr><td>' . $testimonial . '</td></tr>';
            $markup .= '</table></div>';
        }
        $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');
    }
}
Example #6
0
function oldHoursForm($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    // initialization of values
    if (!isset($form_state['TID'])) {
        // first time on form
        $TID = $form_state['TID'] = $params['TID'];
        // set to url params
        $offset = dbGetOffsetHours($TID);
        if ($offset != null) {
            $new = $form_state['new'] = false;
            $form_state['numRows'] = count($offset);
            $form_state['initialNumTimes'] = count($offset);
            // record how many were there before (in case user deletes one)
        } else {
            $new = $form_state['new'] = true;
        }
    } else {
        // not first time on form
        $TID = $form_state['TID'];
        $offset = dbGetOffsetHours($TID);
    }
    // checking that user is on a team
    if (dbGetTeamsForUser($user->uid) == false) {
        drupal_set_message("You don't have a team assigned.", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    // checking that you are accessing this page with a team in mind
    if (!isset($TID)) {
        // if $TID is still null
        drupal_set_message("No team selected.", 'error');
        return;
    }
    // checking to make sure you have permission to actually edit the offset hours
    if (!isMyTeam($TID) || !hasPermissionForTeam('editTeam', $TID)) {
        drupal_set_message("You don't have permission to edit the 'old hours' for this team.", 'error');
        return;
    }
    // beginning the form itself
    $form['fields'] = array('#prefix' => '<div id="oldHourRows-div">', '#type' => 'fieldset', '#title' => t('Enter Old Hours For Team: ' . dbGetTeamName($TID)), '#suffix' => '</div>');
    if (!$new) {
        // if user wants to cancel any changes they made
        $form['fields']['back'] = array('#prefix' => '<left>', '#limit_validation_errors' => array(), '#submit' => array('backToTeam'), '#type' => 'submit', '#value' => '⇦ Cancel Changes', '#attributes' => array('OnSubmit' => 'if(!confirm("Back?")){return false;}'), '#suffix' => '</left>');
    }
    $form['fields']['tableHeader'] = array('#markup' => '<table>');
    if (empty($form_state['numRows'])) {
        $form_state['numRows'] = 1;
    }
    for ($i = 0; $i < $form_state['numRows']; $i++) {
        $rowMarkUp = "<tr id=\"row-{$i}\"";
        $rowMarkUp .= '>';
        $form['fields']["rowHeader-{$i}"] = array('#markup' => $rowMarkUp);
        $form['fields']["hours-{$i}"] = array('#prefix' => '<td style="text-align:left;">', '#type' => 'textfield', '#title' => t('Number Of Hours:'), '#suffix' => '</td>', '#default_value' => $new ? '' : $offset[$i]['numberOfHours']);
        if (!$new) {
            $form_state['fields']["HTID-{$i}"] = $offset[$i]['HTID'];
        }
        $form['fields']["year-{$i}"] = array('#prefix' => '<td style="text-align:left;">', '#type' => 'textfield', '#title' => t('Year:'), '#suffix' => '</td>', '#default_value' => $new ? '' : $offset[$i]['year']);
        if ($i == $form_state['numRows'] - 1) {
            $form['fields']["addRowButton-{$i}"] = array('#prefix' => '<td>', '#type' => 'submit', '#submit' => array('addOldHourRow'), '#value' => '+', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyOldHourRows_callback', 'wrapper' => 'oldHourRows-div'), '#suffix' => '</td>');
        }
        if ($i == $form_state['numRows'] - 1) {
            $form['fields']["removeRowButton-{$i}"] = array('#prefix' => '<td>', '#type' => 'submit', '#submit' => array('removeOldHourRow'), '#value' => '-', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyOldHourRows_callback', 'wrapper' => 'oldHourRows-div'), '#suffix' => '</td>');
        }
        $form['fields']['rowFooter'] = array('#markup' => '</tr>');
    }
    // end of for loop
    $form['fields']['submit'] = array('#prefix' => '<tr><td colspan="4" style="text-align:right">', '#type' => 'submit', '#value' => t('Submit'), '#suffix' => '</td></tr>');
    $form['fields']['tableFooter'] = array('#markup' => '</table>');
    return $form;
}