Exemplo n.º 1
0
function hoursForm_submit($form, $form_state)
{
    global $user;
    // getting value of new from form state
    $new = isset($form_state['new']) ? $form_state['new'] : true;
    $OID = $form_state['OID'];
    // looping through the rows of hours
    for ($i = 0; $i < $form_state['numRows']; $i++) {
        $fields = array("numberOfHours-{$i}", "description-{$i}", "type-{$i}");
        $row = getFields($fields, $form_state['values']);
        // dont allow any html tags
        $row = stripTags($row, '');
        // setting the values which were read in into the row which will go into the database
        $row['numberOfHours'] = $row["numberOfHours-{$i}"];
        $row['description'] = $row["description-{$i}"];
        $row['isApproved'] = 0;
        $row['type'] = $row["type-{$i}"];
        unset($row["type-{$i}"], $row["numberOfHours-{$i}"], $row["description-{$i}"]);
        if (isset($form_state['values']['fields']['UID'])) {
            $UID = $form_state['values']['fields']['UID'];
        } else {
            $UID = $user->uid;
        }
        if ($UID != 0) {
            $row['UID'] = $UID;
        }
        $row['OID'] = $OID;
        // if adding new hours
        if ($new) {
            if (dbLogHours($row) == false) {
                drupal_set_message("Error", 'error');
                break;
            }
        } else {
            // editing old hours
            $row['isApproved'] = 0;
            if (dbUpdateHours($row, $form_state['HID']) == false) {
                drupal_set_message("Error", 'error');
                break;
            }
        }
    }
    // end of for loop
    drupal_set_message("Your hours have been logged!");
    // assigning user to outreach if not new
    if (!$new) {
        dbAssignUserToOutreach($UID, $OID, $row['type']);
        drupal_goto("viewOutreach", array('query' => array("OID" => $OID)));
    } else {
        // notifying appropriate users of changes/addition of hours
        $outreachName = dbGetOutreachName($OID);
        $personName = dbGetUserName($user->uid);
        $notification['message'] = "{$personName} has logged hours for {$outreachName}!";
        $notification['TID'] = dbGetTeamForOutreach($OID);
        $notification['dateTargeted'] = dbDatePHP2SQL(time());
        $notification['dateCreated'] = dbDatePHP2SQL(time());
        notifyUsersByRole($notification, 'moderator');
        notifyOwnerOfOutreach($OID, $notification);
        if ($OID != 0) {
            drupal_goto("viewHours", array('query' => array("OID" => $OID)));
        } else {
            drupal_goto("viewHours", array('query' => array("UID" => $UID)));
        }
    }
}
Exemplo n.º 2
0
function signUp_submit($form, $form_state)
{
    global $user;
    $UID = $user->uid;
    $params = drupal_get_query_parameters();
    $OID = $params['OID'];
    $new = $form_state['new'];
    $fields = array("times");
    $fieldsData = getFields($fields, $form_state['values']);
    $types = $fieldsData['times'];
    $types = array_values($types);
    if ($new) {
        // if the user is signing up for the first time
        foreach ($types as $type) {
            if ($type !== 0) {
                dbAssignUserToOutreach($UID, $OID, $type);
                // assigning user to outreach and the various time(s) they signed up for
            }
        }
        $msgToUser = "******";
    }
    if (!$new) {
        // user is updating the time(s)
        $previous = dbGetUserSignUpType($UID, $OID);
        $deleted = array_diff($previous, $types);
        $added = array_diff($types, $previous);
        foreach ($deleted as $delete) {
            if (!empty($delete)) {
                dbRemoveCommitmentFromOutreach($UID, $OID, $delete);
                // removing the times the user "unchecked"
            }
        }
        foreach ($added as $add) {
            // adding the times the user "checked"
            if (!empty($add)) {
                dbAssignUserToOutreach($UID, $OID, $add);
            }
        }
        $msgToUser = "******";
    }
    // sending a notification to the appropriate user(s)
    $notification = array();
    $userName = dbGetUserName($UID);
    $outName = dbGetOutreachName($OID);
    $team = getCurrentTeam();
    $TID = $team['TID'];
    $notification['dateTargeted'] = $notification['dateCreated'] = dbDatePHP2SQL(time());
    $notification['message'] = "{$userName} has just signed up for your outreach: {$outName}!";
    $notification['TID'] = $TID;
    notifyOwnerOfOutreach($OID, $notification);
    $outreachEventLink = '<a href="?q=viewOutreach&OID=' . $OID . '">' . dbGetOutreachName($OID) . '</a>';
    drupal_set_message("{$msgToUser} {$outreachEventLink}!");
    drupal_goto('viewOutreach', array('query' => array('OID' => $OID)));
}