alert('file opened');"; $data = "Nr;Key;Status\n"; $count = count($keyData) - 1; for ($i = 0; $i < $count; $i++) $data = $data . $i . ";" . $keyData[$i][0] . ";" . $keyData[$i][1] . "\n"; $data = $data . $count . ";" . $keyData[$count][0] . ";" . $keyData[$count][1]; //use exclusive lock for writing flock($handle, LOCK_EX); ftruncate($handle, 0); $res = fwrite($handle, $data); fflush($handle); flock($handle, LOCK_UN); // debug Code //if ($res == false) // echo ""; //else // echo ""; fclose($handle); if ($res) { return true; } else { return false; } } /** * Get the current state of the specified key which will be one of the defines * KEYSTATE constants. * The data type of the key data should be an array of arrays consisting of the key and its state. * * @param array $keyData The key data array in which the key should be found. Passed by reference. * @param string $key The key which state should be got. Passed by reference. * @return integer */ function GetKeyState(&$keyData, &$key) { for ($i = 0; $i < count($keyData); $i++) if ($key == $keyData[$i][0]) return $keyData[$i][1]; return KEYSTATE_NONEXISTENT; } /** * Set the state of the specified key to the specified state. * The data type of the $keyData should be an array of arrays consisting of the key and its state. * Returns true if the key was found within the key data and the state has been changed, otherwise false. * * @param array $keyData The key data array in which the key should be found. Passed by reference. * @param string $key The key which state should be changed. * @param integer $newState The new state of the specified key. Must be on of the KEYSTATE constants. * @return boolean */ function SetKeyState(&$keyData, &$key, $newState) { for ($i = 0; $i < count($keyData); $i++) if ($key == $keyData[$i][0]) { $keyData[$i][1] = $newState; return true; } return false; } ?>