function controlCourse($course_info, $page, $id_catalogue, $id_category, $ini)
{
    require_once _lms_ . '/lib/lib.course.php';
    $acl_manger = Docebo::user()->getAclManager();
    $lang =& DoceboLanguage::CreateInstance('catalogue', 'cms');
    if ($course_info['course_type'] !== 'elearning') {
        if (!isset($course_info['dates'])) {
            return '<p class="cannot_subscribe">' . $lang->def('_NO_EDITIONS') . '</p>';
        } elseif (count($course_info['dates']) == 0) {
            return '<p class="cannot_subscribe">' . $lang->def('_NO_EDITIONS') . '</p>';
        }
        require_once _lms_ . '/lib/lib.date.php';
        $man_date = new DateManager();
        $user_date = $man_date->getUserDates(getLogUserId());
        $date_id = array();
        $date_full = $man_date->getFullDateForCourse($course_info['idCourse']);
        $date_not_confirmed = $man_date->getNotConfirmetDateForCourse($course_info['idCourse']);
        foreach ($course_info['dates'] as $date_info) {
            $date_id[] = $date_info['id_date'];
        }
        reset($course_info['dates']);
        $control = array_diff($date_id, $user_date, $date_full, $date_not_confirmed);
        if (count($control) == 0) {
            return '<p class="cannot_subscribe">' . $lang->def('_NO_EDITIONS') . '</p>';
        }
        if ($course_info['selling'] == 0) {
            if (Docebo::user()->isAnonymous()) {
                return '<p class="cannot_subscribe">' . $lang->def('_NEED_TO_LOGIN') . '</p>';
            } else {
                return '<a href="javascript:;" onClick="datePrenotationPopUp(\'' . $course_info['idCourse'] . '\', \'' . $lang->def('_CHART_EDITION_FOR') . ' : ' . addslashes($course_info['name']) . '\')"><p class="can_subscribe">' . $lang->def('_CAN_SUBSCRIBE') . '</p></a>';
            }
        } else {
            $date_in_chart = array();
            if (isset($_SESSION['chart'][$course_info['idCourse']])) {
                $date_in_chart = $_SESSION['chart'][$course_info['idCourse']]['dates'];
            }
            $control = array_diff($control, $date_in_chart);
            if (count($control) == 0) {
                return '<p class="subscribed">' . $lang->def('_ALL_EDITION_BUYED') . '</p>';
            }
            $query = "SELECT id_date" . " FROM " . $GLOBALS['prefix_lms'] . "_transaction_info" . " WHERE id_course = " . $course_info['idCourse'] . " AND id_transaction IN" . " (" . " SELECT id_transaction" . " FROM " . $GLOBALS['prefix_lms'] . "_transaction" . " WHERE id_user = "******" AND status = 0" . " )";
            $res = sql_query($query);
            if (sql_num_rows($res)) {
                $waiting_payment = array();
                while (list($id_date) = sql_fetch_row($query)) {
                    $waiting_payment[$id_date] = $id_date;
                }
                $control = array_diff($control, $waiting_payment);
                if (count($control) == 0) {
                    return '<p class="subscribed">' . $lang->def('_WAITING_PAYMENT_FOL_LAST_EDITION') . '</p>';
                }
            }
            return '<a href="javascript:;" onClick="datePrenotationPopUp(\'' . $course_info['idCourse'] . '\', \'' . $lang->def('_CHART_EDITION_FOR') . ' : ' . addslashes($course_info['name']) . '\')"><p class="can_subscribe">' . $lang->def('_CAN_SUBSCRIBE') . '</p></a>';
        }
    } else {
        $course_in_chart = array_keys($_SESSION['chart']);
        if (array_search($course_info['idCourse'], $course_in_chart) !== false) {
            return '<p class="subscribed">' . $lang->def('_COURSE_IN_CART') . '</p>';
        }
        $query = "SELECT status, waiting" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idCourse = " . $course_info['idCourse'] . " AND idUser = "******"subscribed">' . $lang->def('_WAITING') . '</p>';
            } else {
                return '<p class="subscribed">' . $lang->def('_USER_STATUS_SUBS') . '</p>';
            }
        }
        if ($course_info['max_num_subscribe'] !== 0) {
            $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "courseuser" . " WHERE idCourse = " . $course_info['idCourse'];
            list($control) = sql_fetch_row(sql_query($query));
            if ($control >= $course_info['max_num_subscribe']) {
                return '<p class="cannot_subscribe">' . $lang->def('_MAX_NUM_SUBSCRIBE') . '</p>';
            }
        }
        if ($course_info['selling'] == 0) {
            if (Docebo::user()->isAnonymous()) {
                return '<p class="cannot_subscribe">' . $lang->def('_NEED_TO_LOGIN') . '</p>';
            } else {
                return '<a href="index.php?pag=' . $page . '&amp;id_catalogue=' . $id_catalogue . ($id_category != 0 ? '&amp;id_cat=' . $id_category : '') . '&amp;id_course=' . $course_info['idCourse'] . '&amp;ini=' . $ini . '&amp;action=subscribe"><p class="can_subscribe">' . $lang->def('_CAN_SUBSCRIBE') . '</p></a>';
            }
        } else {
            $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_transaction_info" . " WHERE id_date = 0" . " AND id_course = " . $course_info['idCourse'] . " AND id_transaction IN" . " (" . " SELECT id_transaction" . " FROM " . $GLOBALS['prefix_lms'] . "_transaction" . " WHERE id_user = "******" AND status = 0" . " )";
            list($control) = sql_fetch_row(sql_query($query));
            if ($control > 0) {
                return '<p class="subscribed">' . $lang->def('_WAITING_PAYMENT') . '</p>';
            }
            return '<a href="index.php?pag=' . $page . '&amp;id_catalogue=' . $id_catalogue . ($id_category != 0 ? '&amp;id_cat=' . $id_category : '') . '&amp;id_course=' . $course_info['idCourse'] . '&amp;ini=' . $ini . '"><p class="can_subscribe">' . $lang->def('_CAN_SUBSCRIBE') . '</p></a>';
        }
    }
}