CREATE OR REPLACE FUNCTION getUserIntroStep(personid int) RETURNS int AS $$
	DECLARE
		sid int;
	BEGIN
		IF ((SELECT count(*) FROM nij_person_data WHERE person = personid AND key = 'browser_check') = 0) THEN
			RETURN 0;
		END IF;
		
		SELECT INTO sid ID FROM survey ORDER BY ID ASC LIMIT 1;
		IF ((SELECT numquestions FROM survey ORDER BY ID ASC LIMIT 1) <> (SELECT count(*) FROM survey_result WHERE survey = sid AND person = personid)) THEN
			RETURN 1;
		END IF;
		RETURN 2;
	END;
$$ LANGUAGE plpgsql;
