0) {
while ($row = Database::fetch_row($res)) {
$course_codes .= '\''.$row[0].'\',';
}
$course_codes = substr($course_codes,0,(strlen($course_codes)-1));
$cond_course_code = ' AND course.id NOT IN('.$course_codes.') ';
}
}
if ($type=='single') {
// search users where username or firstname or lastname begins likes $needle
$sql = 'SELECT
course.code,
course.visual_code,
course.title,
session_rel_course.session_id
FROM '.$tbl_course.' course
LEFT JOIN '.$tbl_session_rel_course.' session_rel_course
ON course.id = session_rel_course.c_id
AND session_rel_course.session_id = '.intval($id_session).'
WHERE
course.visual_code LIKE "'.$needle.'%" OR
course.title LIKE "'.$needle.'%"';
} else {
$sql = 'SELECT course.code, course.visual_code, course.title
FROM '.$tbl_course.' course
WHERE
course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
ORDER BY course.code ';
}
if (api_is_multiple_url_enabled()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1){
if ($type=='single') {
$sql = 'SELECT
course.code,
course.visual_code,
course.title,
session_rel_course.session_id
FROM '.$tbl_course.' course
LEFT JOIN '.$tbl_session_rel_course.' session_rel_course
ON course.id = session_rel_course.c_id
AND session_rel_course.session_id = '.intval($id_session).'
INNER JOIN '.$tbl_course_rel_access_url.' url_course
ON (url_course.c_id = course.id)
WHERE
access_url_id = '.$access_url_id.' AND
(course.visual_code LIKE "'.$needle.'%" OR
course.title LIKE "'.$needle.'%" )';
} else {
$sql = 'SELECT course.code, course.visual_code, course.title
FROM '.$tbl_course.' course, '.$tbl_course_rel_access_url.' url_course
WHERE
url_course.c_id = course.id AND
access_url_id = '.$access_url_id.' AND
course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
ORDER BY course.code ';
}
}
}
$rs = Database::query($sql);
$course_list = array();
if ($type=='single') {
while($course = Database :: fetch_array($rs)) {
$course_list[] = $course['code'];
$course_title=str_replace("'","\'",$course_title);
$return .= ''.$course['title'].' ('.$course['visual_code'].')
';
}
$xajax_response -> addAssign('ajax_list_courses_single','innerHTML',api_utf8_encode($return));
} else {
$return .= '';
$xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
}
}
$_SESSION['course_list'] = $course_list;
return $xajax_response;
}
}