function viewUsersForTeam_submit($form, $form_state) { $TID = $form_state['TID']; $roleChanged = false; for ($i = 0; $i < $form_state['numUsers']; $i++) { if (!isset($form_state['values']["RID-{$i}"])) { continue; } $UID = $form_state["UID-{$i}"]; $newRID = $form_state['values']["RID-{$i}"]; $oldRID = $form["RID-{$i}"]['#default_value']; // check if the RID changed if ($newRID != $oldRID) { // adding new role if ($oldRID == 0) { dbGiveUserRID($UID, $TID, $newRID); } else { if ($newRID != 0) { $result = dbUpdateUserRole($UID, $TID, $newRID); } else { dbRemoveAllUserRoles($UID, $TID); } } $userName = dbGetUserName($UID); drupal_set_message("{$userName}'s role has been updated."); $roleChanged = true; $notification = array('UID' => $UID, 'TID' => $TID, 'dateCreated' => date(DEFAULT_TIME_FORMAT, time()), 'dateTargeted' => date(DEFAULT_TIME_FORMAT, time())); // check if the user no longer has a role if (dbGetRoleName($newRID) == false) { $notification['message'] = "You are no longer a " . strtolower(dbGetRoleName($oldRID)); } else { $notification['message'] = 'You are now a ' . strtolower(dbGetRoleName($newRID)); } $notification['message'] .= ' on team ' . dbGetTeamName($TID) . '.'; dbAddNotification($notification); } } if (!$roleChanged) { drupal_set_message('No changes were made. An issue occured.', 'error'); } }
function transferTeamOwnershipForm_submit($form, $form_state) { global $user; // update the team and the new owner's role $newOwnerUID = $form_state['values']['newOwner']; $TID = $form_state['TID']; dbUpdateTeam($TID, array('UID' => $newOwnerUID)); dbUpdateUserRole($newOwnerUID, $TID, dbGetRID('teamOwner')); dbUpdateUserRole($user->uid, $TID, dbGetRID('teamAdmin')); // set a message to notify the old owner on-screen $newOwnerName = dbGetUserName($newOwnerUID); $teamName = dbGetTeamName($TID); drupal_set_message("{$newOwnerName} is now the owner of {$teamName}!"); // notify new owner through CROMA $notification = array('UID' => $newOwnerUID, 'TID' => $TID, 'dateTargeted' => dbDatePHP2SQL(time()), 'dateCreated' => dbDatePHP2SQL(time())); $notification['message'] = "You are now the owner of {$teamName}!"; $notification['bttnTitle'] = 'View'; $notification['bttnLink'] = "?q=viewTeam&TID=" . $TID; dbAddNotification($notification); // notify new owner through email $oldOwnerName = dbGetUserName($user->uid); $oldOwnerEmail = $user->mail; drupal_mail('teams', 'becameOwner', dbGetUserPrimaryEmail($newOwnerUID), variable_get('language_default'), $params = array('teamName' => $teamName, 'newOwnerName' => $newOwnerName, 'oldOwnerName' => $oldOwnerName, 'oldOwnerEmail' => $oldOwnerEmail, 'TID' => $TID), $from = NULL, $send = TRUE); drupal_goto('showUsersForTeam', array('query' => array('TID' => $TID))); }