Using the API
From Dokeos
Contents |
Course API
user / course relations
Is a user subscribed in a course?
$course_info['code'] = $dokeos_course_code; CourseManager::is_user_subscribed_in_course($user_id, $course_info);
Subscribe a user in a course
CourseManager::add_user_to_course($user_id, $course_code);
Get the status of a user inside a certain course:
$status = CourseManager::get_user_in_course_status($user_id, $course_code);
if ($status == COURSEMANAGER)
{
...
}
else if ($status == STUDENT)
{
...
}
Change the status of a user inside a certain course: (function available starting from Dokeos 1.7, in cvs now)
$status = COURSEMANAGER; // or STUDENT CourseManager::set_user_in_course_status($user_id, $course_code, $status);
Display API
Displaying messages
Use the following functions
Display::display_normal_message($message) Display::display_error_message($message)
The layout of these messages is decided by the stylesheets (default.css for screen display).
Database API
The database.lib.php contains the database library. It is included by default when including the claro_init_global.inc.php.
How to get a table name
Use one of the functions
Database::get_main_table($short_table_name) Database::get_course_table($short_table_name, $database_name = '') Database::get_statistic_table($short_table_name)
You use one of these functions and specify with a parameter which table you want. These are constants for all tables inside the database.lib.php. A few examples:
//main database tables
define("MAIN_COURSE_TABLE", "course");
define("MAIN_USER_TABLE", "user");
//statistic database tables
define("STATISTIC_TRACK_E_LOGIN_TABLE", "track_e_login");
//course tables
define("AGENDA_TABLE", "calendar_event");
define("ANNOUNCEMENT_TABLE", "announcement");
Group API
Main API
This is the main, basic code library for Dokeos. In here you'll find important functions dealing with sessions and protections.
Protecting scripts
If you are improving the code of an existing course tool, or creating your own new course tool, you should protect it by using the function api_protect_course_script().
This function can best be placed directly after the include of the global init stuff, for example as in the documents tool:
$langFile = "document";
include("../inc/claro_init_global.inc.php");
api_protect_course_script();
Similarly, when working on an admin script be sure to use the protection function api_protect_admin_script():
include ('../inc/claro_init_global.inc.php');
api_protect_admin_script();
Without this line of code, anyone will be able to just surf to the page without being stopped...
To block a more general script from access by anonymous users, you can use the function api_block_anonymous_users():
include ('../inc/claro_init_global.inc.php');
api_block_anonymous_users();
You shouldn't use this function in course or admin scripts, there you should use the more specific api_protect_course_script() and api_protect_admin_script(), respectively.

