Count the opening curly braces ("{") and the closing ones ("}")
When you're done counting, you'll notice the difference. Then you have to go through and find where that missing (or extra) one is.
In your case, at the bottom of the file, you have this:
<?php
}
?>
but no opening { anywhere in the file. Either remove it, or put in an if/else statement.