The function of state switching is added

This commit is contained in:
Valentin Popov 2017-12-03 19:33:44 +04:00
parent 90cf7a0ce1
commit 3c98979336

19
lib.php
View File

@ -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.
*