function notificationForm() { $params = drupal_get_query_parameters(); if (isset($params['OID'])) { $OID = $params['OID']; } else { drupal_set_message('No outreach specified.', 'error'); } $form['fields'] = array('#type' => 'fieldset', '#title' => t('Add Info: Notification')); $form['fields']['tableHeader'] = array('#markup' => '<table>'); $outreachName = dbGetOutreachName($OID); if (!$outreachName) { drupal_set_message('Invalid outreach event.', 'error'); return; } // simply displays the chosen outreach event $form['fields']['outreachName'] = array('#prefix' => '<tr><td>', '#type' => 'textfield', '#title' => t('Outreach Name:'), '#disabled' => true, '#default_value' => $outreachName, '#suffix' => '</td></tr>'); // allow the user to choose who the notification will go to (of those signed up or who own the outreach) $UIDs = dbGetUIDsForOutreach($OID); if (!empty($UIDs)) { $form['fields']['UID'] = array('#prefix' => '<tr><td>', '#title' => 'Select Users', '#type' => 'checkboxes', '#options' => $UIDs, '#suffix' => '</td>'); } else { drupal_set_message('There are no users associated with this event.', 'error'); drupal_goto('manageNotifications', array('query' => array('OID' => $OID))); } // allow the user to choose when the notification will arrive $form['fields']['dateHeader'] = array('#markup' => '<td colspan="2" align="left" style="text-align:left">'); $form['fields']['dateTargeted'] = array('#type' => 'date_popup', '#title' => t('Delivery Date:'), '#date_format' => TIME_FORMAT, '#date_label_position' => 'within', '#date_increment' => 1, '#date_year_range' => '-20:+20', '#datepicker_options' => array()); $form['fields']['dateFooter'] = array('#markup' => '</td>'); $form['fields']['message'] = array('#prefix' => '<tr><td colspan="2">', '#type' => 'textarea', '#title' => t('Message:'), '#suffix' => '</td></tr>'); $form['fields']['submit'] = array('#prefix' => '<tr><td colspan="2" style="text-align:right">', '#type' => 'submit', '#value' => t('Submit'), '#suffix' => '</td></tr>'); $form['fields']['tableFooter'] = array('#markup' => '</table>'); return $form; }
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'); } }
function manageNotifications() { $params = drupal_get_query_parameters(); if (isset($params['OID'])) { $OID = $params['OID']; $outreachName = dbGetOutreachName($OID); // create page header, table, and add notification button $markup = ''; $markup .= '<table>'; $markup .= "<tr><td><h1>Manage Notifications for \"{$outreachName}\" </h1>"; $markup .= '</td><td style="text-align:right">'; $markup .= '<a href="?q=notificationForm&OID=' . $OID . '"><button>Add Notification</button></a></td></tr></table>'; $markup .= '<table class="infoTable"><tr><th colspan="3">Target Users</th><th colspan="3">Notification Message</th><th colspan="2">Date To Be Sent</th><th colspan="2"></th></tr>'; $notifications = dbGetNotificationsForOutreach($OID); // if outreach already has notifications if (!empty($notifications)) { foreach ($notifications as $notification) { $markup .= '<tr>'; $markup .= '<td colspan="3">' . dbGetUserName($notification['UID']) . '</td>'; $markup .= '<td colspan="3">' . $notification['message'] . '</td>'; $date = dbDateSQL2PHP($notification['dateTargeted']); $markup .= '<td colspan="2">' . date(TIME_FORMAT, $date) . '</td>'; $markup .= '<td colspan="2"><a href="?q=deleteNotification/' . $notification['NID']; $markup .= "/{$OID}\"><button>Delete</button></a></td>"; $markup .= '</td>'; } $markup .= '</table>'; } else { // if outreach does not have notifications $markup .= "<tr>"; $markup .= '<td style="text-align:center" colspan="10"><em>[None]</em></td>'; $markup .= "</tr>"; } $markup .= "</table>"; return array('#markup' => $markup); } else { // returns message if OID is not correct drupal_set_message('No outreach selected.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } }
function viewHours() { $params = drupal_get_query_parameters(); global $user; // checks to make sure you are assigned to a team if (dbGetTeamsForUser($user->uid) == NULL) { drupal_set_message("You don't have a team assigned.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // setting all permissions to a default "false" value $canEdit = $canApprove = $myHours = false; $markup = ''; // showing the hours if the UID is set for a user $filterParams = array(); if (isset($params['UID'])) { $UID = $params['UID']; $myHours = $UID == $user->uid; $filterParams['hourCounting.UID'] = $UID; $userName = dbGetUserName($UID); $markup = "<table><tr><td><h1>Hours for {$userName}</h1></td></tr></table>"; } // showing the hours if the OID is set for an outreach if (isset($params['OID'])) { $OID = $params['OID']; $TID = getCurrentTeam()['TID']; $filterParams['OID'] = $OID; $canEdit = canEditHoursForOutreach($OID); // can be set for the entire page if (hasPermissionForTeam('manageOutreachTags', $TID)) { $canApprove = true; // can be set for the entire page } $outreachName = dbGetOutreachName($OID); $markup = "<table><tr><td><h1>Hours for {$outreachName}</a></h1></td>"; } if (isset($params['OID']) && isset($params['UID']) && !isset($params['TID'])) { $markup = "<table><tr><td><h1>Hours contributed to {$outreachName} by {$userName}</h1></td></tr></table>"; } // showing the hours needing to be approved for a team if the TID is set if (isset($params['TID'])) { $TID = $params['TID']; $filterParams['TID'] = $TID; $filterParams['isApproved'] = 0; $teamName = dbGetTeamName($TID); $markup = "<table><tr><td><h1>Hours to be approved for {$teamName}</h1></td></tr></table>"; } // if the filters are not empty... if (!empty($filterParams)) { $hoursEntries = dbGetHours($filterParams); // get all the matching "hour" records if (isset($OID)) { $markup .= '<td style="text-align:right">'; $markup .= "<a href=\"?q=logHours&OID={$OID}\"><button>Add Hours</button></a></td></tr></table>"; } $markup .= '<table class="infoTable">'; // starting the table if (empty($OID)) { $markup .= '<th>Event</th>'; } if (!$myHours) { $markup .= '<th>Person</th>'; } $markup .= '<th>Type</th><th># Hours</th>'; $markup .= '<th></th>'; // create placeholder column foreach ($hoursEntries as $hours) { $markup .= '<tr>'; if (!isset($OID)) { // permissions must be set per hour record $canEdit = canEditHours($hours['HID']); // can be set for the entire page $canApprove = canApproveHours($hours['HID']); // can be set for the entire page if (isset($TID) && !$canApprove) { // if trying to approve hours for the team continue; } $outreachName = dbGetOutreachName($hours['OID']); $markup .= "<td><a href=\"?q=viewOutreach&OID={$hours['OID']}\">{$outreachName}</a></td>"; } // if the hours don't belong the current user, show the name of the person they do belong to if (!$myHours) { $markup .= '<td>'; if ($hours['UID'] != null) { $name = dbGetUserName($hours['UID']); $email = dbGetUserPrimaryEmail($hours['UID']); $markup .= "<a href=\"mailto:{$email}\" target=\"_top\">{$name}</a>"; } else { $markup .= '[none]'; } $markup .= '</td>'; } switch ($hours['type']) { // switch the type to be more formal case 'prep': $formalType = "Preparation"; break; case 'atEvent': $formalType = "At Event"; break; case 'writeUp': $formalType = "Write Up"; break; case 'followUp': $formalType = "Follow Up"; break; case 'other': $formalType = "Other"; break; } $markup .= "<td>{$formalType}</td>"; $markup .= "<td>{$hours['numberOfHours']}</td>"; if ($canEdit || $canApprove) { $markup .= '<td>'; if ($canEdit) { // if user can edit... $markup .= "<a href=\"?q=logHours&HID={$hours['HID']}\">"; $markup .= '<button><img class="editIcon" src="/images/icons/editWhite.png"></button></a>'; $markup .= "<a href=\"?q=deleteHours/{$hours['HID']}\">"; $markup .= '<button><img class="trashIcon" src="/images/icons/trashWhite.png"></button></a>'; } if ($canApprove && !$hours['isApproved']) { // if user can approve hours and the hours are not approved... $markup .= "<a href=\"?q=approveHours/{$hours['HID']}\">"; $markup .= '<button>Approve Hours</button></a>'; } else { if (!$hours['isApproved']) { $markup .= '<button disabled>Approve Hours</button>'; } } $markup .= '</td>'; } $markup .= '</tr>'; } if (empty($hoursEntries)) { $markup .= '<tr><td style="text-align:center" colspan="10"><em>[None]</em></td></tr>'; } $markup .= '</table>'; } else { // no filter params drupal_set_message('No filter parameters selected.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } return array('#markup' => $markup); }
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 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 viewMedia() { global $user; if (dbGetTeamsForUser($user->uid) == false) { drupal_set_message("You don't have a team assigned.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } $params = drupal_get_query_parameters(); if (!isset($params['OID'])) { drupal_set_message('No outreach selected.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } $OID = $params['OID']; $markup = ''; $outreachName = dbGetOutreachName($OID); // create header, table $markup .= "<table><tr><td><h1>Media for \"{$outreachName}\" </h1></td>"; $markup .= '<td style="text-align:right">'; // upload media button $markup .= "<a href=\"?q=uploadMedia&OID={$OID}\"><button>Upload Media</button></a></td></tr></table>"; $media = dbGetMediaForOutreach($OID); // create table $markup .= '<table class="infoTable"><tr><th>Image</th><th>Name</th><th><Info</th><th>Uploaded By</th><th></th><th></th>'; // if media for outreach is not empty if (!empty($media)) { // displays all media for the outreach foreach ($media as $m) { $url = generateURL($m['FID']); $MID = $m['MID']; $UIDofMID = dbGetUserForMedia($MID); $profile = dbGetUserProfile($UIDofMID); $markup .= '<tr><td><a href=' . $url . '><img src="' . $url . '" width="150px" height="150px"></a></td>'; $markup .= '<td>' . $m['title'] . '</td>'; $markup .= '<td>' . wordwrap(chopString($m['description'], 30), 15, "<br>\n", TRUE) . '</td>'; $markup .= "<td>" . $profile['firstName'] . ' ' . $profile['lastName'] . "</td>"; $markup .= "<td><a href=\"?q=mediaForm&MID={$MID}&OID={$OID}\"><button><img class=\"editIcon\" src=\"/images/icons/editThumbnailWhite.png\"></button></a></td>"; // allow user to delete media if he/she was the one to upload it if (isMyMedia($MID)) { $markup .= "<td><a href=\"?q=removeMedia/{$MID}\"><button><img class=\"trashIcon\" src=\"/images/icons/trashWhite.png\"></button></a></td>"; } else { $markup .= "<td></td>"; } } $markup .= '</tr></table>'; } else { // if there is no media assigned to the outreach $markup .= "<tr>"; $markup .= '<td style="text-align:center" colspan="10"><em>[None]</em></td>'; $markup .= "</tr>"; } $markup .= "</table>"; return array('#markup' => $markup); }
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))); }
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))); }