Graphics settings from code

I need to enable/disable or to set a level of quality for some graphics settings (translucency, refraction, texture quality and many many others).
I tried to do it by using console variables but it seems not to work.
What is the correct way of doing it?
For example what is the variable that is set when we use showflag.fog from the console? How can I do it from code?