moved if/else conditions in to php and out of javascript