SQL: SELECT *, label AS label, (
ctrl_show = 1
AND (
((DATE_FORMAT(datetime_start,"%Y-%m-%d") >= DATE_FORMAT(NOW(),"%Y-%m-%d") OR datetime_start = "0000-00-00") AND datetime_end = "0000-00-00" )
OR
((DATE_FORMAT(datetime_end,"%Y-%m-%d") >= DATE_FORMAT(NOW(),"%Y-%m-%d") OR datetime_end = "0000-00-00") )
)
AND ( ctrl_show_from <= NOW() OR ( ctrl_show_from = "0000-00-00" OR ISNULL(ctrl_show_from) ) )
AND ( ctrl_show_until >= NOW() OR ( ctrl_show_until = "0000-00-00" OR ISNULL(ctrl_show_until) ) )
) AS is_active FROM event WHERE 1 AND ( ( 1 AND ( `assoc_localgroup_id` = 0 ) AND (
ctrl_show = 1
AND (
((DATE_FORMAT(datetime_start,"%Y-%m-%d") >= DATE_FORMAT(NOW(),"%Y-%m-%d") OR datetime_start = "0000-00-00") AND datetime_end = "0000-00-00" )
OR
((DATE_FORMAT(datetime_end,"%Y-%m-%d") >= DATE_FORMAT(NOW(),"%Y-%m-%d") OR datetime_end = "0000-00-00") )
)
AND ( ctrl_show_from <= NOW() OR ( ctrl_show_from = "0000-00-00" OR ISNULL(ctrl_show_from) ) )
AND ( ctrl_show_until >= NOW() OR ( ctrl_show_until = "0000-00-00" OR ISNULL(ctrl_show_until) ) )
) ) ) AND ctrl_deleted = 0 ORDER BY datetime_start