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'); } }
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 signUp($form, &$form_state) { global $user; $UID = $user->uid; $new = $form_state['new'] = true; $params = drupal_get_query_parameters(); // various checks for permissions if (dbGetTeamsForUser($user->uid) == false) { drupal_set_message("You don't have a team assigned.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // getting the outreach ID from the URL parameters and setting that and the team ID into local variables if (isset($params['OID']) && $params['OID'] > 0) { $OID = $params['OID']; $TID = dbGetTeamForOutreach($OID); if (!dbIsUserApprovedForTeam($UID, $TID)) { drupal_set_message('You do not have the permission to contribute to this event.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } if (dbIsOutreachOver($OID)) { drupal_set_message('You can not contribute to this event. It has already ended.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } $outreach = dbGetOutreach($OID); if (dbIsUserSignedUp($UID, $OID)) { // if user is already signed up for outreach then sets "new" to false $new = $form_state['new'] = false; $data = dbGetUserSignUpType($UID, $OID); // getting data related to sign up } $types = array('prep' => 'Preparation', 'atEvent' => 'At Event', 'writeUp' => 'Write Up', 'followUp' => 'Follow Up'); $form = array(); $form['fields'] = array('#type' => 'fieldset', '#title' => t('Sign Up For Outreach: ' . dbGetOutreachName($OID))); // displays outreach owner's name and email (unless they are no longer on the team) $ownerUID = dbGetOutreachOwner($OID); $email = dbGetUserPrimaryEmail($ownerUID); if (dbGetUserName($ownerUID) != -1) { $markup = '<b>Owner of Outreach: </b>' . dbGetUserName($ownerUID); if (dbIsUserApprovedForTeam($ownerUID, $TID)) { $markup .= "<br><b>Email of Owner: </b><a href=\"mailto:{$email}\" target=\"_top\">{$email}</a>"; } else { $markup .= ' (no longer on this team)<br>'; } } else { $markup = '<b>Owner of Outreach: </b>[none]<br>'; $markup .= '<b>Email of Owner: </b>[none]'; } $form['tableHeader'] = array('#markup' => $markup); // signing up for time slots listed in the array above (local variable --> "types") $form['fields']['times'] = array('#prefix' => '<table colspan="4"><tr><td colspan="2">', '#type' => 'checkboxes', '#title' => t('<h4>Which time(s) would you like to sign up for?</h4>'), '#options' => $types, '#default_value' => $new ? array() : $data, '#suffix' => '</td>'); // obligatory confirmation for the user to understand their commitment $form['fields']['confirmation'] = array('#prefix' => '<td colspan="2">', '#type' => 'checkbox', '#title' => t('<b>By checking this box, I understand that I am signing up for this event and am committed to the time(s) I agreed to.</b>'), '#suffix' => '</td></tr>'); $form['fields']['html1'] = array('#markup' => '<tr>'); // allows a user to cancel their commitment to their outreach times if (!$new) { $form['fields']['cancel'] = array('#prefix' => '<td colspan="2">', '#type' => 'submit', '#value' => 'Remove Commitment', '#limit_validation_errors' => array(), '#submit' => array('cancelCommit'), '#suffix' => '</td>'); } else { $form['fields']['html'] = array('#markup' => '<td></td>'); } $form['fields']['submit'] = array('#prefix' => '<td colspan="2" style="text-align:right">', '#type' => 'submit', '#value' => t('Submit'), '#suffix' => '</td>'); $form['fields']['footer'] = array('#markup' => '</tr></table>'); return $form; } else { // in case the parameter passed was an invalid OID drupal_set_message('Invalid outreach event. Click <a href="?q=teamDashboard">here</a> to naviagte back to events in Team Dashboard.', 'error'); } }