aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-12-03 18:33:44 +0300
committerValentin Popov <info@valentineus.link>2017-12-03 18:33:44 +0300
commit3c989793366c47fd0877782267dcfbdca63e8a13 (patch)
tree09d33604ca35b6972695eef89bf6108287fa05fb /lib.php
parent90cf7a0ce17f84f5d484904691956a1f784846ee (diff)
downloadtool_managertokens-3c989793366c47fd0877782267dcfbdca63e8a13.tar.xz
tool_managertokens-3c989793366c47fd0877782267dcfbdca63e8a13.zip
The function of state switching is added
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib.php b/lib.php
index 7856667..8274b11 100644
--- a/lib.php
+++ b/lib.php
@@ -48,6 +48,25 @@ function tool_managertokens_activate_token($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.
*
* @return string