function teamLeaderSelect($area, $selected) { $url = getEnv('PERMISSIONSURL'); // Ask the permission microservice which groups' users can be team leaders $groups = sendAuthenticatedRequest("GET", $url . "/permission/verbs/28e60394-f719-4225-85ad-fa542ab6a8df/lead"); $teamLeads = array(); // loop through groups and get users for ($i = 0; $i < count($groups["data"]); $i++) { $users = sendAuthenticatedRequest("GET", $url . "/groupMembers/" . $groups["data"][$i]["Guid"]); for ($j = 0; $j < count($users["data"]); $j++) { if (!in_array($users["data"][$j], $teamLeads)) { $teamLeads[] = $users["data"][$j]; } } } $count = 0; for ($i = 0; $i < count($teamLeads); $i++) { if ($teamLeads[$i] == $selected) { echo "<option value='" . $teamLeads[$i] . "' selected>" . nameByNetId($teamLeads[$i]) . "</option>"; } else { $count++; echo "<option value='" . $teamLeads[$i] . "'>" . nameByNetId($teamLeads[$i]) . "</option>"; } } // If the selected team lead was not pulled add him/her if (count($teamLeads) == $count) { echo "<option value='" . $selected . "' selected>" . nameByNetId($selected) . "</option>"; } }
/** * Calls out to the new permission system to check * if a user can be a superuser * * @param $netId string (optional) The netId to check for admin rights * Defaults to the current user * * @return bool true if the user can be superuser, false otherwise */ function canBeSuperuser($netId = null) { global $netID; if ($netId == null) { $netId = $netID; } $domain = getEnv('PERMISSIONSURL'); $url = $domain . "/superuser/can/" . $netId; $response = sendAuthenticatedRequest("GET", $url); // Return response (true OR false) if request was successful, return false otherwise if ($response["status"] == "OK") { return filter_var($response["data"], FILTER_VALIDATE_BOOLEAN); } else { return false; } }
/** * Forces an onsite notification to all people in the area regardless of preferences, or to one person, if the fourth * parameter is filled. * @param $type string The notification type GUID * @param $message string The message to send * @param $persons (object)array The NetId, method, and email addres of a specific person(s) to receive the message, * usually the person to whom the message is referring (i.e. performance logs) */ function forceNotify($type, $message, $persons = null) { global $area, $areaGuid, $db; // Get notifications url $url = getEnv('NOTIFICATIONSURL'); $receivers = array(); if ($persons !== NULL) { foreach ($persons as $person) { $receivers[] = (object) array("netId" => $person->netId, "method" => "onsite", "email" => $person->email); } } else { // Get recipients try { $stmt = $db->prepare("SELECT netID, email FROM employee WHERE area=:area AND active=1"); $stmt->execute(array(':area' => $area)); } catch (PDOException $e) { exit("error in query"); } while ($recipient = $stmt->fetch()) { $receivers[] = (object) array("netId" => $recipient->netID, "method" => "onsite", "email" => $recipient->email); } } $guid = newGuid(); try { $stmt3 = $db->prepare("INSERT INTO notifications (message, type, area, guid) VALUES (:message, :type, :area, :guid)"); $stmt3->execute(array(":message" => $message, ":type" => $type, ":area" => $areaGuid, ":guid" => $guid)); } catch (PDOException $e) { exit("error in query"); } if (count($receivers) > 0) { sendAuthenticatedRequest("POST", "https://" . $url . "/notify", array("message" => $message, "receivers" => json_encode($receivers))); foreach ($receivers as $receiver) { try { $stmt4 = $db->prepare("INSERT INTO userNotifications (netId, notificationGuid) VALUES (:netId, :guid)"); $stmt4->execute(array(":netId" => $receiver->netId, ":guid" => $guid)); } catch (PDOException $e) { } // catch exceptions if they arise, but try to add as many as possible } } }
function getAllUserPermissions() { global $db, $areaGuid, $netID; // Set url for accessing permission microservice $url = getEnv('PERMISSIONSURL'); // Retrieve permissions $result = sendAuthenticatedRequest("GET", $url . "/permission/user/" . $netID . "/" . $areaGuid); // Verify that result was returned if ($result == null || $result["status"] == "ERROR") { return null; } return $result["data"]; }