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 dbGiveUserRole($UID, $TID, $roleName) { $RID = dbSimpleSelect("roles", "name", $roleName)[0]['RID']; return dbGiveUserRID($UID, $TID, $RID); }