$conditions = array('where'=>array('active = ? AND session_id = ? AND c_id = ? '=>array('1', $session_id, $course_id)), 'order'=>'title');
$now = api_get_utc_datetime();
$time_conditions = '';
if ($check_publication_dates) {
$time_conditions = " AND ((start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now' ) OR
(start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time = '0000-00-00 00:00:00') OR
(start_time = '0000-00-00 00:00:00' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now')) ";
}
if ($session_id == 0) {
$conditions = array('where'=>array('active = ? AND session_id = ? AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order'=>'title');
} else {
//All exercises
$conditions = array('where'=>array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id = ? ' => array('1', $session_id, $course_id)), 'order'=>'title');
$conditions = array('where'=>array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order'=>'title');
$sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $condition_session $order";
$now = api_get_utc_datetime();
$time_conditions = '';
if ($check_publication_dates) {
$time_conditions = " AND ( (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR
(publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR
(publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now')) ";
}
$sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $time_conditions $condition_session $order";
$res = Database::query($sql);
$names = array();
while ($row = Database::fetch_array($res,'ASSOC')) {