@ -28,15 +28,16 @@ require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
* @param int Expiration delay in unix timestamp
* @param int Expiration delay in unix timestamp
* @return mixed Course code if course was successfully created, false otherwise
* @return mixed Course code if course was successfully created, false otherwise
*/
*/
function create_course($wanted_code, $title, $tutor_name, $category_code, $course_language, $course_admin_id, $db_prefix, $firstExpirationDelay) {
function create_course($wanted_code, $title, $tutor_name, $category_code, $course_language, $course_admin_id, $db_prefix, $first_expiration_delay) {
$keys = define_course_keys($wanted_code, '', $db_prefix);
$keys = define_course_keys($wanted_code, '', $db_prefix);
if (sizeof ($keys)) {
if (count ($keys)) {
$visual_code = $keys['currentCourseCode'];
$visual_code = $keys['currentCourseCode'];
$code = $keys['currentCourseId'];
$code = $keys['currentCourseId'];
$db_name = $keys['currentCourseDbName'];
$db_name = $keys['currentCourseDbName'];
$directory = $keys['currentCourseRepository'];
$directory = $keys['currentCourseRepository'];
$expiration_date = time() + $firstExpirationD elay;
$expiration_date = time() + $first_expiration_d elay;
prepare_course_repository($directory, $code);
prepare_course_repository($directory, $code);
update_Db_course($db_name, $course_language);
update_Db_course($db_name, $course_language);
@ -59,133 +60,133 @@ function generate_course_code($course_title, $encoding = null) {
return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, 'X', $encoding))), 0, 20);
return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, 'X', $encoding))), 0, 20);
}
}
/**
/**
* Defines the four needed keys to create a course based on several parameters.
* Defines the four needed keys to create a course based on several parameters.
* @return array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'], ['currentCourseRepository']
*
* @param string The code you want for this course
* @param string The code you want for this course
* @param string Prefix added for ALL keys
* @param string Prefix added for ALL keys
* @param string Prefix added for databases only
* @param string Prefix added for databases only
* @param string Prefix added for paths only
* @param string Prefix added for paths only
* @param bool Add unique prefix
* @param bool Add unique prefix
* @param bool Use code-independent keys
* @param bool Use code-independent keys
* @return array An array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'], ['currentCourseRepository']
* @todo Eliminate the global variables.
* @todo Eliminate the global variables.
*/
*/
function define_course_keys($wantedCode, $prefix4all = '', $prefix4baseName = '', $prefix4path = '', $addUniquePrefix = false, $useCodeInDepedentKeys = true) {
function define_course_keys($wanted_code, $prefix_for_all = '', $prefix_for_base_name = '', $prefix_for_path = '', $add_unique_prefix = false, $use_code_indepedent_keys = true) {
global $prefixAntiNumber, $_configuration;
global $prefixAntiNumber, $_configuration;
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$wantedCode = generate_course_code($wantedCode);
$keysCourseCode = $wantedCode;
$wanted_code = generate_course_code($wanted_code);
if (!$useCodeInDepedentKeys) {
$keys_course_code = $wanted_code;
$wantedCode = '';
if (!$use_code_indepedent_keys) {
$wanted_code = '';
}
}
if ($addUniqueP refix) {
if ($add_unique_p refix) {
$uniqueP refix = substr(md5(uniqid(rand())), 0, 10);
$unique_p refix = substr(md5(uniqid(rand())), 0, 10);
} else {
} else {
$uniqueP refix = '';
$unique_p refix = '';
}
}
$keys = array ();
$keys = array ();
$finalS uffix = array('CourseId' => '', 'CourseDb' => '', 'CourseDir' => '');
$final_s uffix = array('CourseId' => '', 'CourseDb' => '', 'CourseDir' => '');
$limitNumbT ry = 100;
$limit_numb_t ry = 100;
$keysAreU nique = false;
$keys_are_u nique = false;
$tryNewFSCId = $tryNewFSCDb = $tryNewFSCD ir = 0;
$try_new_fsc_id = $try_new_fsc_db = $try_new_fsc_d ir = 0;
while (!$keysAreU nique) {
while (!$keys_are_u nique) {
$keysCourseId = $prefix4all.$uniquePrefix.$wantedCode.$finalS uffix['CourseId'];
$keys_course_id = $prefix_for_all . $unique_prefix . $wanted_code . $final_s uffix['CourseId'];
$keysCourseDbName = $prefix4baseName.$uniquePrefix.strtoupper($keysCourseId).$finalS uffix['CourseDb'];
$keys_course_db_name = $prefix_for_base_name . $unique_prefix . strtoupper($keys_course_id) . $final_s uffix['CourseDb'];
$keysCourseRepository = $prefix4path.$uniquePrefix.$wantedCode.$finalS uffix['CourseDir'];
$keys_course_repository = $prefix_for_path . $unique_prefix . $wanted_code . $final_s uffix['CourseDir'];
$keysAreU nique = true;
$keys_are_u nique = true;
// Check whether they are unique.
// Check whether they are unique.
$query = "SELECT 1 FROM ".$course_table . " WHERE code='".$keysCourseId . "' LIMIT 0,1";
$query = "SELECT 1 FROM ".$course_table." WHERE code='".$keys_course_id. "' LIMIT 0,1";
$result = Database::query($query);
$result = Database::query($query);
if ($keysCourseI d == DEFAULT_COURSE || Database::num_rows($result)) {
if ($keys_course_i d == DEFAULT_COURSE || Database::num_rows($result)) {
$keysAreU nique = false;
$keys_are_u nique = false;
$tryNewFSCI d ++;
$try_new_fsc_i d ++;
$finalS uffix['CourseId'] = substr(md5(uniqid(rand())), 0, 4);
$final_s uffix['CourseId'] = substr(md5(uniqid(rand())), 0, 4);
}
}
if ($_configuration['single_database']) {
if ($_configuration['single_database']) {
$query = "SHOW TABLES FROM `".$_configuration['main_database']."` LIKE '".$_configuration['table_prefix']."$keysCourseDbName" .$_configuration['db_glue']."%'";
$query = "SHOW TABLES FROM `".$_configuration['main_database']."` LIKE '".$_configuration['table_prefix'].$keys_course_db_name .$_configuration['db_glue']."%'";
$result = Database::query($query);
$result = Database::query($query);
} else {
} else {
$query = "SHOW DATABASES LIKE '$keysCourseDbN ame'";
$query = "SHOW DATABASES LIKE '$keys_course_db_n ame'";
$result = Database::query($query);
$result = Database::query($query);
}
}
if (Database::num_rows($result)) {
if (Database::num_rows($result)) {
$keysAreU nique = false;
$keys_are_u nique = false;
$tryNewFSCD b ++;
$try_new_fsc_d b ++;
$finalS uffix['CourseDb'] = substr('_'.md5(uniqid(rand())), 0, 4);
$final_s uffix['CourseDb'] = substr('_'.md5(uniqid(rand())), 0, 4);
}
}
// @todo: Use and api_get_path here instead of constructing it by yourself.
// @todo: Use and api_get_path here instead of constructing it by yourself.
if (file_exists($_configuration['root_sys'].$_configuration['course_folder'].$keysCourseR epository)) {
if (file_exists($_configuration['root_sys'] . $_configuration['course_folder'] . $keys_course_r epository)) {
$keysAreU nique = false;
$keys_are_u nique = false;
$tryNewFSCD ir ++;
$try_new_fsc_d ir ++;
$finalS uffix['CourseDir'] = substr(md5(uniqid(rand())), 0, 4);
$final_s uffix['CourseDir'] = substr(md5(uniqid(rand())), 0, 4);
}
}
if (($tryNewFSCId + $tryNewFSCDb + $tryNewFSCDir) > $limitNumbT ry) {
if (($try_new_fsc_id + $try_new_fsc_db + $try_new_fsc_dir) > $limit_numb_t ry) {
return $keys;
return $keys;
}
}
}
}
// Db name can't begin with a number.
// Db name can't begin with a number.
if (!stristr('abcdefghijklmnopqrstuvwxyz', $keysCourseDbName[0]) ) {
if (stripos('abcdefghijklmnopqrstuvwxyz', $keys_course_db_name[0]) === false ) {
$keysCourseDbName = $prefixAntiNumber.$keysCourseDbN ame;
$keys_course_db_name = $prefixAntiNumber . $keys_course_db_n ame;
}
}
$keys['currentCourseCode'] = $keysCourseC ode;
$keys['currentCourseCode'] = $keys_course_c ode;
$keys['currentCourseId'] = $keysCourseI d;
$keys['currentCourseId'] = $keys_course_i d;
$keys['currentCourseDbName'] = $keysCourseDbN ame;
$keys['currentCourseDbName'] = $keys_course_db_n ame;
$keys['currentCourseRepository'] = $keysCourseR epository;
$keys['currentCourseRepository'] = $keys_course_r epository;
return $keys;
return $keys;
}
}
/**
/**
*
* Initializes a file repository for a newly created course.
*
*/
*/
function prepare_course_repository($courseRepository, $courseId) {
function prepare_course_repository($course_repository, $course_code) {
$perm = api_get_permissions_for_new_directories();
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$perm_file = api_get_permissions_for_new_files();
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository, $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository, $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/images/gallery/', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/images/gallery/', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/shared_folder/', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/shared_folder/', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/audio', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/audio', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/flash', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/flash', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/video', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/video', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/document/video/flv', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/document/video/flv', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/dropbox', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/dropbox', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/group', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/group', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/page', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/page', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/scorm', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/scorm', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/temp', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/temp', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/forum', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/forum', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/forum/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/forum/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/test', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/test', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/blog', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/blog', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/learning_path', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/learning_path', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/learning_path/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/learning_path/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/calendar', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/calendar', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/calendar/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/calendar/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/work', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/work', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/announcements', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/announcements', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseR epository . '/upload/announcements/images', $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$course_r epository . '/upload/announcements/images', $perm);
// Create .htaccess in the dropbox directory.
// Create .htaccess in the dropbox directory.
$fp = fopen(api_get_path(SYS_COURSE_PATH).$courseR epository . '/dropbox/.htaccess', 'w');
$fp = fopen(api_get_path(SYS_COURSE_PATH).$course_r epository . '/dropbox/.htaccess', 'w');
fwrite($fp, "AuthName AllowLocalAccess
fwrite($fp, "AuthName AllowLocalAccess
AuthType Basic
AuthType Basic
@ -196,25 +197,28 @@ function prepare_course_repository($courseRepository, $courseId) {
fclose($fp);
fclose($fp);
// Build index.php of the course.
// Build index.php of the course.
$fd = fopen(api_get_path(SYS_COURSE_PATH).$courseR epository . '/index.php', 'w');
$fd = fopen(api_get_path(SYS_COURSE_PATH).$course_r epository . '/index.php', 'w');
// str_replace() removes \r that cause squares to appear at the end of each line
// str_replace() removes \r that cause squares to appear at the end of each line
$string = str_replace("\r", "", "<? " . " php
$string = str_replace("\r", "", "<? " . " php
\$cidReq = \"$courseId \";
\$cidReq = \"$course_code \";
\$dbname = \"$courseId \";
\$dbname = \"$course_code \";
include(\"../../main/course_home/course_home.php\");
include(\"../../main/course_home/course_home.php\");
?>");
?>");
fwrite($fd, $string);
fwrite($fd, $string);
@chmod(api_get_path(SYS_COURSE_PATH).$courseR epository . '/index.php',$perm_file);
@chmod(api_get_path(SYS_COURSE_PATH).$course_r epository . '/index.php',$perm_file);
$fd = fopen(api_get_path(SYS_COURSE_PATH).$courseR epository . '/group/index.html', 'w');
$fd = fopen(api_get_path(SYS_COURSE_PATH).$course_r epository . '/group/index.html', 'w');
$string = '< html > < / html > ';
$string = '< html > < / html > ';
fwrite($fd, $string);
fwrite($fd, $string);
fclose($fd);
fclose($fd);
return 0;
return 0;
};
};
function update_Db_course($courseDbName, $language = null) {
/**
* Creates all the necessary tables for a new course.
*/
function update_Db_course($course_db_name, $language = null) {
global $_configuration, $language_interface;
global $_configuration, $language_interface;
if (empty($language)) {
if (empty($language)) {
@ -225,144 +229,144 @@ function update_Db_course($courseDbName, $language = null) {
$charset_clause = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci';
$charset_clause = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci';
if (!$_configuration['single_database']) {
if (!$_configuration['single_database']) {
Database::query("CREATE DATABASE IF NOT EXISTS `" . $courseDbN ame . "`" . $charset_clause);
Database::query("CREATE DATABASE IF NOT EXISTS `" . $course_db_n ame . "`" . $charset_clause);
}
}
$courseDbName = $_configuration['table_prefix'].$courseDbN ame.$_configuration['db_glue'];
$course_db_name = $_configuration['table_prefix'].$course_db_n ame.$_configuration['db_glue'];
$tbl_course_homepage = $courseDbN ame . 'tool';
$tbl_course_homepage = $course_db_n ame . 'tool';
$TABLEINTROS = $courseDbN ame . 'tool_intro';
$TABLEINTROS = $course_db_n ame . 'tool_intro';
// Group tool
// Group tool
$TABLEGROUPS = $courseDbN ame . 'group_info';
$TABLEGROUPS = $course_db_n ame . 'group_info';
$TABLEGROUPCATEGORIES = $courseDbN ame . 'group_category';
$TABLEGROUPCATEGORIES = $course_db_n ame . 'group_category';
$TABLEGROUPUSER = $courseDbN ame . 'group_rel_user';
$TABLEGROUPUSER = $course_db_n ame . 'group_rel_user';
$TABLEGROUPTUTOR = $courseDbN ame . 'group_rel_tutor';
$TABLEGROUPTUTOR = $course_db_n ame . 'group_rel_tutor';
$TABLEITEMPROPERTY = $courseDbN ame . 'item_property';
$TABLEITEMPROPERTY = $course_db_n ame . 'item_property';
$TABLETOOLUSERINFOCONTENT = $courseDbN ame . 'userinfo_content';
$TABLETOOLUSERINFOCONTENT = $course_db_n ame . 'userinfo_content';
$TABLETOOLUSERINFODEF = $courseDbN ame . 'userinfo_def';
$TABLETOOLUSERINFODEF = $course_db_n ame . 'userinfo_def';
$TABLETOOLCOURSEDESC = $courseDbN ame . 'course_description';
$TABLETOOLCOURSEDESC = $course_db_n ame . 'course_description';
$TABLETOOLAGENDA = $courseDbN ame . 'calendar_event';
$TABLETOOLAGENDA = $course_db_n ame . 'calendar_event';
$TABLETOOLAGENDAREPEAT = $courseDbN ame . 'calendar_event_repeat';
$TABLETOOLAGENDAREPEAT = $course_db_n ame . 'calendar_event_repeat';
$TABLETOOLAGENDAREPEATNOT = $courseDbN ame . 'calendar_event_repeat_not';
$TABLETOOLAGENDAREPEATNOT = $course_db_n ame . 'calendar_event_repeat_not';
$TABLETOOLAGENDAATTACHMENT = $courseDbN ame . 'calendar_event_attachment';
$TABLETOOLAGENDAATTACHMENT = $course_db_n ame . 'calendar_event_attachment';
// Announcements
// Announcements
$TABLETOOLANNOUNCEMENTS = $courseDbN ame . 'announcement';
$TABLETOOLANNOUNCEMENTS = $course_db_n ame . 'announcement';
$TABLETOOLANNOUNCEMENTSATTACHMENT = $courseDbN ame . 'announcement_attachment';
$TABLETOOLANNOUNCEMENTSATTACHMENT = $course_db_n ame . 'announcement_attachment';
// Resourcelinker
// Resourcelinker
$TABLEADDEDRESOURCES = $courseDbN ame . 'resource';
$TABLEADDEDRESOURCES = $course_db_n ame . 'resource';
// Student Publication
// Student Publication
$TABLETOOLWORKS = $courseDbN ame . 'student_publication';
$TABLETOOLWORKS = $course_db_n ame . 'student_publication';
$TABLETOOLWORKSASS = $courseDbN ame . 'student_publication_assignment';
$TABLETOOLWORKSASS = $course_db_n ame . 'student_publication_assignment';
// Document
// Document
$TABLETOOLDOCUMENT = $courseDbN ame . 'document';
$TABLETOOLDOCUMENT = $course_db_n ame . 'document';
// Forum
// Forum
$TABLETOOLFORUMCATEGORY = $courseDbN ame . 'forum_category';
$TABLETOOLFORUMCATEGORY = $course_db_n ame . 'forum_category';
$TABLETOOLFORUM = $courseDbN ame . 'forum_forum';
$TABLETOOLFORUM = $course_db_n ame . 'forum_forum';
$TABLETOOLFORUMTHREAD = $courseDbN ame . 'forum_thread';
$TABLETOOLFORUMTHREAD = $course_db_n ame . 'forum_thread';
$TABLETOOLFORUMPOST = $courseDbN ame . 'forum_post';
$TABLETOOLFORUMPOST = $course_db_n ame . 'forum_post';
$TABLETOOLFORUMMAILCUE = $courseDbN ame . 'forum_mailcue';
$TABLETOOLFORUMMAILCUE = $course_db_n ame . 'forum_mailcue';
$TABLETOOLFORUMATTACHMENT = $courseDbN ame . 'forum_attachment';
$TABLETOOLFORUMATTACHMENT = $course_db_n ame . 'forum_attachment';
$TABLETOOLFORUMNOTIFICATION = $courseDbN ame . 'forum_notification';
$TABLETOOLFORUMNOTIFICATION = $course_db_n ame . 'forum_notification';
$TABLETOOLFORUMQUALIFY = $courseDbN ame . 'forum_thread_qualify';
$TABLETOOLFORUMQUALIFY = $course_db_n ame . 'forum_thread_qualify';
$TABLETOOLFORUMQUALIFYLOG = $courseDbN ame . 'forum_thread_qualify_log';
$TABLETOOLFORUMQUALIFYLOG = $course_db_n ame . 'forum_thread_qualify_log';
// Link
// Link
$TABLETOOLLINK = $courseDbN ame . 'link';
$TABLETOOLLINK = $course_db_n ame . 'link';
$TABLETOOLLINKCATEGORIES = $courseDbN ame . 'link_category';
$TABLETOOLLINKCATEGORIES = $course_db_n ame . 'link_category';
$TABLETOOLONLINECONNECTED = $courseDbN ame . 'online_connected';
$TABLETOOLONLINECONNECTED = $course_db_n ame . 'online_connected';
$TABLETOOLONLINELINK = $courseDbN ame . 'online_link';
$TABLETOOLONLINELINK = $course_db_n ame . 'online_link';
// Chat
// Chat
$TABLETOOLCHATCONNECTED = $courseDbN ame . 'chat_connected';
$TABLETOOLCHATCONNECTED = $course_db_n ame . 'chat_connected';
// Quiz (a.k.a. exercises)
// Quiz (a.k.a. exercises)
$TABLEQUIZ = $courseDbN ame . 'quiz';
$TABLEQUIZ = $course_db_n ame . 'quiz';
$TABLEQUIZQUESTION = $courseDbN ame . 'quiz_rel_question';
$TABLEQUIZQUESTION = $course_db_n ame . 'quiz_rel_question';
$TABLEQUIZQUESTIONLIST = $courseDbN ame . 'quiz_question';
$TABLEQUIZQUESTIONLIST = $course_db_n ame . 'quiz_question';
$TABLEQUIZANSWERSLIST = $courseDbN ame . 'quiz_answer';
$TABLEQUIZANSWERSLIST = $course_db_n ame . 'quiz_answer';
// Dropbox
// Dropbox
$TABLETOOLDROPBOXPOST = $courseDbN ame . 'dropbox_post';
$TABLETOOLDROPBOXPOST = $course_db_n ame . 'dropbox_post';
$TABLETOOLDROPBOXFILE = $courseDbN ame . 'dropbox_file';
$TABLETOOLDROPBOXFILE = $course_db_n ame . 'dropbox_file';
$TABLETOOLDROPBOXPERSON = $courseDbN ame . 'dropbox_person';
$TABLETOOLDROPBOXPERSON = $course_db_n ame . 'dropbox_person';
$TABLETOOLDROPBOXCATEGORY = $courseDbN ame . 'dropbox_category';
$TABLETOOLDROPBOXCATEGORY = $course_db_n ame . 'dropbox_category';
$TABLETOOLDROPBOXFEEDBACK = $courseDbN ame . 'dropbox_feedback';
$TABLETOOLDROPBOXFEEDBACK = $course_db_n ame . 'dropbox_feedback';
// New Learning path
// New Learning path
$TABLELP = $courseDbN ame . 'lp';
$TABLELP = $course_db_n ame . 'lp';
$TABLELPITEM = $courseDbN ame . 'lp_item';
$TABLELPITEM = $course_db_n ame . 'lp_item';
$TABLELPVIEW = $courseDbN ame . 'lp_view';
$TABLELPVIEW = $course_db_n ame . 'lp_view';
$TABLELPITEMVIEW = $courseDbN ame . 'lp_item_view';
$TABLELPITEMVIEW = $course_db_n ame . 'lp_item_view';
$TABLELPIVINTERACTION = $courseDbN ame . 'lp_iv_interaction';
$TABLELPIVINTERACTION = $course_db_n ame . 'lp_iv_interaction';
$TABLELPIVOBJECTIVE = $courseDbN ame . 'lp_iv_objective';
$TABLELPIVOBJECTIVE = $course_db_n ame . 'lp_iv_objective';
// Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be)
// Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be)
$tbl_blogs = $courseDbN ame . 'blog';
$tbl_blogs = $course_db_n ame . 'blog';
$tbl_blogs_comments = $courseDbN ame . 'blog_comment';
$tbl_blogs_comments = $course_db_n ame . 'blog_comment';
$tbl_blogs_posts = $courseDbN ame . 'blog_post';
$tbl_blogs_posts = $course_db_n ame . 'blog_post';
$tbl_blogs_rating = $courseDbN ame . 'blog_rating';
$tbl_blogs_rating = $course_db_n ame . 'blog_rating';
$tbl_blogs_rel_user = $courseDbN ame . 'blog_rel_user';
$tbl_blogs_rel_user = $course_db_n ame . 'blog_rel_user';
$tbl_blogs_tasks = $courseDbN ame . 'blog_task';
$tbl_blogs_tasks = $course_db_n ame . 'blog_task';
$tbl_blogs_tasks_rel_user = $courseDbN ame . 'blog_task_rel_user';
$tbl_blogs_tasks_rel_user = $course_db_n ame . 'blog_task_rel_user';
$tbl_blogs_attachment = $courseDbN ame . 'blog_attachment';
$tbl_blogs_attachment = $course_db_n ame . 'blog_attachment';
//Smartblogs permissions (Kevin Van Den Haute :: kevin@develop-it.be)
//Smartblogs permissions (Kevin Van Den Haute :: kevin@develop-it.be)
$tbl_permission_group = $courseDbN ame . 'permission_group';
$tbl_permission_group = $course_db_n ame . 'permission_group';
$tbl_permission_user = $courseDbN ame . 'permission_user';
$tbl_permission_user = $course_db_n ame . 'permission_user';
$tbl_permission_task = $courseDbN ame . 'permission_task';
$tbl_permission_task = $course_db_n ame . 'permission_task';
//Smartblogs roles (Kevin Van Den Haute :: kevin@develop-it.be)
//Smartblogs roles (Kevin Van Den Haute :: kevin@develop-it.be)
$tbl_role = $courseDbN ame . 'role';
$tbl_role = $course_db_n ame . 'role';
$tbl_role_group = $courseDbN ame . 'role_group';
$tbl_role_group = $course_db_n ame . 'role_group';
$tbl_role_permissions = $courseDbN ame . 'role_permissions';
$tbl_role_permissions = $course_db_n ame . 'role_permissions';
$tbl_role_user = $courseDbN ame . 'role_user';
$tbl_role_user = $course_db_n ame . 'role_user';
//Survey variables for course homepage;
//Survey variables for course homepage;
$TABLESURVEY = $courseDbN ame . 'survey';
$TABLESURVEY = $course_db_n ame . 'survey';
$TABLESURVEYQUESTION = $courseDbN ame . 'survey_question';
$TABLESURVEYQUESTION = $course_db_n ame . 'survey_question';
$TABLESURVEYQUESTIONOPTION = $courseDbN ame . 'survey_question_option';
$TABLESURVEYQUESTIONOPTION = $course_db_n ame . 'survey_question_option';
$TABLESURVEYINVITATION = $courseDbN ame . 'survey_invitation';
$TABLESURVEYINVITATION = $course_db_n ame . 'survey_invitation';
$TABLESURVEYANSWER = $courseDbN ame . 'survey_answer';
$TABLESURVEYANSWER = $course_db_n ame . 'survey_answer';
$TABLESURVEYGROUP = $courseDbN ame . 'survey_group';
$TABLESURVEYGROUP = $course_db_n ame . 'survey_group';
// Wiki
// Wiki
$TABLETOOLWIKI = $courseDbN ame . 'wiki';
$TABLETOOLWIKI = $course_db_n ame . 'wiki';
$TABLEWIKICONF = $courseDbN ame . 'wiki_conf';
$TABLEWIKICONF = $course_db_n ame . 'wiki_conf';
$TABLEWIKIDISCUSS = $courseDbN ame . 'wiki_discuss';
$TABLEWIKIDISCUSS = $course_db_n ame . 'wiki_discuss';
$TABLEWIKIMAILCUE = $courseDbN ame . 'wiki_mailcue';
$TABLEWIKIMAILCUE = $course_db_n ame . 'wiki_mailcue';
// audiorecorder
// audiorecorder
$TABLEAUDIORECORDER = $courseDbN ame . 'audiorecorder';
$TABLEAUDIORECORDER = $course_db_n ame . 'audiorecorder';
// Course settings
// Course settings
$TABLESETTING = $courseDbN ame . 'course_setting';
$TABLESETTING = $course_db_n ame . 'course_setting';
// Glossary
// Glossary
$TBL_GLOSSARY = $courseDbN ame . 'glossary';
$TBL_GLOSSARY = $course_db_n ame . 'glossary';
// Notebook
// Notebook
$TBL_NOTEBOOK = $courseDbN ame . 'notebook';
$TBL_NOTEBOOK = $course_db_n ame . 'notebook';
// Attendance
// Attendance
$TBL_ATTENDANCE = $courseDbN ame . 'attendance';
$TBL_ATTENDANCE = $course_db_n ame . 'attendance';
$TBL_ATTENDANCE_SHEET = $courseDbN ame . 'attendance_sheet';
$TBL_ATTENDANCE_SHEET = $course_db_n ame . 'attendance_sheet';
$TBL_ATTENDANCE_CALENDAR = $courseDbN ame . 'attendance_calendar';
$TBL_ATTENDANCE_CALENDAR = $course_db_n ame . 'attendance_calendar';
$TBL_ATTENDANCE_RESULT = $courseDbN ame . 'attendance_result';
$TBL_ATTENDANCE_RESULT = $course_db_n ame . 'attendance_result';
// Thematic
// Thematic
$TBL_THEMATIC = $courseDbN ame . 'thematic';
$TBL_THEMATIC = $course_db_n ame . 'thematic';
$TBL_THEMATIC_PLAN = $courseDbN ame . 'thematic_plan';
$TBL_THEMATIC_PLAN = $course_db_n ame . 'thematic_plan';
$TBL_THEMATIC_ADVANCE = $courseDbN ame . 'thematic_advance';
$TBL_THEMATIC_ADVANCE = $course_db_n ame . 'thematic_advance';
/*
/*
-----------------------------------------------------------
-----------------------------------------------------------
@ -1861,7 +1865,8 @@ function sort_pictures($files, $type) {
* example content.
* example content.
* @version 1.2
* @version 1.2
*/
*/
function fill_course_repository($courseRepository) {
function fill_course_repository($course_repository) {
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$web_code_path = api_get_path(WEB_CODE_PATH);
$web_code_path = api_get_path(WEB_CODE_PATH);
@ -1870,7 +1875,7 @@ function fill_course_repository($courseRepository) {
/*doc_html = file(api_get_path(SYS_CODE_PATH).'document/example_document.html');
/*doc_html = file(api_get_path(SYS_CODE_PATH).'document/example_document.html');
$fp = fopen($sys_course_path.$courseR epository.'/document/example_document.html', 'w');
$fp = fopen($sys_course_path.$course_r epository.'/document/example_document.html', 'w');
foreach ($doc_html as $key => $enreg) {
foreach ($doc_html as $key => $enreg) {
$enreg = str_replace('"stones.jpg"', '"'.$web_code_path.'img/stones.jpg"', $enreg);
$enreg = str_replace('"stones.jpg"', '"'.$web_code_path.'img/stones.jpg"', $enreg);
@ -1886,10 +1891,10 @@ function fill_course_repository($courseRepository) {
$audio_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/audio/';
$audio_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/audio/';
$flash_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/flash/';
$flash_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/flash/';
$video_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/video/';
$video_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/video/';
$course_documents_folder_images = $sys_course_path.$courseR epository.'/document/images/gallery/';
$course_documents_folder_images = $sys_course_path.$course_r epository.'/document/images/gallery/';
$course_documents_folder_audio = $sys_course_path.$courseR epository.'/document/audio/';
$course_documents_folder_audio = $sys_course_path.$course_r epository.'/document/audio/';
$course_documents_folder_flash = $sys_course_path.$courseR epository.'/document/flash/';
$course_documents_folder_flash = $sys_course_path.$course_r epository.'/document/flash/';
$course_documents_folder_video = $sys_course_path.$courseR epository.'/document/video/';
$course_documents_folder_video = $sys_course_path.$course_r epository.'/document/video/';
/*
/*
* Images
* Images
@ -2040,41 +2045,41 @@ function lang2db($string) {
* Fills the course database with some required content and example content.
* Fills the course database with some required content and example content.
* @version 1.2
* @version 1.2
*/
*/
function fill_Db_course($courseDbName, $courseR epository, $language, $default_document_array = array()) {
function fill_Db_course($course_db_name, $course_r epository, $language, $default_document_array = array()) {
global $_configuration, $clarolineRepositoryWeb, $ _user;
global $_configuration, $_user;
$courseDbName = $_configuration['table_prefix'].$courseDbN ame.$_configuration['db_glue'];
$course_db_name = $_configuration['table_prefix'].$course_db_n ame.$_configuration['db_glue'];
$tbl_course_homepage = $courseDbN ame . 'tool';
$tbl_course_homepage = $course_db_n ame . 'tool';
$TABLEINTROS = $courseDbN ame . 'tool_intro';
$TABLEINTROS = $course_db_n ame . 'tool_intro';
$TABLEGROUPS = $courseDbN ame . 'group_info';
$TABLEGROUPS = $course_db_n ame . 'group_info';
$TABLEGROUPCATEGORIES = $courseDbN ame . 'group_category';
$TABLEGROUPCATEGORIES = $course_db_n ame . 'group_category';
$TABLEGROUPUSER = $courseDbN ame . 'group_rel_user';
$TABLEGROUPUSER = $course_db_n ame . 'group_rel_user';
$TABLEITEMPROPERTY = $courseDbN ame . 'item_property';
$TABLEITEMPROPERTY = $course_db_n ame . 'item_property';
$TABLETOOLCOURSEDESC = $courseDbN ame . 'course_description';
$TABLETOOLCOURSEDESC = $course_db_n ame . 'course_description';
$TABLETOOLAGENDA = $courseDbN ame . 'calendar_event';
$TABLETOOLAGENDA = $course_db_n ame . 'calendar_event';
$TABLETOOLANNOUNCEMENTS = $courseDbN ame . 'announcement';
$TABLETOOLANNOUNCEMENTS = $course_db_n ame . 'announcement';
$TABLEADDEDRESOURCES = $courseDbN ame . 'resource';
$TABLEADDEDRESOURCES = $course_db_n ame . 'resource';
$TABLETOOLWORKS = $courseDbN ame . 'student_publication';
$TABLETOOLWORKS = $course_db_n ame . 'student_publication';
$TABLETOOLWORKSUSER = $courseDbN ame . 'stud_pub_rel_user';
$TABLETOOLWORKSUSER = $course_db_n ame . 'stud_pub_rel_user';
$TABLETOOLDOCUMENT = $courseDbN ame . 'document';
$TABLETOOLDOCUMENT = $course_db_n ame . 'document';
$TABLETOOLWIKI = $courseDbN ame . 'wiki';
$TABLETOOLWIKI = $course_db_n ame . 'wiki';
$TABLETOOLLINK = $courseDbN ame . 'link';
$TABLETOOLLINK = $course_db_n ame . 'link';
$TABLEQUIZ = $courseDbN ame . 'quiz';
$TABLEQUIZ = $course_db_n ame . 'quiz';
$TABLEQUIZQUESTION = $courseDbN ame . 'quiz_rel_question';
$TABLEQUIZQUESTION = $course_db_n ame . 'quiz_rel_question';
$TABLEQUIZQUESTIONLIST = $courseDbN ame . 'quiz_question';
$TABLEQUIZQUESTIONLIST = $course_db_n ame . 'quiz_question';
$TABLEQUIZANSWERSLIST = $courseDbN ame . 'quiz_answer';
$TABLEQUIZANSWERSLIST = $course_db_n ame . 'quiz_answer';
$TABLESETTING = $courseDbN ame . 'course_setting';
$TABLESETTING = $course_db_n ame . 'course_setting';
$TABLEFORUMCATEGORIES = $courseDbN ame . 'forum_category';
$TABLEFORUMCATEGORIES = $course_db_n ame . 'forum_category';
$TABLEFORUMS = $courseDbN ame . 'forum_forum';
$TABLEFORUMS = $course_db_n ame . 'forum_forum';
$TABLEFORUMTHREADS = $courseDbN ame . 'forum_thread';
$TABLEFORUMTHREADS = $course_db_n ame . 'forum_thread';
$TABLEFORUMPOSTS = $courseDbN ame . 'forum_post';
$TABLEFORUMPOSTS = $course_db_n ame . 'forum_post';
$nom = $_user['lastName'];
$nom = $_user['lastName'];
$prenom = $_user['firstName'];
$prenom = $_user['firstName'];
@ -2085,7 +2090,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
include api_get_path(SYS_CODE_PATH) . $file_to_include;
include api_get_path(SYS_CODE_PATH) . $file_to_include;
}
}
Database::select_db($courseDbN ame);
Database::select_db($course_db_n ame);
/*
/*
==============================================================================
==============================================================================
@ -2096,9 +2101,9 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
==============================================================================
==============================================================================
*/
*/
$visible4 all = 1;
$visible_for_ all = 1;
$visible4AdminOfCourse = 0;
$visible_for_course_admin = 0;
$visible4AdminOfClaroline = 2;
$visible_for_platform_admin = 2;
/*
/*
-----------------------------------------------------------
-----------------------------------------------------------
@ -2150,9 +2155,9 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
-----------------------------------------------------------
-----------------------------------------------------------
*/
*/
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_TRACKING . "','tracking/courseLog.php','statistics.gif','$visible4AdminOfCourse ','1','', 'NO','_self','admin','0')");
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_TRACKING . "','tracking/courseLog.php','statistics.gif','$visible_for_course_admin ','1','', 'NO','_self','admin','0')");
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_COURSE_SETTING . "','course_info/infocours.php','reference.gif','$visible4AdminOfCourse ','1','', 'NO','_self','admin','0')");
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_COURSE_SETTING . "','course_info/infocours.php','reference.gif','$visible_for_course_admin ','1','', 'NO','_self','admin','0')");
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL,'".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible4AdminOfCourse ','1','','NO','_self', 'admin','0')");
Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL,'".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible_for_course_admin ','1','','NO','_self', 'admin','0')");
/*
/*
-----------------------------------------------------------
-----------------------------------------------------------
@ -2196,7 +2201,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
*/
*/
global $language_interface;
global $language_interface;
// Example material in the same language
// Example material should be in the same language as the course is.
$language_interface_tmp = $language_interface;
$language_interface_tmp = $language_interface;
$language_interface = $language;
$language_interface = $language;
@ -2207,7 +2212,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
*/
*/
//Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/example_document.html','example_document.html','file','3367')");
//Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/example_document.html','example_document.html','file','3367')");
//w e need to add the document properties too!
// W e need to add the document properties too!
//$example_doc_id = Database :: insert_id();
//$example_doc_id = Database :: insert_id();
//Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,1)");
//Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,1)");
@ -2245,19 +2250,19 @@ function fill_Db_course($courseDbName, $courseRepository, $language, $default_do
foreach ($default_document_array as $media_type => $array_media) {
foreach ($default_document_array as $media_type => $array_media) {
if ($media_type == 'images') {
if ($media_type == 'images') {
$path_documents = '/images/gallery/';
$path_documents = '/images/gallery/';
$course_documents_folder = $sys_course_path.$courseR epository.'/document/images/gallery/';
$course_documents_folder = $sys_course_path.$course_r epository.'/document/images/gallery/';
}
}
if ($media_type == 'audio') {
if ($media_type == 'audio') {
$path_documents = '/audio/';
$path_documents = '/audio/';
$course_documents_folder = $sys_course_path.$courseR epository.'/document/audio/';
$course_documents_folder = $sys_course_path.$course_r epository.'/document/audio/';
}
}
if ($media_type == 'flash') {
if ($media_type == 'flash') {
$path_documents = '/flash/';
$path_documents = '/flash/';
$course_documents_folder = $sys_course_path.$courseR epository.'/document/flash/';
$course_documents_folder = $sys_course_path.$course_r epository.'/document/flash/';
}
}
if ($media_type == 'video') {
if ($media_type == 'video') {
$path_documents = '/video/';
$path_documents = '/video/';
$course_documents_folder = $sys_course_path.$courseR epository.'/document/video/';
$course_documents_folder = $sys_course_path.$course_r epository.'/document/video/';
}
}
foreach ($array_media as $key => $value) {
foreach ($array_media as $key => $value) {
if ($value['dir'] != '') {
if ($value['dir'] != '') {
@ -2406,10 +2411,10 @@ function string2binary($variable) {
/**
/**
* function register_course to create a record in the course table of the main database
* function register_course to create a record in the course table of the main database
* @param string $courseId
* @param string $course_sys_code
* @param string $courseC ode
* @param string $course_screen_c ode
* @param string $courseR epository
* @param string $course_r epository
* @param string $courseDbN ame
* @param string $course_db_n ame
* @param string $tutor_name
* @param string $tutor_name
* @param string $category
* @param string $category
* @param string $title complete name of course
* @param string $title complete name of course
@ -2419,44 +2424,44 @@ function string2binary($variable) {
* @param array Optional array of teachers' user ID
* @param array Optional array of teachers' user ID
* @return int 0
* @return int 0
*/
*/
function register_course($courseSysCode, $courseScreenCode, $courseRepository, $courseDbName, $titular, $category, $title, $course_language, $uidC reator, $expiration_date = '', $teachers = array(), $visibility = null) {
function register_course($course_sys_code, $course_screen_code, $course_repository, $course_db_name, $titular, $category, $title, $course_language, $uid_c reator, $expiration_date = '', $teachers = array(), $visibility = null) {
global $defaultVisibilityForANewCourse, $error_msg;
global $defaultVisibilityForANewCourse, $error_msg;
$TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);
$TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);
$TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$TABLEANNOUNCEMENTS = Database :: get_course_table(TABLE_ANNOUNCEMENT, $courseDbN ame);
$TABLEANNOUNCEMENTS = Database :: get_course_table(TABLE_ANNOUNCEMENT, $course_db_n ame);
$okForRegisterC ourse = true;
$ok_to_register_c ourse = true;
// Check if I have all
// Check whether all the needed parameters are present.
if (empty($courseSysC ode)) {
if (empty($course_sys_c ode)) {
$error_msg[] = 'courseSysCode is missing';
$error_msg[] = 'courseSysCode is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($courseScreenC ode)) {
if (empty($course_screen_c ode)) {
$error_msg[] = 'courseScreenCode is missing';
$error_msg[] = 'courseScreenCode is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($courseDbN ame)) {
if (empty($course_db_n ame)) {
$error_msg[] = 'courseDbName is missing';
$error_msg[] = 'courseDbName is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($courseR epository)) {
if (empty($course_r epository)) {
$error_msg[] = 'courseRepository is missing';
$error_msg[] = 'courseRepository is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($titular)) {
if (empty($titular)) {
$error_msg[] = 'titular is missing';
$error_msg[] = 'titular is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($title)) {
if (empty($title)) {
$error_msg[] = 'title is missing';
$error_msg[] = 'title is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($course_language)) {
if (empty($course_language)) {
$error_msg[] = 'language is missing';
$error_msg[] = 'language is missing';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
if (empty($expiration_date)) {
if (empty($expiration_date)) {
@ -2470,18 +2475,18 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
} else {
} else {
if ($visibility < 0 | | $ visibility > 3) {
if ($visibility < 0 | | $ visibility > 3) {
$error_msg[] = 'visibility is invalid';
$error_msg[] = 'visibility is invalid';
$okForRegisterC ourse = false;
$ok_to_register_c ourse = false;
}
}
}
}
if ($okForRegisterC ourse) {
if ($ok_to_register_c ourse) {
$titular = addslashes($titular);
$titular = addslashes($titular);
// Here we must add 2 fields.
// Here we must add 2 fields.
$sql = "INSERT INTO ".$TABLECOURSE . " SET
$sql = "INSERT INTO ".$TABLECOURSE . " SET
code = '".Database :: escape_string($courseSysC ode) . "',
code = '".Database :: escape_string($course_sys_c ode) . "',
db_name = '".Database :: escape_string($courseDbN ame) . "',
db_name = '".Database :: escape_string($course_db_n ame) . "',
directory = '".Database :: escape_string($courseR epository) . "',
directory = '".Database :: escape_string($course_r epository) . "',
course_language = '".Database :: escape_string($course_language) . "',
course_language = '".Database :: escape_string($course_language) . "',
title = '".Database :: escape_string($title) . "',
title = '".Database :: escape_string($title) . "',
description = '".lang2db(get_lang('CourseDescription')) . "',
description = '".lang2db(get_lang('CourseDescription')) . "',
@ -2494,17 +2499,17 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
last_edit = now(),
last_edit = now(),
last_visit = NULL,
last_visit = NULL,
tutor_name = '".Database :: escape_string($titular) . "',
tutor_name = '".Database :: escape_string($titular) . "',
visual_code = '".Database :: escape_string($courseScreenC ode) . "'";
visual_code = '".Database :: escape_string($course_screen_c ode) . "'";
Database::query($sql);
Database::query($sql);
$sort = api_max_sort_value('0', api_get_user_id());
$sort = api_max_sort_value('0', api_get_user_id());
require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
$i_course_sort = CourseManager :: userCourseSort($uidCreator,$courseSysC ode);
$i_course_sort = CourseManager :: userCourseSort($uid_creator, $course_sys_c ode);
$sql = "INSERT INTO ".$TABLECOURSUSER . " SET
$sql = "INSERT INTO ".$TABLECOURSUSER . " SET
course_code = '".addslashes($courseSysC ode) . "',
course_code = '".addslashes($course_sys_c ode) . "',
user_id = '".Database::escape_string($uidC reator) . "',
user_id = '".Database::escape_string($uid_c reator) . "',
status = '1',
status = '1',
role = '".lang2db(get_lang('Professor')) . "',
role = '".lang2db(get_lang('Professor')) . "',
tutor_id='0',
tutor_id='0',
@ -2515,7 +2520,7 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
if (count($teachers) > 0) {
if (count($teachers) > 0) {
foreach ($teachers as $key) {
foreach ($teachers as $key) {
$sql = "INSERT INTO ".$TABLECOURSUSER . " SET
$sql = "INSERT INTO ".$TABLECOURSUSER . " SET
course_code = '".Database::escape_string($courseSysC ode) . "',
course_code = '".Database::escape_string($course_sys_c ode) . "',
user_id = '".Database::escape_string($key) . "',
user_id = '".Database::escape_string($key) . "',
status = '1',
status = '1',
role = '',
role = '',
@ -2534,15 +2539,15 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
if (api_get_current_access_url_id() != -1) {
if (api_get_current_access_url_id() != -1) {
$url_id = api_get_current_access_url_id();
$url_id = api_get_current_access_url_id();
}
}
UrlManager::add_course_to_url($courseSysC ode, $url_id);
UrlManager::add_course_to_url($course_sys_c ode, $url_id);
} else {
} else {
UrlManager::add_course_to_url($courseSysC ode, 1);
UrlManager::add_course_to_url($course_sys_c ode, 1);
}
}
// Add event to the system log.
// Add event to the system log.
$time = time();
$time = time();
$user_id = api_get_user_id();
$user_id = api_get_user_id();
event_system(LOG_COURSE_CREATE, LOG_COURSE_CODE, $courseSysCode, $time, $user_id, $courseSysC ode);
event_system(LOG_COURSE_CREATE, LOG_COURSE_CODE, $course_sys_code, $time, $user_id, $course_sys_c ode);
$send_mail_to_admin = api_get_setting('send_email_to_admin_when_create_course');
$send_mail_to_admin = api_get_setting('send_email_to_admin_when_create_course');
@ -2570,20 +2575,18 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $
/**
/**
* WARNING: This function always returns true.
* WARNING: This function always returns true.
*/
*/
function checkArchive($pathToA rchive) {
function checkArchive($path_to_a rchive) {
return true;
return true;
}
}
/**
/**
* TODO: This function is not used anywhere. Probably it is obsolete.
*
* Extract properties of the files from a ZIP package, write them to disk and
* Extract properties of the files from a ZIP package, write them to disk and
* return them as an array.
* return them as an array.
* @param string Absolute path to the ZIP file
* @param string Absolute path to the ZIP file
* @param bool Whether the ZIP file is compressed (not implemented). Defaults to TRUE.
* @param bool Whether the ZIP file is compressed (not implemented). Defaults to TRUE.
* @return array List of files properties from the ZIP package
* @return array List of files properties from the ZIP package
*/
*/
function readPropertiesInArchive($archive, $isC ompressed = true) {
function readPropertiesInArchive($archive, $is_c ompressed = true) {
include api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
include api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
debug::printVar(dirname($archive), 'Zip : ');
debug::printVar(dirname($archive), 'Zip : ');
$uid = api_get_user_id();
$uid = api_get_user_id();
@ -2600,16 +2603,16 @@ function readPropertiesInArchive($archive, $isCompressed = true) {
details.
details.
tempnam() returns the temporary filename, or the string NULL upon failure.
tempnam() returns the temporary filename, or the string NULL upon failure.
*/
*/
$zipF ile = new pclZip($archive);
$zip_f ile = new pclZip($archive);
$tmpDirN ame = dirname($archive) . '/tmp'.$uid.uniqid($uid);
$tmp_dir_n ame = dirname($archive) . '/tmp'.$uid.uniqid($uid);
if (mkdir($tmpDirN ame, api_get_permissions_for_new_directories(), true)) {
if (mkdir($tmp_dir_n ame, api_get_permissions_for_new_directories(), true)) {
$unzippingSate = $zipFile->extract($tmpDirN ame);
$unzipping_state = $zip_file->extract($tmp_dir_n ame);
} else {
} else {
die ('mkdir failed');
die ('mkdir failed');
}
}
$pathToArchiveIni = dirname($tmpDirN ame) . '/archive.ini';
$path_to_archive_ini = dirname($tmp_dir_n ame) . '/archive.ini';
//echo $pathToArchiveI ni;
//echo $path_to_archive_i ni;
$courseProperties = parse_ini_file($pathToArchiveI ni);
$course_properties = parse_ini_file($path_to_archive_i ni);
rmdir($tmpDirN ame);
rmdir($tmp_dir_n ame);
return $courseP roperties;
return $course_p roperties;
}
}