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'); } }
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'); } }
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 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))); }
function approve($form, $form_state) { global $user; $UID = $user->uid; $params = drupal_get_query_parameters(); $TID = getCurrentTeam()['TID']; $OID = $params["OID"]; $writeUpFields = array("totalAttendance", "testimonial", "writeUp"); $writeUpData = getFields($writeUpFields, $form_state['values']); $writeUpData = stripTags($writeUpData, ''); // remove all tags $writeUpData['isWriteUpApproved'] = true; $writeUpData['isWriteUpSubmitted'] = 0; $writeUpData['status'] = 'locked'; if (empty($writeUpData["totalAttendance"])) { $writeUpData["totalAttendance"] = null; } $result = dbUpdateOutreach($OID, $writeUpData); $notification = array('TID' => $TID, 'dateCreated' => dbDatePHP2SQL(time()), 'dateTargeted' => dbDatePHP2SQL(time()), 'message' => dbGetUserName($UID) . ' has just approved ' . dbGetOutreachName($OID) . '!', 'bttnLink' => '?q=viewOutreach&OID=' . $OID, 'bttnTitle' => 'View Outreach'); // notify the appropriate people $outreachOwnerUID = dbGetOutreachOwner($OID); if ($UID != $outreachOwnerUID) { dbAddNotification($notification); } notifyUsersByRole($notification, 'moderator'); notifyUsersByRole($notification, 'teamAdmin'); notifyUsersByRole($notification, 'teamOwner'); drupal_set_message("Write up approved!"); drupal_goto('viewOutreach', array('query' => array('OID' => $OID))); }