function transferTeamOwnershipForm($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    if (isset($params['TID'])) {
        $form_state['TID'] = $TID = $params['TID'];
    } else {
        drupal_set_message('You need to choose a team.', 'error');
        drupal_goto('showUsersForTeam');
    }
    $team = dbGetTeam($TID);
    if ($user->uid != $team['UID']) {
        // if the user is not the team owner
        drupal_set_message("You are not the owner of team {$team['name']}", 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    $people = dbGetUsersListFromTeam($TID);
    unset($people[$user->uid]);
    // shouldn't be able to transfer to self
    $people[0] = '';
    // field needs a default value
    $form['header'] = array('#markup' => "<h1>Transfer Ownership of {$team['name']}</h1>");
    $form['fields'] = array('#type' => 'fieldset');
    $form['fields']['table'] = array('#prefix' => '<table><tr>', '#suffix' => '</tr></table>');
    $form['fields']['table']['info'] = array('#prefix' => '<td>', '#markup' => 'Transferring ownership of this team will make you into a team admin (at which point you may leave the team if you wish). The new owner you choose will be notified of their promotion via email, and will gain the <strong>ability to delete the team at will</strong>. His/her notification email will also include your email for contact purposes in case of an error. If you wish to become the team owner again, the new owner must transfer ownership.', '#suffix' => '</td>');
    $form['fields']['table']['newOwner'] = array('#prefix' => '<td>', '#type' => 'select', '#title' => t('New Team Owner:'), '#default_value' => 0, '#options' => $people, '#chosen' => true, '#suffix' => '</td>');
    $form['submit'] = array('#prefix' => '<div align="right">', '#attributes' => array('onclick' => 'return confirm("Are you sure you want to transfer ownership?");'), '#type' => 'submit', '#value' => 'Submit', '#suffix' => '</div>');
    return $form;
}
Exemple #2
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;
}
Exemple #3
0
function searchFormSidebar($form, &$form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    $form_state['TID'] = getCurrentTeam()['TID'];
    if (isset($_SESSION['showAdvanced'])) {
        $form_state['showAdvanced'] = $_SESSION['showAdvanced'];
    } else {
        $form_state['showAdvanced'] = $_SESSION['showAdvanced'] = true;
    }
    // where the current instance of the form is located (e.g. allTeamOutreach)
    $form['fields']['source'] = array('#type' => 'hidden', '#value' => isset($params['source']) ? $params['source'] : '');
    $form['fields']['markupOne'] = array('#markup' => '<div id="searchFormOnSidebar" style="padding:24px 0px 0px 0px"><h2>Search All Outreach</h2>');
    $form['fields']['nameHeader'] = array('#markup' => '<table><tr><td style="padding:0px 5px 0px 0px"><b>Name:</b></td><td style="padding:0px">');
    $form['fields']['name'] = array('#type' => 'textfield', '#default_value' => fillFromSession('name', array()));
    $form['fields']['nameFooter'] = array('#markup' => '</td></tr></table>');
    $form['fields']['statusHeader'] = array();
    $form['fields']['status'] = array('#type' => 'checkboxes', '#prefix' => '<table><tr><td style="vertical-align:top">', '#title' => '<b>Status:</b>', '#options' => array('isIdea' => 'Idea', 'isOutreach' => 'Outreach', 'doingWriteUp' => 'Write-Up', 'locked' => 'Locked'), '#default_value' => fillFromSession('status', array()), '#suffix' => '</td>');
    $teams = dbGetTeamsForUser($user->uid);
    // if user is on multiple teams, allow him to select teams for searching
    if (!empty($teams)) {
        $teamOptions = array();
        foreach ($teams as $team) {
            $teamOptions[$team['TID']] = $team['number'];
        }
        $defaultTeam = array(getCurrentTeam()['TID']);
        $form['fields']['teams'] = array('#prefix' => '<td style="vertical-align:top">', '#type' => 'checkboxes', '#title' => '<b>Team:</b>', '#options' => $teamOptions, '#default_value' => fillFromSession('teams', $defaultTeam), '#suffix' => '</td></tr></table>');
    }
    $form['fields']['typeBttn'] = array('#type' => 'submit', '#submit' => array('toggleShowTypeSection'), '#value' => 'Type', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'showTypeSection_callback', 'wrapper' => 'type-div'));
    $form['fields']['type'] = array('#prefix' => '<div id="type-div">', '#suffix' => '</div>');
    // merge various data from all the teams of the given user
    $userTIDs = dbGetTIDsforUser($user->uid);
    $tags = array();
    $allUsers = array();
    foreach ($userTIDs as $TID) {
        $teamTags = dbGetOutreachTagsForTeam($TID);
        $users = dbGetUsersListFromTeam($TID);
        if (!empty($teamTags)) {
            $tags = array_replace($tags, $teamTags);
        }
        if (!empty($users)) {
            $allUsers = array_replace($users, $allUsers);
        }
    }
    // toggle display of the "Type" section
    if (isset($_SESSION['showTypeSection']) && $_SESSION['showTypeSection']) {
        if (!empty($tags)) {
            $form['fields']['type']['tags'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Tags:'), '#attributes' => array('style' => 'width:200px'), '#chosen' => true, '#multiple' => true, '#options' => $tags, '#default_value' => fillFromSession('tags', array()), '#suffix' => '</td>');
        }
        $form['fields']['type']['cancelled'] = array('#type' => 'checkbox', '#title' => t("Cancelled"), '#default_value' => fillFromSession('cancelled'));
    }
    $form['fields']['peopleBttn'] = array('#type' => 'submit', '#submit' => array('toggleShowPeopleSection'), '#value' => 'People', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'showPeopleSection_callback', 'wrapper' => 'people-div'));
    $form['fields']['people'] = array('#prefix' => '<div id="people-div">', '#suffix' => '</div>');
    if (isset($_SESSION['showPeopleSection']) && $_SESSION['showPeopleSection']) {
        $form['fields']['people']['ownerLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>Owner:</b>', '#suffix' => '</td>');
        $form['fields']['people']['owner'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'select', '#options' => $allUsers, '#default_value' => fillFromSession('owner'), '#attributes' => array('style' => 'width:200px'), '#chosen' => true, '#multiple' => true, '#suffix' => '</td></tr></table>');
        $form['fields']['people']['signedUpLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>Signed Up:</b>', '#suffix' => '</td>');
        $form['fields']['people']['signedUp'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'select', '#options' => $allUsers, '#default_value' => fillFromSession('signedUp'), '#attributes' => array('style' => 'width:200px'), '#chosen' => true, '#multiple' => true, '#suffix' => '</td></tr></table>');
        $form['fields']['people']['co_organizationLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>Organization:</b>', '#suffix' => '</td>');
        $form['fields']['people']['co_organization'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'textfield', '#default_value' => fillFromSession('co_organization'), '#size' => 20, '#suffix' => '</td></tr></table>');
    }
    $form['fields']['locationBttn'] = array('#type' => 'submit', '#submit' => array('toggleShowLocationSection'), '#value' => 'Location', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'showLocationSection_callback', 'wrapper' => 'location-div'));
    $form['fields']['location'] = array('#prefix' => '<div id="location-div">', '#suffix' => '</div>');
    if (isset($_SESSION['showLocationSection']) && $_SESSION['showLocationSection']) {
        $form['fields']['location']['cityLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>City:</b>', '#suffix' => '</td>');
        $form['fields']['location']['city'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'textfield', '#size' => 25, '#default_value' => fillFromSession('city'), '#suffix' => '</td></tr></table>');
        $form['fields']['location']['stateLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>State:</b>', '#suffix' => '</td>');
        $form['fields']['location']['state'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'select', '#options' => states_list(), '#default_value' => fillFromSession('state'), '#chosen' => true, '#suffix' => '</td></tr></table>');
        $form['fields']['location']['countryLabel'] = array('#prefix' => '<table style="margin:0px"><tr><td style="padding:0px">', '#markup' => '<b>Country:</b>', '#suffix' => '</td>');
        $form['fields']['location']['country'] = array('#prefix' => '<td style="padding:0px">', '#type' => 'select', '#options' => countries_list(), '#default_value' => fillFromSession('country'), '#attributes' => array('width' => '200px'), '#chosen' => true, '#suffix' => '</td></tr></table>');
    }
    // if user would like to see advanced fields, show them
    //  if (isset($form_state['showAdvanced']) && $form_state['showAdvanced']){
    //  if (isset($_SESSION['showAdvanced']) && $_SESSION['showAdvanced']){
    $form['fields']['timeBttn'] = array('#type' => 'submit', '#submit' => array('toggleShowTimeSection'), '#value' => 'Time', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'showTimeSection_callback', 'wrapper' => 'time-div'));
    $form['fields']['time'] = array('#prefix' => '<div id="time-div">', '#suffix' => '</div>');
    if (isset($_SESSION['showTimeSection']) && $_SESSION['showTimeSection']) {
        $form['fields']['time']['timeConstraints'] = array('#markup' => '<table style="table-layout:fixed"><tr></tr>');
        $form['fields']['time']['within5Years'] = array('#prefix' => '<tr style="white-space:nowrap"><td style="padding:0px;display:inline-block">Within 5 Years</td><td style="padding:5px;display:inline-block">', '#type' => 'checkbox', '#default_value' => fillFromSession('within5Years'), '#suffix' => '</td></tr>');
        $form['fields']['time']['dateSelection3'] = array('#markup' => '<tr style="white-space:nowrap"><td style="padding:5px; display:inline-block">Within</td><td style="padding:5px; display:inline-block">');
        // search outreaches within some time of specified date
        $distanceOptions = array('1 day' => '1 day', '1 week' => '1 week', '1 month' => '1 month', '1 year' => '1 year');
        $form['fields']['time']['dateDistance'] = array('#type' => 'select', '#options' => $distanceOptions, '#default_value' => fillFromSession('dateDistance'), '#chosen' => true);
        $form['fields']['time']['dateSelection4'] = array('#markup' => '</td><td style="padding:5px; display:inline-block">of</td><td style="padding:5px;display:inline-block; width:100px">');
        // specify date of outreach for use with dateDistance
        $form['fields']['time']['date'] = array('#type' => 'date_popup', '#date_format' => SHORT_TIME_FORMAT, '#date_label_position' => 'within', '#date_increment' => 1, '#date_year_range' => '-20:+20', '#datepicker_options' => array(), '#default_value' => isset($_SESSION['searchParams']['date']['center']) ? $_SESSION['searchParams']['date']['center'] : '');
        $form['fields']['time']['dateSelection5'] = array('#markup' => '</td></tr><tr style="white-space:nowrap"><td style="padding:0px; display:inline-block">Events In Year</td><td style="display:inline-block">');
        $years = array('select' => '-Select-');
        for ($i = date("Y"); $i >= 1992; $i--) {
            $years[(string) $i] = $i;
        }
        $form['fields']['time']['year'] = array('#type' => 'select', '#options' => $years, '#chosen' => true, '#default_value' => fillFromSession('year'));
        $form['fields']['time']['dateSelection6'] = array('#markup' => '</td></tr></table>');
    }
    $form['fields']['submit'] = array('#type' => 'submit', '#value' => 'Search');
    return $form;
}