package com.newsclan.crud;

public class Auth {
	public static boolean isAdmin(int user_id) {
		if( user_id == 1) return true;
		if(Config.get("login.check").equalsIgnoreCase("false")) return true;
		return checkPrivilegeForRightOfTable(user_id,"","admin");
	}
	public static boolean checkPrivilegeForRightOfTable(int user_id, String tbname,
			String right) {
		if(Config.get("login.check").equalsIgnoreCase("false")) return true;
		if(user_id>1000&&"student,news".contains(tbname)&&"insert,update".contains(right)) return true;
		String sql="select `right` from "+Config.sysPrefix+"privilege where `user_id`=? and `right`=?";
		String ret=DAO.queryString(sql, String.valueOf(user_id),String.format("[%s]%s", tbname,right));
		return ret!=null;
	}
	public static boolean canInsertTable(int user_id, String tbname) {

		if (isAdmin(user_id))
			return true;
		return checkPrivilegeForRightOfTable(user_id, tbname, "insert");
	}

	public static boolean canReadTable(int user_id, String tbname) {
		if (isAdmin(user_id))
			return true;
		return checkPrivilegeForRightOfTable(user_id, tbname, "read");
	}

	

	public static boolean canUpdateTable(int user_id, String tbname) {
		if (isAdmin(user_id))
			return true;
		return checkPrivilegeForRightOfTable(user_id, tbname, "update");
	}
	public static boolean canUploadFile(int user_id) {
		if (isAdmin(user_id))
			return true;
		return checkPrivilegeForRightOfTable(user_id, "", "upload");
	}

	public static boolean canDeleteTable(int user_id, String tbname) {
		if (isAdmin(user_id))
			return true;
		return checkPrivilegeForRightOfTable(user_id, tbname, "delete");
	}

	public static boolean canInsertField(int user_id, String tbname,
			String fdname) {
		if (isAdmin(user_id))
			return true;
		return true;
	}

	public static boolean canReadField(int user_id, String tbname, String fdname) {
		if (isAdmin(user_id))
			return true;
		return true;
	}

	public static boolean canUpdateField(int user_id, String tbname,
			String fdname) {
		if (isAdmin(user_id))
			return true;
		return true;
	}

	public static boolean canDeleteField(int user_id, String tbname,
			String fdname) {
		if (isAdmin(user_id))
			return true;
		return true;
	}

}

@@ -440,107 +440,8 @@
 e;%0D%0A
-%09%09if(user_id%3E1000&&%22student,news%22.contains(tbname)&&%22insert,update%22.contains(right)) return true;%0D%0A
 %09%09St

Update Auth.java