$course_title = Database::result(Database::query('SELECT title FROM '.$TABLECOURSE.
$course_title = Database::result(Database::query('SELECT title FROM '.$TABLECOURSE.' WHERE code="'.$course_code.'"'), 0, 0);
' WHERE code="'.$course_code.'"'), 0, 0);
$result = Database::query('SELECT course.code as code, course.title as title, cu.sort as sort FROM '.$TABLECOURSUSER.' as cu, '.$TABLECOURSE.' as course
$sql = 'SELECT course.code as code, course.title as title, cu.sort as sort FROM '.$TABLECOURSUSER.' as cu, '.$TABLECOURSE.' as course
WHERE course.code = cu.course_code
WHERE course.code = cu.course_code AND user_id = "'.$user_id.'" AND
AND user_id = "'.$user_id.'"
cu.relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND
AND cu.relation_type<>'.COURSE_RELATION_TYPE_RRHH.'
user_course_cat = 0
AND user_course_cat=0 ORDER BY cu.sort');
ORDER BY cu.sort';
$result = Database::query($sql);
$course_title_precedent = '';
$course_title_precedent = '';
$counter = 0;
$counter = 0;
$course_found = false;
$course_found = false;
$course_sort = 1;
$course_sort = 1;
while ($courses = Database::fetch_array($result)){
if (Database::num_rows($result) > 0) {
while ($courses = Database::fetch_array($result)) {
if ($course_title_precedent == '') {
if ($course_title_precedent == '') {
$course_title_precedent = $courses['title'];
$course_title_precedent = $courses['title'];
}
}
if (api_strcasecmp($course_title_precedent, $course_title) <0){
if (api_strcasecmp($course_title_precedent, $course_title) <0){
$course_found = true;
$course_sort = $courses['sort'];
$course_found = true;
if ($counter == 0) {
$course_sort = $courses['sort'];
$sql = 'UPDATE '.$TABLECOURSUSER.' SET sort = sort+1 WHERE user_id= "'.$user_id.'" AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND user_course_cat="0" AND sort > "'.$course_sort.'"';
$course_sort++;
} else {
$sql = 'UPDATE '.$TABLECOURSUSER.' SET sort = sort+1 WHERE user_id= "'.$user_id.'" AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND user_course_cat="0" AND sort >= "'.$course_sort.'"';
}
Database::query($sql);
break;
if ($counter == 0) {
$sql = 'UPDATE '.$TABLECOURSUSER.' SET sort = sort+1 WHERE user_id= "'.$user_id.'" AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND user_course_cat="0" AND sort > "'.$course_sort.'"';
$course_sort++;
} else {
} else {
$sql = 'UPDATE '.$TABLECOURSUSER.' SET sort = sort+1 WHERE user_id= "'.$user_id.'" AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND user_course_cat="0" AND sort >= "'.$course_sort.'"';
$course_title_precedent = $courses['title'];
}
}
$counter++;
Database::query($sql);
break;
} else {
$course_title_precedent = $courses['title'];
}
}
$counter++;
// We must register the course in the beginning of the list
}
if (!$course_found) {
$course_sort = Database::result(Database::query('SELECT min(sort) as min_sort FROM '.$TABLECOURSUSER.' WHERE user_id="'.$user_id.'" AND user_course_cat="0"'), 0, 0);
// We must register the course in the beginning of the list
Database::query('UPDATE '.$TABLECOURSUSER.' SET sort = sort+1 WHERE user_id= "'.$user_id.'" AND user_course_cat="0"');
if (Database::num_rows($result) > 0 && !$course_found) {
}
$course_sort = Database::result(Database::query('SELECT min(sort) as min_sort FROM '.$TABLECOURSUSER.
' WHERE user_id="'.$user_id.'" AND user_course_cat="0"'), 0, 0);
Database::query('UPDATE '.$TABLECOURSUSER.' SET sort = sort+1
WHERE user_id= "'.$user_id.'" AND user_course_cat="0"');