- Beeznest
* @package chamilo.auth
*/
if (isset($_REQUEST['action']) && Security::remove_XSS($_REQUEST['action']) !== 'subscribe') {
$stok = Security::get_token();
} else {
$stok = Security::getTokenFromSession();
}
$showCourses = CoursesAndSessionsCatalog::showCourses();
$showSessions = CoursesAndSessionsCatalog::showSessions();
$pageCurrent = isset($pageCurrent) ? $pageCurrent : isset($_GET['pageCurrent']) ? intval($_GET['pageCurrent']) : 1;
$pageLength = isset($pageLength) ? $pageLength : isset($_GET['pageLength']) ? intval($_GET['pageLength']) : CoursesAndSessionsCatalog::PAGE_LENGTH;
$pageTotal = intval(ceil(intval($countCoursesInCategory) / $pageLength));
$cataloguePagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($pageCurrent, $pageLength, $pageTotal) : '';
$searchTerm = isset($_REQUEST['search_term']) ? Security::remove_XSS($_REQUEST['search_term']) : '';
if ($showSessions && isset($_POST['date'])) {
$date = $_POST['date'];
} else {
$date = date('Y-m-d');
}
$userInfo = api_get_user_info();
$code = isset($code) ? $code : null;
?>
';
$form .= '
';
$form .= '
';
$form .= '
';
$form .= '
';
$form .= ''.get_lang('CourseCategories').' ';
$form .= '';
$codeType = isset($_REQUEST['category_code'])
? Security::remove_XSS($_REQUEST['category_code'])
: '';
foreach ($browse_course_categories[0] as $category) {
$categoryCode = $category['code'];
$countCourse = $category['count_courses'];
$form .= ''.$category['name'].' ('.$countCourse.') ';
if (!empty($browse_course_categories[$categoryCode])) {
foreach ($browse_course_categories[$categoryCode] as $subCategory) {
$subCategoryCode = $subCategory['code'];
$form .= '---'.$subCategory['name'].' ('.$subCategory['count_courses'].') ';
}
}
}
$form .= ' ';
$form .= '
';
$form .= '';
echo $form;
?>
".get_lang('SearchResultsFor')." ".$searchTerm." ";
}
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$user_id = api_get_user_id();
$categoryList = CourseManager::getCategoriesList();
if (!empty($browse_courses_in_category)) {
echo '';
foreach ($browse_courses_in_category as $course) {
$course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
if ($course_hidden) {
continue;
}
$userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
$userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
$userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
$course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
$course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
$course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
$course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
$course_subscribe_allowed = $course['subscribe'] == 1;
$course_unsubscribe_allowed = $course['unsubscribe'] == 1;
$count_connections = $course['count_connections'];
$creation_date = substr($course['creation_date'], 0, 10);
// display the course bloc
$html = '
';
$course['category_title'] = '';
if (isset($course['category'])) {
$course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
}
// display thumbnail
$html .= returnThumbnail($course, $userRegistered);
$separator = null;
$subscribeButton = return_register_button($course, $stok, $code, $searchTerm);
// start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
$course['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE
);
if ($isThisCourseInSale) {
// set the Price label
$separator = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$subscribeButton = $plugin->returnBuyCourseButton(
$course['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE
);
}
}
// end buycourse validation
// display course title and button bloc
$html .= '
';
$html .= return_title($course, $userRegisteredInCourse);
$html .= return_teacher($course);
// display button line
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
echo $html;
}
echo '
';
} else {
if (!isset($_REQUEST['subscribe_user_with_password']) &&
!isset($_REQUEST['subscribe_course'])
) {
echo Display::return_message(
get_lang('ThereAreNoCoursesInThisCategory'),
'warning'
);
}
}
}
echo '';
echo $cataloguePagination;
echo '
';
/**
* Display the course catalog image of a course
* @param array $course
* @param bool $registeredUser
*
* @return string HTML string
*/
function returnThumbnail($course, $registeredUser)
{
$html = '';
$title = cut($course['title'], 70);
$linkCourse = api_get_course_url($course['code']);
// course path
$course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
if (file_exists($course_path.'/course-pic.png')) {
$course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; // redimensioned image 85x85
} else {
// without picture
$course_medium_image = Display::return_icon(
'session_default.png',
null,
null,
null,
null,
true
);
}
$html .= '';
if (!$registeredUser) {
$html .= '
';
} else {
$html .= '
'
.' ';
}
$categoryTitle = isset($course['category_title']) ? $course['category_title'] : '';
if (!empty($categoryTitle)) {
$html .= '
'.$categoryTitle.' ';
$html .= '
';
}
$html .= '
';
$html .= return_description_button($course);
$html .= '
';
return $html;
}
/**
* @param array $courseInfo
* @return string
*/
function return_teacher($courseInfo)
{
$teachers = CourseManager::getTeachersFromCourse($courseInfo['real_id']);
$length = count($teachers);
if (!$length) {
return '';
}
$html = '';
foreach ($teachers as $value) {
$name = $value['firstname'].' '.$value['lastname'];
if ($length > 2) {
$html .= '
';
} else {
$html .= '
';
$html .= '
';
}
}
$html .= '
';
return $html;
}
/**
* Display the title of a course in course catalog
* @param array $course
* @param bool $registeredUser
*
* @return string HTML string
*/
function return_title($course, $registeredUser)
{
$html = '';
$linkCourse = api_get_course_url($course['code']);
$html .= '';
if (!$registeredUser) {
$html .= $course['title'];
} else {
$html .= ''.$course['title'].' ';
}
$html .= ' ';
if (api_get_configuration_value('hide_course_rating') === false) {
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$rating = Display::return_rating_system(
'star_'.$course['real_id'],
$ajax_url.'&course_id='.$course['real_id'],
$course['point_info']
);
$html .= ''.$rating.'
';
}
return $html;
}
/**
* Display the description button of a course in the course catalog
* @param array $course
*
* @return string HTML string
*/
function return_description_button($course)
{
$title = $course['title'];
$html = '';
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
$html = Display::url(
Display::returnFontAwesomeIcon('info-circle'),
api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&code='.$course['code'],
array(
'class' => 'ajax btn btn-default btn-sm',
'data-title' => $title,
'title' => get_lang('Description'),
'aria-label' => get_lang('Description'),
'data-size' => 'lg'
)
);
}
return $html;
}
/**
* Display the goto course button of a course in the course catalog
* @param $course
* @return string HTML string
*/
function return_goto_button($course)
{
$title = get_lang('GoToCourse');
$html = Display::url(
Display::returnFontAwesomeIcon('share'),
api_get_course_url($course['code']),
array(
'class' => 'btn btn-default btn-sm',
'title' => $title,
'aria-label' => $title,
)
);
return $html.PHP_EOL;
}
/**
* Display the already registerd text in a course in the course catalog
* @param $in_status
*
* @return string HTML string
*/
function return_already_registered_label($in_status)
{
$icon = ' ';
$title = get_lang("YouAreATeacherOfThisCourse");
if ($in_status == 'student') {
$icon = ' ';
$title = get_lang("AlreadySubscribed");
}
$html = Display::tag(
'span',
$icon.' '.$title,
array(
'id' => 'register',
'class' => 'label-subscribed text-success',
'title' => $title,
'aria-label' => $title,
)
);
return $html.PHP_EOL;
}
/**
* Display the register button of a course in the course catalog
* @param $course
* @param $stok
* @param $code
* @param $search_term
*
* @return string
*/
function return_register_button($course, $stok, $code, $search_term)
{
$title = get_lang('Subscribe');
$html = Display::url(
Display::returnFontAwesomeIcon('check').' '.$title,
api_get_self().'?action=subscribe_course&sec_token='.$stok.
'&subscribe_course='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
array('class' => 'btn btn-success btn-sm', 'title' => $title, 'aria-label' => $title)
);
return $html;
}
/**
* Display the unregister button of a course in the course catalog
* @param $course
* @param $stok
* @param $search_term
* @param $code
*
* @return string
*/
function return_unregister_button($course, $stok, $search_term, $code)
{
$title = get_lang('Unsubscription');
$html = Display::url(
Display::returnFontAwesomeIcon('sign-in').' '.$title,
api_get_self().'?action=unsubscribe&sec_token='.$stok
.'&unsubscribe='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
array('class' => 'btn btn-danger btn-sm', 'title' => $title, 'aria-label' => $title)
);
return $html;
}