Chart - disable certain user from viewing in event

Hi,

​I have created a chart and in Events under onScriptInit, I allow if the user has a rank “3”, he will be able to view the information pertaining to his department. Below is the code:

​if($rank==‘3’){
​ sc_select_where(add) = " where dept = ‘$dept’";
​}

​If the person login using admin account, he will see all information but if he is rank=2, he will not see any information. Thus, I try adding the following but it does not works. Can someone kindly help? Thanks.

​else if([login]!=‘admin’ && $rank==‘2’){
sc_error_message(“You do not have the permission”);
​}