From 3c989793366c47fd0877782267dcfbdca63e8a13 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 3 Dec 2017 19:33:44 +0400 Subject: The function of state switching is added --- lib.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib.php b/lib.php index 7856667..8274b11 100644 --- a/lib.php +++ b/lib.php @@ -47,6 +47,25 @@ function tool_managertokens_activate_token($token = "") { return $token; } +/** + * Toggles the status of an existing token. + * + * @param number|string $key + * @return boolean + */ +function tool_managertokens_change_status($key = "") { + global $DB; + + $result = false; + $select = "id = '$key' OR token = '$key'"; + if ($DB->record_exists_select("tool_managertokens_tokens", $select, null)) { + $enabled = $DB->get_field_select("tool_managertokens_tokens", "enabled", $select, null, IGNORE_MISSING); + $result = $DB->set_field_select("tool_managertokens_tokens", "enabled", !boolval($enabled), $select, null); + } + + return boolval($result); +} + /** * Creates a backup copy of the tokens. * -- cgit v1.2.3