예제 #1
0
function notificationForm_submit($form, $form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    $OID = $params['OID'];
    // generate the notification
    $notification = getFields(array('dateTargeted', 'message'), $form_state['values']);
    $notification = stripTags($notification);
    // allow some tags
    $notification['dateTargeted'] = dbDatePHP2SQL(strtotime($notification['dateTargeted']));
    $notification['bttnTitle'] = 'View Outreach';
    $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
    $notification['OID'] = $OID;
    $notification['TID'] = dbGetTeamForOutreach($OID);
    $notification['dateCreated'] = dbDatePHP2SQL(time());
    foreach ($form_state['values']['UID'] as $UID) {
        if ($UID != null) {
            $notification['UID'] = $UID;
            $result = dbAddNotification($notification);
        }
    }
    if ($result) {
        drupal_set_message('Notification added!');
        drupal_goto('manageNotifications', array('query' => array('OID' => $OID)));
    } else {
        drupal_set_message('There was an error.', 'error');
    }
}
예제 #2
0
function applyForTeamForm_submit($form, $form_state)
{
    global $user;
    $name = $form_state['values']['personName'];
    $email = $form_state['values']['email'];
    $teamName = dbGetTeamName($form_state['TID']);
    $note = $form_state['values']['message'];
    // fill in the fields of the application
    $application['UID'] = $user->uid;
    $application['TID'] = $form_state['TID'];
    $application['userEmail'] = stripTags($email, '');
    // do not allow tags
    $application['userMessage'] = stripTags($note);
    // allow some tags
    // add a notification for the team owner and admins
    if (dbApplyForTeam($application)) {
        // note that this does its own error checking
        $notification['dateCreated'] = dbDatePHP2SQL(time());
        $notification['dateTargeted'] = dbDatePHP2SQL(time());
        $notification['TID'] = $form_state['TID'];
        $notification['message'] = "{$name} has applied to join your team {$teamName}.";
        $notification['bttnTitle'] = 'View';
        $notification['bttnLink'] = '?q=viewUsersToBeApproved&TID=' . $form_state['TID'];
        notifyUsersByRole($notification, 'teamOwner');
        notifyUsersByRole($notification, 'teamAdmin');
        drupal_set_message('Your application has been sent! You will receive an email when you have been approved for the team.');
        drupal_goto('manageUserTeams');
    }
}
예제 #3
0
function approveTeam($TID)
{
    $params = drupal_get_query_parameters();
    dbApproveTeam($TID);
    $UID = dbGetOwnerForTeam($TID);
    $teamName = dbGetTeamName($TID);
    drupal_mail('adminFunctions', 'teamApproved', dbGetUserPrimaryEmail($UID), variable_get('language_default'), $params = array('teamName' => $teamName, 'fullName' => dbGetUserName($UID)), $from = NULL, $send = TRUE);
    drupal_set_message('The team has been approved and the team owner has been notified!');
    $notification = array('UID' => $UID, 'TID' => $TID, 'dateCreated' => dbDatePHP2SQL(time()), 'dateTargeted' => dbDatePHP2SQL(time()));
    $notification['message'] = "Your team, team \"{$teamName}\" has just been approved!";
    $notification['bttnTitle'] = 'View';
    $notification['bttnLink'] = "?q=viewTeam&TID={$TID}";
    dbAddNotification($notification);
    if (isset($params['show'])) {
        drupal_goto('adminPage', array('query' => array($params['show'])));
    } else {
        drupal_goto('adminPage');
    }
}
function rejectIdea($OID)
{
    $outreach = dbGetOutreach($OID);
    $outreachName = dbGetOutreachName($OID);
    if (dbRejectIdea($OID)) {
        $UID = $outreach['UID'];
        $TID = $outreach['TID'];
        // notification to user that their outreach has been rejected
        $notification = array('UID' => $UID, 'TID' => $TID, 'message' => "{$outreachName} has been rejected.", 'dateCreated' => dbDatePHP2SQL(time()), 'dateTargeted' => dbDatePHP2SQL(time()));
        dbAddNotification($notification);
        drupal_set_message("{$outreachName} has been rejected");
    } else {
        drupal_set_message("An error has occurred.", 'error');
    }
    if (isset($_SERVER['HTTP_REFERER'])) {
        drupal_goto($_SERVER['HTTP_REFERER']);
    } else {
        drupal_goto('myDashboard');
    }
}
예제 #5
0
function addTeamMember_submit($form, $form_state)
{
    $UID = dbSearchUserByEmail($form_state['values']['primaryEmail']);
    $teamName = dbGetTeamName($form_state['TID']);
    // if the user doesn't exist yet
    if ($UID == false) {
        // programmatically creates a Drupal user and sends an email to set-up account
        $UID = createNewUser($form_state);
    } else {
        $params['fullName'] = dbGetUserName($UID);
        $params['teamName'] = $teamName;
        drupal_mail('teams', 'approvedForTeam', $form_state['values']['primaryEmail'], NULL, $params, '*****@*****.**');
    }
    $notification = array('UID' => $UID, 'TID' => $form_state['TID'], 'dateCreated' => dbDatePHP2SQL(time()), 'dateTargeted' => dbDatePHP2SQL(time()));
    $notification['message'] = 'You have just been added to ' . $teamName . '!';
    $notification['bttnTitle'] = 'View Team';
    $notification['bttnLink'] = "?q=viewTeam&TID={$form_state['TID']}";
    dbAddNotification($notification);
    dbAssignUserToTeam($UID, $form_state['TID']);
    $userName = dbGetUserName($UID);
    drupal_set_message("{$userName} has been invited to your team!");
}
예제 #6
0
function dbDuplicateOutreach($OID)
{
    $row = dbGetOutreach($OID);
    $row['name'] = $row['name'] . ' copy';
    $row['logDate'] = dbDatePHP2SQL(time());
    unset($row['OID']);
    $newOID = dbGenericInsert($row, 'outreach');
    if ($newOID == 0) {
        dbErrorMsg("Outreach not created!");
        return false;
    } else {
        return $newOID;
    }
}
예제 #7
0
function rescindTeamApplication($TID)
{
    global $user;
    dbRescindTeamApplication($user->uid, $TID);
    $teamName = dbGetTeamName($TID);
    $userName = dbGetUserName($user->uid);
    $notification['message'] = "{$userName} is no longer applying to {$teamName}.";
    $notification['dateCreated'] = dbDatePHP2SQL(time());
    $notification['dateTargeted'] = dbDatePHP2SQL(time());
    $notification['TID'] = $TID;
    notifyUsersByRole($notification, 'teamAdmin');
    drupal_set_message("Your application to {$teamName} has been removed.");
    if (isset($_SERVER['HTTP_REFERER'])) {
        drupal_goto($_SERVER['HTTP_REFERER']);
    } else {
        drupal_goto('manageUserTeams');
    }
}
예제 #8
0
function outreachForm_submit($form, $form_state)
{
    global $user;
    $UID = $user->uid;
    $TID = $form_state['TID'];
    $outreachFields = array("name", "peopleImpacted", "address", "city", "state", "country", "status", "co_organization", "co_firstName", "co_lastName", "co_email", "co_phoneNumber", "isPublic");
    $outreachData = getFields($outreachFields, $form_state['values']);
    $outreachData = stripTags($outreachData, '');
    // remove all tags
    $outreachData['description'] = stripTags(array($form_state['values']['description']));
    // allow some tags
    $outreachData["TID"] = $TID;
    if ($form_state['new']) {
        $outreachData["UID"] = $UID;
    }
    if (isset($form_state['OID'])) {
        $OID = $form_state['OID'];
        $oldOutreachData = dbGetOutreach($OID);
        if ($outreachData["status"] == "doingWriteUp" && $oldOutreachData["isWriteUpApproved"] == true) {
            $outreachData["writeUpUID"] = null;
            $outreachData["isWriteUpSubmitted"] = 0;
            $outreachData["isWriteUpApproved"] = 0;
        }
    }
    if (!$form_state['new']) {
        // updating existing event
        $OID = $form_state['OID'];
        $result = dbUpdateOutreach($OID, $outreachData);
        if ($result) {
            // if db call was successful
            for ($i = 0; $i < $form_state['numRows']; $i++) {
                // loop through date rows
                $TOID = isset($form_state['fields']['dates']["TOID-{$i}"]) ? $form_state['fields']['dates']["TOID-{$i}"] : 0;
                $timeData['startTime'] = dbDatePHP2SQL(strtotime($form_state['values']["startTime-{$i}"]));
                dpm($timeData['startTime']);
                $timeData['endTime'] = dbDatePHP2SQL(strtotime($form_state['values']["endTime-{$i}"]));
                if ($timeData['startTime'] != null && $timeData['endTime'] != null) {
                    // if row isn't empty
                    if ($TOID != 0) {
                        // update existing record
                        dbUpdateTimesForOutreach($TOID, $timeData);
                    } else {
                        // add a new time record if there wasn't one previously
                        $timeData['OID'] = $OID;
                        dbAddTimesToOutreach($timeData);
                    }
                } else {
                    // remove time record if empty
                    dbRemoveTimeFromOutreach($TOID);
                }
            }
            for ($i = $form_state['numRows']; $i < $form_state['initialNumTimes']; $i++) {
                // executes if times were deleted
                dbRemoveTimeFromOutreach($form_state['fields']['dates']["TOID-{$i}"]);
            }
            $notification = array();
            $userName = dbGetUserName($user->uid);
            $outName = dbGetOutreachName($OID);
            $notification['dateCreated'] = dbDatePHP2SQL(time());
            $notification['dateTargeted'] = dbDatePHP2SQL(time());
            $notification['message'] = "{$userName} has updated outreach {$outName}.";
            $notification['bttnTitle'] = 'View';
            $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
            $notification['TID'] = $TID;
            notifyUsersByRole($notification, 'moderator');
            // handle tags
            if (!empty($form_state['values']['tags'])) {
                $newTags = $form_state['values']['tags'];
                $previous = dbGetTagsForOutreach($OID, true);
                // the "true" means this will return only OTID's
                if ($previous == false) {
                    // if there aren't any tags
                    $previous = array();
                }
                $deleted = array_diff($previous, $newTags);
                $added = array_diff($newTags, $previous);
                foreach ($deleted as $delete) {
                    // $delete is the OTID to be removed from the outreach
                    if (!empty($delete)) {
                        dbRemoveTagFromOutreach($delete, $OID);
                    }
                }
                foreach ($added as $add) {
                    // $add is the OTID to be added to the outreach
                    if (!empty($add)) {
                        dbAddTagToOutreach($add, $OID);
                    }
                }
            }
            drupal_set_message("Outreach updated!");
        } else {
            drupal_set_message("Outreach not updated.");
        }
    } else {
        // adding new event
        $outreachData['logDate'] = dbDatePHP2SQL(time());
        $OID = dbCreateOutreach($outreachData);
        if ($OID != false) {
            dbAddUserAsOwnerOfOutreach($UID, $OID);
            dbAssignUserToOutreach($UID, $OID, 'owner');
            // handle times
            if ($outreachData['status'] != 'isIdea') {
                for ($i = 0; $i < $form_state['numRows']; $i++) {
                    $time = array("startTime-{$i}", "endTime-{$i}");
                    $timeData = getFields($time, $form_state['values']);
                    if ($timeData["startTime-{$i}"] != null && $timeData["endTime-{$i}"] != null) {
                        // rename array keys to match columns
                        $timeData['startTime'] = dbDatePHP2SQL(strtotime($timeData["startTime-{$i}"]));
                        $timeData['endTime'] = dbDatePHP2SQL(strtotime($timeData["endTime-{$i}"]));
                        unset($timeData["endTime-{$i}"], $timeData["startTime-{$i}"]);
                        $timeData['OID'] = $OID;
                        dbAddTimesToOutreach($timeData);
                    }
                }
            }
            // handle tags
            if (!empty($form_state['values']['tags'])) {
                foreach ($form_state['values']['tags'] as $OTID) {
                    dbAddTagToOutreach($OTID, $OID);
                }
            }
            // create notification
            $notification = array();
            $userName = dbGetUserName($user->uid);
            $outName = dbGetOutreachName($OID);
            $notification['dateCreated'] = dbDatePHP2SQL(time());
            $notification['dateTargeted'] = dbDatePHP2SQL(time());
            $notification['message'] = "{$userName} has created outreach {$outName}.";
            $notification['bttnTitle'] = 'View';
            $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
            $notification['TID'] = $TID;
            notifyUsersByRole($notification, 'moderator');
            drupal_set_message("Outreach created!");
        } else {
            // if the $OID IS false
            form_set_error("Outreach not created successfully");
        }
    }
    if (dbIsOutreachOver($OID)) {
        drupal_set_message("It appears you are logging an old event. Don't forget to <a href=\"?q=logHours&OID={$OID}\"><b>log old hours</b></a>!");
    }
    drupal_goto('viewOutreach', array('query' => array('OID' => $OID)));
}
예제 #9
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)));
        }
    }
}
function dbInsertNewCustomer($row, $replace = false)
{
    // TODO - massage some of the fields to convert from php to sql (like dates)
    $row["MetDate"] = dbDatePHP2SQL($row["MetDate"]);
    return dbGenericInsert($row, "customers", "CID", $replace);
}
예제 #11
0
function reject($form, $form_state)
{
    global $user;
    $params = drupal_get_query_parameters();
    $TID = getCurrentTeam()['TID'];
    $OID = $params["OID"];
    $outreachData = dbGetOutreach($OID);
    $writeUpUpdate['status'] = "doingWriteUp";
    $writeUpUpdate['writeUpUID'] = null;
    $writeUpUpdate['isWriteUpSubmitted'] = 0;
    $result = dbUpdateOutreach($OID, $writeUpUpdate);
    $notification = array();
    $userName = dbGetUserName($user->uid);
    $outName = dbGetOutreachName($OID);
    $notification['dateCreated'] = dbDatePHP2SQL(time());
    $notification['dateTargeted'] = dbDatePHP2SQL(time());
    $notification['message'] = "{$userName} has rejected a write up for {$outName}.";
    $notification['bttnTitle'] = 'Redo Write Up';
    $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
    $notification['TID'] = $TID;
    $notification['UID'] = $outreachData['writeUpUID'];
    dbAddNotification($notification);
    drupal_set_message("Write Up Rejected.");
    drupal_goto('viewOutreach', array('query' => array('OID' => $OID)));
}
예제 #12
0
function searchFormSidebar_submit($form, &$form_state)
{
    $fields = array('source', 'name', 'country', 'state', 'city', 'co_organization', 'date', 'dateDistance', 'within5Years', 'year', 'cancelled');
    $searchData = getFields($fields, $form_state['values']);
    $searchData = stripTags($searchData, '');
    // don't allow any tags
    // searchParams is an array containing search data to be passed into generateSearchSQL()
    if (!empty($form_state['values']['status'])) {
        foreach ($form_state['values']['status'] as $status => $value) {
            if ($value != '0') {
                $searchParams['status'][] = $value;
            }
        }
    }
    if (!empty($form_state['values']['teams'])) {
        foreach ($form_state['values']['teams'] as $team => $value) {
            if ($value != '0') {
                $searchParams['teams'][] = $value;
            }
        }
    }
    if (!empty($form_state['values']['tags'])) {
        foreach ($form_state['values']['tags'] as $tag => $value) {
            if ($value != '0') {
                $searchParams['tags'][] = $value;
            }
        }
    }
    if (!empty($searchData['name'])) {
        $searchParams['name'] = array('value' => $searchData['name'], 'matchType' => 'fuzzy');
    }
    if (!empty($form_state['values']['owner'])) {
        $searchParams['owner'] = array('value' => $form_state['values']['owner'], 'matchType' => 'exact');
    }
    if (!empty($form_state['values']['signedUp'])) {
        $searchParams['signedUp'] = array('value' => $form_state['values']['signedUp'], 'matchType' => 'exact');
    }
    if (!empty($searchData['country']) && $searchData['country'] != '[none]') {
        $searchParams['country'] = array('value' => $searchData['country'], 'matchType' => 'exact');
    }
    if (!empty($searchData['state']) && $searchData['state'] != '[none]') {
        $searchParams['state'] = array('value' => $searchData['state'], 'matchType' => 'exact');
    }
    if (!empty($searchData['city'])) {
        $searchParams['city'] = array('value' => $searchData['city'], 'matchType' => 'fuzzy');
    }
    if (!empty($searchData['co_organization'])) {
        $searchParams['co_organization'] = array('value' => $searchData['co_organization'], 'matchType' => 'fuzzy');
    }
    if (!empty($searchData['cancelled'])) {
        $searchParams['cancelled'] = array('value' => $searchData['cancelled'], 'matchType' => 'exact');
    } else {
        $searchParams['cancelled'] = array('value' => false, 'matchType' => 'exact');
    }
    if (!empty($searchData['within5Years'])) {
        $searchParams['within5Years'] = true;
    }
    if (!empty($searchData['date'])) {
        $date = strtotime($searchData['date']);
        $start = strtotime('-' . $searchData['dateDistance'], $date);
        $end = strtotime('+' . $searchData['dateDistance'], $date);
        $searchParams['date'] = array('start' => dbDatePHP2SQL($start), 'center' => date(DEFAULT_TIME_FORMAT, $date), 'end' => dbDatePHP2SQL($end));
    }
    if (!empty($searchData['year']) && $searchData['year'] != 'select') {
        $searchParams['year'] = array('year' => $searchData['year']);
    }
    $proxyFields = array();
    $_SESSION['searchParams'] = $searchParams;
    $_SESSION['proxyFields'] = $proxyFields;
    drupal_goto('outreach', array('query' => array('query' => 'search')));
}
예제 #13
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)));
}
예제 #14
-1
function rejectUser($UID, $TID)
{
    if (teamIsIneligible($TID)) {
        drupal_set_message('Your team does not have permission to access this page.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    // currently delete the user's application to the team
    dbRejectUser($UID, $TID);
    $notification = array('UID' => $UID, 'TID' => $TID, 'dateCreated' => dbDatePHP2SQL(time()), 'dateTargeted' => dbDatePHP2SQL(time()));
    $notification['message'] = 'You have been rejected from ' . dbGetTeamName($TID) . '.';
    $notification['bttnTitle'] = 'Reapply';
    $notification['bttnLink'] = "?q=applyForTeamForm";
    dbAddNotification($notification);
    module_load_include('inc', 'mimemail');
    drupal_mail('teams', 'rejectedFromTeam', dbGetUserPrimaryEmail($UID), variable_get('language_default'), $params = array('teamName' => dbGetTeamName($TID), 'fullName' => dbGetUserName($UID)), $from = NULL, $send = TRUE);
    drupal_set_message("User has been rejected from your team.");
    if (isset($_SERVER['HTTP_REFERER'])) {
        drupal_goto($_SERVER['HTTP_REFERER']);
    } else {
        drupal_goto('viewUsersToBeApproved', array('query' => array('TID' => $TID)));
    }
}