Any person owning, controlling or managing any building, structure or premises where there shall exist anything in violation of any of the provisions of this chapter or any condition imposed by the Planning Board or the Zoning Board of Appeals, and any person who shall assist in the commission of any violation of this chapter or any condition imposed by the Planning Board or the Zoning Board of Appeals shall be guilty of an offense; and for conviction of a first offense, such person shall be punishable by a fine not exceeding $350 or imprisonment for a period not to exceed six months, or both; for conviction of a second offense, both of which were committed within a period of five years, such person shall be punishable by a fine of not less than $350 nor more than $700 or imprisonment for a period not to exceed six months, or both; and upon conviction for a third or subsequent offense, all of which were committed within a period of five years, such person shall be punishable by a fine of not less than $700 nor more than $1,000 or imprisonment for a period not to exceed six months, or both. For the purpose of conferring jurisdiction upon courts and judicial officers generally, violations of this chapter shall be deemed misdemeanors; and for such purpose only, all provisions of law relating to misdemeanors shall apply.