text: 
  SELECT
    true
  
  FROM
    requirements
      JOIN courses ON courses.id = requirements.course AND courses.deleted = 0
      LEFT JOIN enrollments ON
        enrollments.id = $u[id] AND enrollments.course = courses.id AND
        enrollments.status = 1 AND enrollments.history = 0 AND
        enrollments.sdate <= $stamp AND (enrollments.edate > $stamp OR enrollments.edate = 0)
  
      LEFT JOIN members ON members.id = $u[id] AND members.status = 1 AND members.history = 0
      LEFT JOIN classes ON classes.id = members.class AND classes.course = courses.id AND classes.deleted = 0
  
      LEFT JOIN students as pvt ON
        pvt.id = $u[id] AND pvt.category = 'student' AND pvt.iid = requirements.id AND pvt.type = 'requirement' AND
        pvt.status = 1 AND pvt.history = 0 AND pvt.sdate <= $stamp AND (pvt.edate > $stamp OR pvt.edate = 0)
  
      LEFT JOIN students as cls ON
        cls.id = classes.id AND cls.category = 'group' AND cls.iid = requirements.id AND cls.type = 'requirement' AND
        cls.status = 1 AND cls.history = 0 AND cls.sdate <= $stamp AND (cls.edate > $stamp OR cls.edate = 0)
  
      LEFT JOIN students as pub ON
        pub.category = 'public' AND pub.iid = requirements.id AND pub.type = 'requirement' AND
        pub.status = 1 AND pub.sdate <= $stamp AND (pub.edate > $stamp OR pub.edate = 0) AND pub.history = 0
  
  WHERE
    (enrollments.allow = 1 OR (courses.public = 1 AND enrollments.allow IS NULL)) AND
    (
      (
        pvt.allow = 1 OR
        (cls.allow = 1 AND pvt.allow IS NULL) OR
        (pub.allow = 1 AND cls.allow IS NULL AND pvt.allow IS NULL)
      ) OR
      (
        requirements.public = 1 AND
        pub.allow IS NULL AND cls.allow IS NULL AND pvt.allow IS NULL
      )
    ) AND
    requirements.id = %d AND requirements.deleted = 0
  
  GROUP BY
    requirements.id;