MISC-misc-39a7.18: Replaced intval() by idval() on db query preparation. Fixed captain query