First off that code box is super bad to read.
Second, what exactly are you trying to ask. You can't just post code and think someone can help you.
Use [php] [/ php] with spoilers. It will be easier to read.
[spoiler][php] [/php ][/spoiler ] (Just remove the spaces from the 2nd set of brackets.