Your friend is right. It's isolated electrically but is is NOT SAFE nor will it meet any safety standards that I'm aware of.
You can't run AC or any other traces under the opto and there are minimum spacing requirements between AC and logic as well as between AC with different polarity. Review that DIN spec for particulars.
Draw an imaginary line vertically through the opto. All AC must be on one side of the line and all logic on the other side. Sometimes, you'll even see a slot in the PCB under the opto to further isolate the two halves.
You are going to have to move things around, like it or not.
It's better. It still violates the 'vertical line rule' I described. It is much better to have the AC stuff exclusively on one side of the opto and the low voltage stuff on the other side with no encroachment of the other's space. You indicated earlier that you can't move P1. Can you put the AC entry on the left side of the picture or rotate the opto so that the logic side is above P1 and stretch the board vertically to accommodate the AC stuff? One of those would be my personal preference. Based on your earlier layout, I'd move P1 anyway.I have changed my PCB. Is it Ok?
Thanks my dearIt's better. It still violates the 'vertical line rule' I described. It is much better to have the AC stuff exclusively on one side of the opto and the low voltage stuff on the other side with no encroachment of the other's space. You indicated earlier that you can't move P1. Can you put the AC entry on the left side of the picture or rotate the opto so that the logic side is above P1 and stretch the board vertically to accommodate the AC stuff? One of those would be my personal preference. Based on your earlier layout, I'd move P1 anyway.
Failing that, you can get better spacing on the trace from pin 4 of the opto by dropping a via just to the right of the pad and routing that trace to P1 on the top of the board outside the opto pattern. Move the opto down a bit as well.
There are specs and standards governing spacings, trace widths, creepage etc. and if you are within those, you might decide you're OK. The best option would be to consult the standards applicable to your product and adhere to those. Google things like PCB trace spacing and creepage. Here's some stuff I found:
http://www.smpspowersupply.com/ipc2221pcbclearance.html
A nice PCB layout guide here (requires registration). Covers pretty much all you need to know.
http://blog.optimumdesign.com/optimum-designer-handbook
As we noted earlier, safety is of prime importance.