* @author Julio Montoya - Cleaning code * @author Ricardo Rodriguez - Separated the function and code * */ require_once ('xajax/xajax.inc.php'); class Accessurleditcoursestourl { /** * Search for a list of available courses by title or code, based on * a given string * @param string String to search for * @param int Deprecated param * @return string A formatted, xajax answer block * @assert () === false */ public static function search_courses($needle, $id) { global $tbl_course; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = Database::escape_string($needle); // search courses where username or firstname or lastname begins likes $needle $sql = 'SELECT code, title FROM '.$tbl_course.' u '. ' WHERE (title LIKE "'.$needle.'%" '. ' OR code LIKE "'.$needle.'%" '. ' ) '. ' ORDER BY title, code '. ' LIMIT 11'; $rs = Database::query($sql); $i = 0; while ($course = Database :: fetch_array($rs)) { $i++; if ($i <= 10) { $return .= ''.$course['title'].' ('.$course['code'].')
'; } else { $return .= '...
'; } } } $xajax_response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return)); return $xajax_response; } }