📄 main_api.lib.php
字号:
<?php/*=============================================================================== Dokeos - elearning and course management software Copyright (c) 2004-2008 Dokeos S.A. Copyright (c) 2003 Ghent University (UGent) Copyright (c) 2001 Universite catholique de Louvain (UCL) Copyright (c) Hugues Peeters Copyright (c) Christophe Gesche Copyright (c) Roan Embrechts (Vrije Universiteit Brussel) Copyright (c) Patrick Cool Copyright (c) Olivier Brouckaert Copyright (c) Toon Van Hoecke Copyright (c) Denes Nagy For a full list of contributors, see "credits.txt". The full license can be read in "license.txt". This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the GNU General Public License for more details. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium Mail: info@dokeos.com===============================================================================*//**==============================================================================* This is a code library for Dokeos.* It is included by default in every Dokeos file* (through including the global.inc.php)** @package dokeos.library==============================================================================*//*============================================================================== CONSTANTS==============================================================================*///USER STATUS CONSTANTS/** global status of a user: student */define('STUDENT', 5);/** global status of a user: course manager */define('COURSEMANAGER', 1);/** global status of a user: session admin */define('SESSIONADMIN', 3);/** global status of a user: human ressource manager */define('DRH', 4);/** global status of a user: human ressource manager */define('ANONYMOUS', 6);// table of status$_status_list[STUDENT] = 'user';$_status_list[COURSEMANAGER] = 'teacher';$_status_list[SESSIONADMIN] = 'session_admin';$_status_list[DRH] = 'drh';$_status_list[ANONYMOUS] = 'anonymous';//COURSE VISIBILITY CONSTANTS/** only visible for course admin */define('COURSE_VISIBILITY_CLOSED', 0);/** only visible for users registered in the course*/define('COURSE_VISIBILITY_REGISTERED', 1);/** open for all registered users on the platform */define('COURSE_VISIBILITY_OPEN_PLATFORM', 2);/** open for the whole world */define('COURSE_VISIBILITY_OPEN_WORLD', 3);define('SUBSCRIBE_ALLOWED', 1);define('SUBSCRIBE_NOT_ALLOWED', 0);define('UNSUBSCRIBE_ALLOWED', 1);define('UNSUBSCRIBE_NOT_ALLOWED', 0);//CONSTANTS FOR api_get_path FUNCTIONdefine('WEB_PATH', 'WEB_PATH');define('SYS_PATH', 'SYS_PATH');define('REL_PATH', 'REL_PATH');define('WEB_COURSE_PATH', 'WEB_COURSE_PATH');define('SYS_COURSE_PATH', 'SYS_COURSE_PATH');define('REL_COURSE_PATH', 'REL_COURSE_PATH');define('REL_CODE_PATH', 'REL_CODE_PATH');define('WEB_CODE_PATH', 'WEB_CODE_PATH');define('SYS_CODE_PATH', 'SYS_CODE_PATH');define('SYS_LANG_PATH', 'SYS_LANG_PATH');define('WEB_IMG_PATH', 'WEB_IMG_PATH');define('WEB_CSS_PATH', 'WEB_CSS_PATH');define('GARBAGE_PATH', 'GARBAGE_PATH');define('SYS_PLUGIN_PATH', 'SYS_PLUGIN_PATH');define('PLUGIN_PATH', 'PLUGIN_PATH');define('WEB_PLUGIN_PATH', 'WEB_PLUGIN_PATH');define('SYS_ARCHIVE_PATH', 'SYS_ARCHIVE_PATH');define('INCLUDE_PATH', 'INCLUDE_PATH');define('LIBRARY_PATH', 'LIBRARY_PATH');define('CONFIGURATION_PATH', 'CONFIGURATION_PATH');define('WEB_LIBRARY_PATH','WEB_LIBRARY_PATH');//CONSTANTS defining all tools, using the english versiondefine('TOOL_DOCUMENT', 'document');define('TOOL_HOTPOTATOES', 'hotpotatoes');define('TOOL_CALENDAR_EVENT', 'calendar_event');define('TOOL_LINK', 'link');define('TOOL_COURSE_DESCRIPTION', 'course_description');define('TOOL_LEARNPATH', 'learnpath');define('TOOL_ANNOUNCEMENT', 'announcement');define('TOOL_FORUM', 'forum');define('TOOL_THREAD', 'thread');define('TOOL_POST', 'post');define('TOOL_DROPBOX', 'dropbox');define('TOOL_QUIZ', 'quiz');define('TOOL_USER', 'user');define('TOOL_GROUP', 'group');define('TOOL_BLOGS', 'blog_management'); // Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be)define('TOOL_CHAT', 'chat');define('TOOL_CONFERENCE', 'conference');define('TOOL_STUDENTPUBLICATION', 'student_publication');define('TOOL_TRACKING', 'tracking');define('TOOL_HOMEPAGE_LINK', 'homepage_link');define('TOOL_COURSE_SETTING', 'course_setting');define('TOOL_BACKUP', 'backup');define('TOOL_COPY_COURSE_CONTENT', 'copy_course_content');define('TOOL_RECYCLE_COURSE', 'recycle_course');define('TOOL_COURSE_HOMEPAGE', 'course_homepage');define('TOOL_COURSE_RIGHTS_OVERVIEW', 'course_rights');define('TOOL_UPLOAD','file_upload');define('TOOL_COURSE_MAINTENANCE','course_maintenance');define('TOOL_VISIO','visio');define('TOOL_VISIO_CONFERENCE','visio_conference');define('TOOL_VISIO_CLASSROOM','visio_classroom');define('TOOL_SURVEY','survey');// CONSTANTS defining dokeos sectionsdefine('SECTION_CAMPUS', 'mycampus');define('SECTION_COURSES', 'mycourses');define('SECTION_MYPROFILE', 'myprofile');define('SECTION_MYAGENDA', 'myagenda');define('SECTION_COURSE_ADMIN', 'course_admin');define('SECTION_PLATFORM_ADMIN', 'platform_admin');define('SECTION_MYGRADEBOOK', 'mygradebook');// CONSTANT name for local authentication sourcedefine('PLATFORM_AUTH_SOURCE', 'platform');//CONSTANT defining the default HotPotatoes files directorydefine('DIR_HOTPOTATOES','/HotPotatoes_files');/*============================================================================== PROTECTION FUNCTIONS use these to protect your scripts==============================================================================*//*** 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!* @param boolean Option to print headers when displaying error message. Default: false* @todo replace global variable* @author Roan Embrechts*/function api_protect_course_script($print_headers=false){ global $is_allowed_in_course; //if (!isset ($_SESSION["_course"]) || !$is_allowed_in_course) if (!$is_allowed_in_course) { api_not_allowed($print_headers); }}/*** 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!** @author Roan Embrechts*/function api_protect_admin_script($allow_sessions_admins=false){ if (!api_is_platform_admin($allow_sessions_admins)) { include (api_get_path(INCLUDE_PATH)."header.inc.php"); api_not_allowed(); }}/*** Function used to prevent anonymous users from accessing a script.** @author Roan Embrechts*/function api_block_anonymous_users(){ global $_user; if (!(isset ($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'],true)) { include (api_get_path(INCLUDE_PATH)."header.inc.php"); api_not_allowed(); }}/*============================================================================== ACCESSOR FUNCTIONS don't access kernel variables directly, use these functions instead==============================================================================*//*** @return an array with the navigator name and version*/function api_get_navigator(){ $navigator = 'Unknown'; $version = 0; if (strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) { $navigator = 'Opera'; list (, $version) = explode('Opera', $_SERVER['HTTP_USER_AGENT']); } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { $navigator = 'Internet Explorer'; list (, $version) = explode('MSIE', $_SERVER['HTTP_USER_AGENT']); } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) { $navigator = 'Mozilla'; list (, $version) = explode('; rv:', $_SERVER['HTTP_USER_AGENT']); } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'Netscape')) { $navigator = 'Netscape'; list (, $version) = explode('Netscape', $_SERVER['HTTP_USER_AGENT']); } $version = doubleval($version); if (!strstr($version, '.')) { $version = number_format(doubleval($version), 1); } return array ('name' => $navigator, 'version' => $version);}/*** @return True if user selfregistration is allowed, false otherwise.*/function api_is_self_registration_allowed(){ if(isset($GLOBALS['allowSelfReg'])) { return $GLOBALS["allowSelfReg"]; } else { return false; }}/*** 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.** @param one of the following constants:* WEB_PATH, SYS_PATH, REL_PATH, WEB_COURSE_PATH, SYS_COURSE_PATH,* REL_COURSE_PATH, REL_CODE_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** @example assume that your server root is /var/www/ dokeos is installed in a subfolder dokeos/ and the URL of your campus is http://www.mydokeos.com* The other configuration paramaters have not been changed.* The different api_get_paths will give* WEB_PATH http://www.mydokeos.com* SYS_PATH /var/www/* REL_PATH dokeos/* WEB_COURSE_PATH http://www.mydokeos.com/courses/* SYS_COURSE_PATH /var/www/dokeos/courses/* REL_COURSE_PATH* REL_CODE_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*/function api_get_path($path_type){ global $_configuration; switch ($path_type) { case WEB_PATH : // example: http://www.mydokeos.com/ or http://www.mydokeos.com/portal/ if you're using // a subdirectory of your document root for Dokeos if(substr($_configuration['root_web'],-1) == '/') { return $_configuration['root_web']; } else { return $_configuration['root_web'].'/'; } break; case SYS_PATH : // example: /var/www/ if(substr($_configuration['root_sys'],-1) == '/') { return $_configuration['root_sys']; } else { return $_configuration['root_sys'].'/'; } break; case REL_PATH : // example: dokeos/ if (substr($_configuration['url_append'], -1) === '/') { return $_configuration['url_append']; } else { return $_configuration['url_append'].'/'; } break; case WEB_COURSE_PATH : // example: http://www.mydokeos.com/courses/ return $_configuration['root_web'].$_configuration['course_folder']; break; case SYS_COURSE_PATH : // example: /var/www/dokeos/courses/ return $_configuration['root_sys'].$_configuration['course_folder']; break; case REL_COURSE_PATH : // example: courses/ or dokeos/courses/ return api_get_path(REL_PATH).$_configuration['course_folder']; break; case REL_CODE_PATH : // example: main/ or dokeos/main/ return api_get_path(REL_PATH).$_configuration['code_append']; break; case WEB_CODE_PATH : // example: http://www.mydokeos.com/main/ return $GLOBALS['clarolineRepositoryWeb']; break; case SYS_CODE_PATH : // example: /var/www/dokeos/main/ return $GLOBALS['clarolineRepositorySys']; break; case SYS_LANG_PATH : // example: /var/www/dokeos/main/lang/ return api_get_path(SYS_CODE_PATH).'lang/'; break; case WEB_IMG_PATH : // example: http://www.mydokeos.com/main/img/ return api_get_path(WEB_CODE_PATH).'img/'; break; case GARBAGE_PATH : // example: /var/www/dokeos/main/garbage/ return $GLOBALS['garbageRepositorySys']; break; case SYS_PLUGIN_PATH : // example: /var/www/dokeos/plugin/ return api_get_path(SYS_PATH).'plugin/'; break; case WEB_PLUGIN_PATH : // example: http://www.mydokeos.com/plugin/ return api_get_path(WEB_PATH).'plugin/'; break; case SYS_ARCHIVE_PATH : // example: /var/www/dokeos/archive/ return api_get_path(SYS_PATH).'archive/'; break; case INCLUDE_PATH : // Generated by main/inc/global.inc.php // example: /var/www/dokeos/main/inc/ return str_replace('\\', '/', $GLOBALS['includePath']).'/'; break; case LIBRARY_PATH : // example: /var/www/dokeos/main/inc/lib/ return api_get_path(INCLUDE_PATH).'lib/'; break; case WEB_LIBRARY_PATH : // example: http://www.mydokeos.com/main/inc/lib/ return api_get_path(WEB_CODE_PATH).'inc/lib/'; break; case CONFIGURATION_PATH : // example: /var/www/dokeos/main/inc/conf/ return api_get_path(INCLUDE_PATH).'conf/'; break; default : return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -