text: 
  SET @comment = %d;
  
  SELECT
    replies.id, replies.description,
    CASE WHEN replies.file <> '' THEN true ELSE false END AS file,
    CASE WHEN replies.creator <> $u[id] THEN replies.sread ELSE false END AS sread,
    users.name as creator,
    users.img,
    replies.stamp
  
  FROM
    replies
      JOIN users ON users.id = replies.creator AND users.blocked = 0 AND users.deleted = 0
      JOIN comments ON comments.id = replies.comment AND comments.deleted = 0
      JOIN forums ON forums.id = comments.forum AND forums.deleted = 0
      JOIN courses ON courses.id = forums.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)
  
  WHERE
    replies.comment = @comment AND replies.deleted = 0 AND
    (enrollments.allow = 1 OR (courses.public = 1 AND enrollments.allow IS NULL))
  
  GROUP BY
    replies.id
  
  ORDER BY
    replies.stamp DESC,
    replies.creator,
    replies.id;
  
  
  UPDATE replies
    JOIN users ON users.id = replies.creator AND users.blocked = 0 AND users.deleted = 0
    JOIN comments ON comments.creator = $u[id] AND comments.id = replies.comment AND comments.deleted = 0
    JOIN forums ON forums.id = comments.forum AND forums.deleted = 0
    JOIN courses ON courses.id = forums.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)
  SET
    replies.sread = 1
  WHERE
    replies.comment = @comment AND replies.deleted = 0 AND
    (enrollments.allow = 1 OR (courses.public = 1 AND enrollments.allow IS NULL));