Amplifier IC - selecting input (Sound Card/Phone jack) and output(Headphones/RCA)
I´ve tried drawing out what you´re trying to do and it´s given me a headache, so I´ll just point you in the right direction.  :)

For the input, you need a multigang switch like this one. Each pole will go to an input of your 5.1. One position for the soundcard, the other for the phone stereo jack.

For the output, how are you going to drive the headphones? They will need their own (separate) amplifier. Have you thought about that? You could just leave them permanently connected and use a switch box to switch out the main speakers. Something like this. 

Hope this helps.