Procedural File: main_api.lib.php
Source Location: /main/inc/lib/main_api.lib.php
Classes:
api_failure
collects and manage failures occuring during script execution The main purpose is allowing to manage the display messages externaly from functions or objects. This strengthens encupsalation principle
Page Details:
This is a code library for Dokeos.
It is included by default in every Dokeos file (through including the global.inc.php)
array $api_failureList [line 988]
CONFIGURATION_PATH [line 87]
COURSEMANAGER [line 50]
COURSE_VISIBILITY_CLOSED [line 54]
COURSE_VISIBILITY_OPEN_PLATFORM [line 58]
COURSE_VISIBILITY_OPEN_WORLD [line 60]
COURSE_VISIBILITY_REGISTERED [line 56]
DIR_HOTPOTATOES [line 135]
GARBAGE_PATH [line 80]
INCLUDE_PATH [line 85]
LIBRARY_PATH [line 86]
PLATFORM_AUTH_SOURCE [line 132]
PLUGIN_PATH [line 82]
REL_CLARO_PATH [line 74]
REL_COURSE_PATH [line 73]
REL_PATH [line 70]
SECTION_CAMPUS [line 124]
SECTION_COURSES [line 125]
SECTION_COURSE_ADMIN [line 128]
SECTION_MYAGENDA [line 127]
SECTION_MYPROFILE [line 126]
SECTION_PLATFORM_ADMIN [line 129]
STUDENT [line 48]
SUBSCRIBE_ALLOWED [line 62]
SUBSCRIBE_NOT_ALLOWED [line 63]
SYS_ARCHIVE_PATH [line 84]
SYS_CODE_PATH [line 76]
SYS_COURSE_PATH [line 72]
SYS_LANG_PATH [line 77]
SYS_PATH [line 69]
SYS_PLUGIN_PATH [line 81]
TOOL_ANNOUNCEMENT [line 96]
TOOL_BACKUP [line 111]
TOOL_BLOGS [line 104]
TOOL_CALENDAR_EVENT [line 92]
TOOL_CHAT [line 105]
TOOL_CONFERENCE [line 106]
TOOL_COPY_COURSE_CONTENT [line 112]
TOOL_COURSE_DESCRIPTION [line 94]
TOOL_COURSE_HOMEPAGE [line 114]
TOOL_COURSE_MAINTENANCE [line 117]
TOOL_COURSE_RIGHTS_OVERVIEW [line 115]
TOOL_COURSE_SETTING [line 110]
TOOL_DOCUMENT [line 90]
TOOL_DROPBOX [line 100]
TOOL_FORUM [line 97]
TOOL_GROUP [line 103]
TOOL_HOMEPAGE_LINK [line 109]
TOOL_HOTPOTATOES [line 91]
TOOL_LEARNPATH [line 95]
TOOL_LINK [line 93]
TOOL_POST [line 99]
TOOL_QUIZ [line 101]
TOOL_RECYCLE_COURSE [line 113]
TOOL_STUDENTPUBLICATION [line 107]
TOOL_SURVEY [line 121]
TOOL_THREAD [line 98]
TOOL_TRACKING [line 108]
TOOL_UPLOAD [line 116]
TOOL_USER [line 102]
TOOL_VISIO [line 118]
TOOL_VISIO_CLASSROOM [line 120]
TOOL_VISIO_CONFERENCE [line 119]
UNSUBSCRIBE_ALLOWED [line 64]
UNSUBSCRIBE_NOT_ALLOWED [line 65]
WEB_CODE_PATH [line 75]
WEB_COURSE_PATH [line 71]
WEB_CSS_PATH [line 79]
WEB_IMG_PATH [line 78]
WEB_PATH [line 68]
WEB_PLUGIN_PATH [line 83]
api_add_url_param [line 707]
void api_add_url_param(
$url, $param)
|
|
Parameters
api_block_anonymous_users [line 188]
void api_block_anonymous_users(
)
|
|
Function used to prevent anonymous users from accessing a script.
Tags:
api_check_password [line 770]
true api_check_password(
string $password)
|
|
Checks a password to see wether it is OK to use.
Tags:
Parameters
api_clear_anonymous [line 819]
bool api_clear_anonymous(
[bool $db_check = false])
|
|
Clear the user ID from the session if it was the anonymous user. Generally used on out-of-tools pages to remove a user ID that could otherwise be used in the wrong context. This function is to be used in conjunction with the api_set_anonymous() function to simulate the user existence in case of an anonymous visit.
Tags:
Parameters
| bool |
$db_check |
database check switch - passed to api_is_anonymous() |
api_display_array [line 1325]
void api_display_array(
array $info_array)
|
|
Displays the contents of an array in a messagebox.
Parameters
| array |
$info_array |
An array with the messages to show |
api_display_debug_info [line 1339]
void api_display_debug_info(
string $debug_info)
|
|
Displays debug info
Tags:
Parameters
| string |
$debug_info |
The message to display |
api_display_language_form [line 1671]
void api_display_language_form(
)
|
|
Displays a form (drop down menu) so the user can select his/her preferred language. The form works with or without javascript
api_display_tool_title [line 1217]
void api_display_tool_title(
mixed $titleElement)
|
|
Displays the title of a tool. Normal use: parameter is a string: api_display_tool_title("My Tool") Optionally, there can be a subtitle below the normal title, and / or a supra title above the normal title. e.g. supra title: group GROUP PROPERTIES e.g. subtitle: AGENDA calender & events tool
Tags:
Parameters
| mixed |
$titleElement |
- it could either be a string or an array containing 'supraTitle', 'mainTitle', 'subTitle' |
api_display_tool_view_option [line 1263]
void api_display_tool_view_option(
)
|
|
Display options to switch between student view and course manager view Changes in version 1.2 (Patrick Cool) Student view switch now behaves as a real switch. It maintains its current state until the state is changed explicitly Changes in version 1.1 (Patrick Cool) student view now works correctly in subfolders of the document tool student view works correctly in the new links tool Example code for using this in your tools: //if ( $is_courseAdmin && api_get_setting('show_student_view') == 'true' ) //{ // display_tool_view_option($isStudentView); //} //and in later sections, use api_is_allowed_to_edit()
Tags:
api_disp_html_area [line 1745]
void api_disp_html_area(
string $name, [string $content = ''], [int $height = ''], [int $width = '100%'], [string $optAttrib = ''])
|
|
Displays the FckEditor WYSIWYG editor for online editing of html
Parameters
| string |
$name |
The name of the form-element |
| string |
$content |
The default content of the html-editor |
| int |
$height |
The height of the form element |
| int |
$width |
The width of the form element |
| string |
$optAttrib |
optional attributes for the form element |
api_generate_password [line 751]
string api_generate_password(
[ $length = 8], int $length,)
|
|
Returns a difficult to guess password.
Tags:
Parameters
| int |
$length, |
the length of the password |
| |
$length |
|
api_get_anonymous_id [line 480]
int api_get_anonymous_id(
)
|
|
Gets an anonymous user ID For some tools that need tracking, like the learnpath tool, it is necessary to have a usable user-id to enable some kind of tracking, even if not perfect. An anonymous ID is taken from the users table by looking for a status of "6" (anonymous).
Tags:
api_get_cidreq [line 500]
Returns the cidreq parameter name + current course id
api_get_course_id [line 438]
void api_get_course_id(
)
|
|
Returns the current course id (integer)
api_get_course_info [line 527]
void api_get_course_info(
)
|
|
Returns the current course info array. Note: this array is only defined if the user is inside a course. Array elements: ['name'] ['official_code'] ['sysCode'] ['path'] ['dbName'] ['dbNameGlu'] ['titular'] ['language'] ['extLink']['url' ] ['extLink']['name'] ['categoryCode'] ['categoryName']
Tags:
api_get_course_path [line 449]
string api_get_course_path(
)
|
|
Returns the current course directory This function relies on api_get_course_info()
Tags:
api_get_course_setting [line 459]
mixed api_get_course_setting(
string $setting_name)
|
|
Gets a course setting from the current course_setting table. Try always using integer values.
Tags:
Parameters
| string |
$setting_name |
The name of the setting we want from the table |
api_get_interface_language [line 1119]
string api_get_interface_language(
)
|
|
Gets the current interface language
Tags:
api_get_languages [line 1717]
array api_get_languages(
)
|
|
Return a list of all the languages that are made available by the admin.
Tags:
api_get_last_failure [line 955]
string api_get_last_failure(
[void 0 = ])
|
|
get the last failure stored in $api_failureList;
Tags:
Parameters
api_get_navigator [line 209]
api_get_path [line 281]
void api_get_path(
one $path_type)
|
|
Returns a full path to a certain Dokeos area, which you specify through a parameter. See $_configuration['course_folder'] in the configuration.php to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters.
Tags:
Parameters
| one |
$path_type |
of the following constants: WEB_PATH, SYS_PATH, REL_PATH, WEB_COURSE_PATH, SYS_COURSE_PATH, REL_COURSE_PATH, REL_CLARO_PATH, WEB_CODE_PATH, SYS_CODE_PATH, SYS_LANG_PATH, WEB_IMG_PATH, GARBAGE_PATH, PLUGIN_PATH, SYS_ARCHIVE_PATH, INCLUDE_PATH, LIBRARY_PATH, CONFIGURATION_PATH |
api_get_self [line 1041]
Returns an escaped version of $_SERVER['PHP_SELF'] to avoid XSS injection
Tags:
api_get_setting [line 1031]
void api_get_setting(
$variable, [ $key = NULL])
|
|
Returns the value of a setting from the web-adjustable admin config settings. WARNING true/false are stored as string, so when comparing you need to check e.g. if(api_get_setting("show_navigation_menu") == "true") //CORRECT instead of if(api_get_setting("show_navigation_menu") == true) //INCORRECT
Tags:
Parameters
api_get_user_id [line 390]
integer api_get_user_id(
)
|
|
This function returns the id of the user which is stored in the $_user array.
Tags:
api_get_user_info [line 405]
$user_info api_get_user_info(
[$user_id $user_id = ''])
|
|
find all the information about a user. If no paramater is passed you find all the information about the current user.
Tags:
Parameters
| $user_id |
$user_id |
(integer): the id of the user |
api_is_allowed [line 1384]
void api_is_allowed(
$tool $tool, $action $action, [ $task_id = 0])
|
|
this fun
Tags:
Parameters
| $tool |
$tool |
the tool we are checking ifthe user has a certain permission |
| $action |
$action |
the action we are checking (add, edit, delete, move, visibility) |
| |
$task_id |
|
api_is_allowed_to_create_course [line 1144]
boolean api_is_allowed_to_create_course(
)
|
|
Check if current user is allowed to create courses
Tags:
api_is_allowed_to_edit [line 1363]
boolean, api_is_allowed_to_edit(
)
|
|
Function that removes the need to directly use is_courseAdmin global in tool scripts. It returns true or false depending on the user's rights in this particular course.
Tags:
api_is_anonymous [line 1459]
bool api_is_anonymous(
[int $user_id = null], [bool $db_check = false])
|
|
Tells whether this user is an anonymous user
Tags:
Parameters
| int |
$user_id |
User ID (optional, will take session ID if not provided) |
| bool |
$db_check |
Whether to check in the database (true) or simply in the session (false) to see if the current user is the anonymous user |
api_is_coach [line 1160]
Check if the current user is a course or session coach
Tags:
api_is_course_admin [line 1152]
boolean api_is_course_admin(
)
|
|
Check if the current user is a course administrator
Tags:
api_is_platform_admin [line 1135]
boolean api_is_platform_admin(
)
|
|
Check if current user is a platform administrator
Tags:
api_is_plugin_installed [line 1878]
boolean api_is_plugin_installed(
$plugin_list, $plugin_name)
|
|
Checks to see wether a certain plugin is installed.
Tags:
Parameters
| |
$plugin_list |
|
| |
$plugin_name |
|
api_is_self_registration_allowed [line 243]
True api_is_self_registration_allowed(
)
|
|
Tags:
api_item_property_update [line 1585]
boolean api_item_property_update(
$_course $_course, $tool $tool, $item_id $item_id, $lastedit_type $lastedit_type, $user_id $user_id, [$to_group_id $to_group_id = 0], [$to_user_id $to_user_id = NULL], [string $start_visible = 0], [unknown_type $end_visible = 0])
|
|
update the item_properties table (if entry not exists, insert) of the course
Tags:
Parameters
| string |
$start_visible |
0000-00-00 00:00:00 format |
| unknown_type |
$end_visible |
0000-00-00 00:00:00 format |
| $_course |
$_course |
: array with course properties |
| $tool |
$tool |
: tool id, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!) |
| $item_id |
$item_id |
: id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool |
| $lastedit_type |
$lastedit_type |
: add or update action (1) message to be translated (in trad4all) : e.g. DocumentAdded, DocumentUpdated; (2) "delete"; (3) "visible"; (4) "invisible"; |
| $user_id |
$user_id |
: id of the editing/adding user |
| $to_group_id |
$to_group_id |
: id of the intended group ( 0 = for everybody), only relevant for $type (1) |
| $to_user_id |
$to_user_id |
: id of the intended user (always has priority over $to_group_id !), only relevant for $type (1) |
api_max_sort_value [line 1805]
int api_max_sort_value(
$user_course_category, $user_id, int $user_course_category:)
|
|
Find the largest sort value in a given user_course_category This function is used when we are moving a course to a different category and also when a user subscribes to a courses (the new courses is added to the end of the main category
Tags:
Parameters
| int |
$user_course_category: |
the id of the user_course_category |
| |
$user_course_category |
|
| |
$user_id |
|
api_not_allowed [line 1495]
void api_not_allowed(
[bool $print_headers = false])
|
|
Displays message "You are not allowed here..." and exits the entire script.
Tags:
Parameters
| bool |
$print_headers |
Whether or not to print headers (default = false -> does not print them) |
api_number_of_plugins [line 1847]
void api_number_of_plugins(
$location)
|
|
Determines the number of plugins installed for a given location
Parameters
api_parse_tex [line 1895]
string api_parse_tex(
$textext, string $text)
|
|
Apply parsing to content to parse tex commandos that are seperated by [tex] [/tex] to make it readable for techexplorer plugin.
Tags:
Parameters
| string |
$text |
The text to parse |
| |
$textext |
|
api_plugin [line 1861]
void api_plugin(
$location)
|
|
including the necessary plugins
Tags:
Parameters
api_protect_admin_script [line 174]
void api_protect_admin_script(
)
|
|
Function used to protect an admin script. The function blocks access when the user has no platform admin rights. This is only the first proposal, test and improve!
Tags:
api_protect_course_script [line 155]
void api_protect_course_script(
[boolean $print_headers = false])
|
|
Function used to protect a course script. The function blocks access when - there is no $_SESSION["_course"] defined; or
- $is_allowed_in_course is set to false (this depends on the course
visibility and user status). This is only the first proposal, test and improve!
Tags:
Parameters
| boolean |
$print_headers |
Option to print headers when displaying error message. Default: false |
api_return_html_area [line 1761]
void api_return_html_area(
$name, [ $content = ''], [ $height = ''], [ $width = '100%'], [ $optAttrib = ''])
|
|
Parameters
| |
$name |
|
| |
$content |
|
| |
$height |
|
| |
$width |
|
| |
$optAttrib |
|
api_send_mail [line 1791]
void api_send_mail(
string $to, string $subject, string $message, [string $additional_headers = null], [string $additional_parameters = null])
|
|
Send an email. Wrapper function for the standard php mail() function. Change this function to your needs. The parameters must follow the same rules as the standard php mail() function. Please look at the documentation on http: //www. php. net/manual/en/function. mail.php
Parameters
| string |
$to |
|
| string |
$subject |
|
| string |
$message |
|
| string |
$additional_headers |
|
| string |
$additional_parameters |
|
api_session_clear [line 684]
void api_session_clear(
)
|
|
Clear the session
Tags:
api_session_destroy [line 695]
void api_session_destroy(
)
|
|
Destroy the session
Tags:
api_session_register [line 661]
void api_session_register(
string $variable)
|
|
save a variable into the session BUG: function works only with global variables
Tags:
Parameters
| string |
$variable |
variable - the variable name to save into the session |
api_session_start [line 613]
void api_session_start(
[string $already_installed = true])
|
|
Start the Dokeos session. The default lifetime for session is set here. It is not possible to have it as a database setting as it is used before the database connection has been made. It is taken from the configuration file, and if it doesn't exist there, it is set to 360000 seconds
Tags:
Parameters
| string |
$already_installed |
variable - the variable name to save into the session |
api_session_unregister [line 673]
void api_session_unregister(
string $variable)
|
|
Remove a variable from the session.
Tags:
Parameters
| string |
$variable |
variable - the variable name to remove from the session |
api_set_anonymous [line 923]
bool api_set_anonymous(
)
|
|
Sets the current user as anonymous if it hasn't been identified yet. This function should be used inside a tool only. The function api_clear_anonymous() acts in the opposite direction by clearing the anonymous user's data every time we get on a course homepage or on a neutral page (index, admin, my space)
Tags:
api_set_failure [line 909]
bolean api_set_failure(
string $failureType)
|
|
Fills a global array called $api_failureList This array collects all the failure occuring during the script runs The main purpose is allowing to manage the display messages externaly from the functions or objects. This strengthens encupsalation principle
Tags:
Parameters
| string |
$failureType |
- the type of failure |
api_sql_query [line 548]
resource api_sql_query(
string $query, [string $file = ''], [string $line = 0])
|
|
Executes an SQL query You have to use addslashes() on each value that you want to record into the database
Tags:
Parameters
| string |
$query |
- SQL query |
| string |
$file |
- optional, the file path and name of the error (__FILE__) |
| string |
$line |
- optional, the line of the error (__LINE__) |
api_store_result [line 587]
array api_store_result(
resource $result)
|
|
Store the result of a query into an array
Tags:
Parameters
| resource |
$result |
- the return value of the query |
api_time_to_hms [line 1915]
string api_time_to_hms(
integer $seconds)
|
|
Transform a number of seconds in hh:mm:ss format
Tags:
Parameters
| integer |
$seconds |
the number of seconds |
api_trunc_str [line 843]
void api_trunc_str(
string $text, [integer $length = 30], [string $endStr = '...'], [boolean $middle = false])
|
|
truncates a string
Tags:
Parameters
| string |
$text |
text - text to truncate |
| integer |
$length |
length - length of the truncated text |
| string |
$endStr |
endStr - suffix |
| boolean |
$middle |
middle - if true, truncates on string middle |
convert_mysql_date [line 1557]
unix convert_mysql_date(
$last_post_datetime $last_post_datetime)
|
|
convert sql date to unix timestamp
Tags:
Parameters
| $last_post_datetime |
$last_post_datetime |
standard output date in a sql query |
copyr [line 1947]
void copyr(
the $source, the $dest, [an $exclude = array()], [copied_files $copied_files = array()])
|
|
function adapted from a php.net comment copy recursively a folder
Parameters
| the |
$source |
source folder |
| the |
$dest |
dest folder |
| an |
$exclude |
array of excluded file_name (without extension) |
| copied_files |
$copied_files |
the returned array of copied files |
domesticate [line 875]
void domesticate(
string $input)
|
|
handling simple and double apostrofe in order that strings be stored properly in database
Tags:
Parameters
| string |
$input |
variable - the variable to be revised |
get_lang [line 1062]
language get_lang(
$variable, [ $notrans = 'DLTT'])
|
|
Whenever the server type in the Dokeos Config settings is set to test/development server you will get an indication that a language variable is not translated and a link to a suggestions form of DLTT.
Tags:
Parameters
get_setting [line 1014]
void get_setting(
$variable, [ $key = NULL])
|
|
DEPRECATED, use api_get_setting instead
Parameters
is_allowed_to_edit [line 1348]
void is_allowed_to_edit(
)
|
|
shorten [line 860]
void shorten(
$input, [ $length = 15])
|
|
Parameters
string_2_boolean [line 1832]
boolean string_2_boolean(
string $string)
|
|
This function converts the string "true" or "false" to a boolean true or false. This function is in the first place written for the Dokeos Config Settings (also named AWACS)
Tags:
Parameters
| string |
$string |
"true" or "false" |
|