Fix warnings

This fixes some PHP notices and/or warning complaining about undefined variables or indices in several scripts.