|
|
|
|
@ -1,7 +1,10 @@ |
|
|
|
|
<?php |
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\AccessUrlRelCourse; |
|
|
|
|
use Chamilo\CoreBundle\Entity\CourseRelUser; |
|
|
|
|
use Chamilo\CourseBundle\Entity\CToolIntro; |
|
|
|
|
use Doctrine\ORM\OptimisticLockException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class AddCourse. |
|
|
|
|
@ -84,122 +87,6 @@ class AddCourse |
|
|
|
|
return $keys; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Initializes a file repository for a newly created course. |
|
|
|
|
* |
|
|
|
|
* @param string Course repository |
|
|
|
|
* @param string Course code |
|
|
|
|
* |
|
|
|
|
* @return int |
|
|
|
|
* @assert (null,null) === false |
|
|
|
|
*/ |
|
|
|
|
public static function prepare_course_repository($course_repository) |
|
|
|
|
{ |
|
|
|
|
$perm = api_get_permissions_for_new_directories(); |
|
|
|
|
$perm_file = api_get_permissions_for_new_files(); |
|
|
|
|
$htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>"; |
|
|
|
|
$cp = api_get_path(SYS_COURSE_PATH).$course_repository; |
|
|
|
|
|
|
|
|
|
//Creating document folder |
|
|
|
|
mkdir($cp, $perm); |
|
|
|
|
mkdir($cp.'/document', $perm); |
|
|
|
|
$cpt = $cp.'/document/index.html'; |
|
|
|
|
$fd = fopen($cpt, 'w'); |
|
|
|
|
fwrite($fd, $htmlpage); |
|
|
|
|
fclose($fd); |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
@chmod($cpt, $perm_file); |
|
|
|
|
@copy($cpt, $cp . '/document/index.html'); |
|
|
|
|
mkdir($cp . '/document/images', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/images/index.html'); |
|
|
|
|
mkdir($cp . '/document/images/gallery/', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/images/gallery/index.html'); |
|
|
|
|
mkdir($cp . '/document/shared_folder/', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/shared_folder/index.html'); |
|
|
|
|
mkdir($cp . '/document/audio', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/audio/index.html'); |
|
|
|
|
mkdir($cp . '/document/flash', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/flash/index.html'); |
|
|
|
|
mkdir($cp . '/document/video', $perm); |
|
|
|
|
@copy($cpt, $cp . '/document/video/index.html'); */ |
|
|
|
|
|
|
|
|
|
//Creatind dropbox folder |
|
|
|
|
mkdir($cp.'/dropbox', $perm); |
|
|
|
|
$cpt = $cp.'/dropbox/index.html'; |
|
|
|
|
$fd = fopen($cpt, 'w'); |
|
|
|
|
fwrite($fd, $htmlpage); |
|
|
|
|
fclose($fd); |
|
|
|
|
@chmod($cpt, $perm_file); |
|
|
|
|
mkdir($cp.'/group', $perm); |
|
|
|
|
@copy($cpt, $cp.'/group/index.html'); |
|
|
|
|
mkdir($cp.'/page', $perm); |
|
|
|
|
@copy($cpt, $cp.'/page/index.html'); |
|
|
|
|
mkdir($cp.'/scorm', $perm); |
|
|
|
|
@copy($cpt, $cp.'/scorm/index.html'); |
|
|
|
|
mkdir($cp.'/upload', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/index.html'); |
|
|
|
|
mkdir($cp.'/upload/forum', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/forum/index.html'); |
|
|
|
|
mkdir($cp.'/upload/forum/images', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/forum/images/index.html'); |
|
|
|
|
mkdir($cp.'/upload/test', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/test/index.html'); |
|
|
|
|
mkdir($cp.'/upload/blog', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/blog/index.html'); |
|
|
|
|
mkdir($cp.'/upload/learning_path', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/learning_path/index.html'); |
|
|
|
|
mkdir($cp.'/upload/learning_path/images', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/learning_path/images/index.html'); |
|
|
|
|
mkdir($cp.'/upload/calendar', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/calendar/index.html'); |
|
|
|
|
mkdir($cp.'/upload/calendar/images', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/calendar/images/index.html'); |
|
|
|
|
mkdir($cp.'/work', $perm); |
|
|
|
|
@copy($cpt, $cp.'/work/index.html'); |
|
|
|
|
mkdir($cp.'/upload/announcements', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/announcements/index.html'); |
|
|
|
|
mkdir($cp.'/upload/announcements/images', $perm); |
|
|
|
|
@copy($cpt, $cp.'/upload/announcements/images/index.html'); |
|
|
|
|
|
|
|
|
|
//Oral expression question type |
|
|
|
|
mkdir($cp.'/exercises', $perm); |
|
|
|
|
@copy($cpt, $cp.'/exercises/index.html'); |
|
|
|
|
|
|
|
|
|
// Create .htaccess in the dropbox directory. |
|
|
|
|
$fp = fopen($cp.'/dropbox/.htaccess', 'w'); |
|
|
|
|
fwrite( |
|
|
|
|
$fp, |
|
|
|
|
"AuthName AllowLocalAccess |
|
|
|
|
AuthType Basic |
|
|
|
|
|
|
|
|
|
order deny,allow |
|
|
|
|
deny from all |
|
|
|
|
|
|
|
|
|
php_flag zlib.output_compression off" |
|
|
|
|
); |
|
|
|
|
fclose($fp); |
|
|
|
|
|
|
|
|
|
// Build index.php of the course. |
|
|
|
|
/*$fd = fopen($cp . '/index.php', 'w'); |
|
|
|
|
|
|
|
|
|
// str_replace() removes \r that cause squares to appear at the end of each line |
|
|
|
|
//@todo fix the harcoded include |
|
|
|
|
$string = str_replace( |
|
|
|
|
"\r", |
|
|
|
|
"", |
|
|
|
|
"<?" . "php |
|
|
|
|
\$cidReq = \"$course_code\"; |
|
|
|
|
\$dbname = \"$course_code\"; |
|
|
|
|
|
|
|
|
|
include(\"" . api_get_path(SYS_CODE_PATH) . "course_home/course_home.php\"); |
|
|
|
|
?>" |
|
|
|
|
); |
|
|
|
|
fwrite($fd, $string); |
|
|
|
|
@chmod($cp . '/index.php', $perm_file);*/ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets an array with all the course tables (deprecated?). |
|
|
|
|
* |
|
|
|
|
@ -430,204 +317,11 @@ class AddCourse |
|
|
|
|
$courseInfo = api_get_course_info_by_id($course_id); |
|
|
|
|
$authorId = empty($authorId) ? api_get_user_id() : (int) $authorId; |
|
|
|
|
|
|
|
|
|
$tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST); |
|
|
|
|
$TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); |
|
|
|
|
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
|
$TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
|
|
|
|
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); |
|
|
|
|
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
|
|
|
|
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
|
|
|
$visible_for_course_admin = 0; |
|
|
|
|
/* Course tools */ |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 1, '".TOOL_COURSE_DESCRIPTION."','course_description/index.php','info.gif','".self::string2binary( |
|
|
|
|
api_get_setting( |
|
|
|
|
'course_create_active_tools', |
|
|
|
|
'course_description' |
|
|
|
|
) |
|
|
|
|
)."','0','squaregrey.gif', 0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 2, '".TOOL_CALENDAR_EVENT."','calendar/agenda.php','agenda.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'agenda') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 3, '".TOOL_DOCUMENT."','document/document.php','folder_document.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'documents') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 4, '".TOOL_LEARNPATH."','lp/lp_controller.php','scorms.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'learning_path') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 5, '".TOOL_LINK."','link/link.php','links.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'links') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 6, '".TOOL_QUIZ."','exercise/exercise.php','quiz.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'quiz') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 7, '".TOOL_ANNOUNCEMENT."','announcements/announcements.php','valves.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'announcements') |
|
|
|
|
)."','0','squaregrey.gif', 0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 8, '".TOOL_FORUM."','forum/index.php','forum.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'forums') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 9, '".TOOL_DROPBOX."','dropbox/index.php','dropbox.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'dropbox') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 10, '".TOOL_USER."','user/user.php','members.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'users') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 11, '".TOOL_GROUP."','group/group.php','group.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'groups') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 12, '".TOOL_CHAT."','chat/chat.php','chat.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'chat') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 13, '".TOOL_STUDENTPUBLICATION."','work/work.php','works.gif','".self::string2binary( |
|
|
|
|
api_get_setting( |
|
|
|
|
'course_create_active_tools', |
|
|
|
|
'student_publications' |
|
|
|
|
) |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 14, '".TOOL_SURVEY."','survey/survey_list.php','survey.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'survey') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 15, '".TOOL_WIKI."','wiki/index.php','wiki.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'wiki') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 16, '".TOOL_GRADEBOOK."','gradebook/index.php','gradebook.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'gradebook') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 17, '".TOOL_GLOSSARY."','glossary/index.php','glossary.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'glossary') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 18, '".TOOL_NOTEBOOK."','notebook/index.php','notebook.gif','".self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'notebook') |
|
|
|
|
)."','0','squaregrey.gif',0,'_self','interaction','0')" |
|
|
|
|
); |
|
|
|
|
if (api_get_configuration_value('allow_portfolio_tool')) { |
|
|
|
|
$tId = Database::insert( |
|
|
|
|
$tbl_course_homepage, |
|
|
|
|
[ |
|
|
|
|
'c_id' => $course_id, |
|
|
|
|
'name' => 'portfolio', |
|
|
|
|
'link' => 'portfolio/index.php', |
|
|
|
|
'image' => 'wiki_task.png', |
|
|
|
|
'visibility' => api_get_setting('course_create_active_tools', 'portfolio') == 'true' ? 1 : 0, |
|
|
|
|
'admin' => 0, |
|
|
|
|
'address' => 'squaregrey.gif', |
|
|
|
|
'added_tool' => 0, |
|
|
|
|
'target' => '_self', |
|
|
|
|
'category' => 'interaction', |
|
|
|
|
'session_id' => 0, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
Database::update( |
|
|
|
|
$tbl_course_homepage, |
|
|
|
|
['id' => $tId], |
|
|
|
|
['iid = ?' => $tId] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$setting = intval(self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'attendances') |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 19, '".TOOL_ATTENDANCE."','attendance/index.php','attendance.gif','".$setting."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$setting = intval(self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'course_progress') |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 20, '".TOOL_COURSE_PROGRESS."','course_progress/index.php','course_progress.gif','".$setting."','0','squaregrey.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (api_get_setting('search_enabled') === 'true') { |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 23, '".TOOL_SEARCH."','search/','info.gif','".self::string2binary( |
|
|
|
|
api_get_setting( |
|
|
|
|
'course_create_active_tools', |
|
|
|
|
'enable_search' |
|
|
|
|
) |
|
|
|
|
)."','0','search.gif',0,'_self','authoring','0')" |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 24,'".TOOL_BLOGS."','blog/blog_admin.php','blog_admin.gif','".intval( |
|
|
|
|
self::string2binary( |
|
|
|
|
api_get_setting('course_create_active_tools', 'blogs') |
|
|
|
|
) |
|
|
|
|
)."','1','squaregrey.gif',0,'_self','admin','0')"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
/* Course homepage tools for course admin only */ |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 25, '".TOOL_TRACKING."','tracking/courseLog.php','statistics.gif','$visible_for_course_admin','1','', 0,'_self','admin','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 26, '".TOOL_COURSE_SETTING."','course_info/infocours.php','reference.gif','$visible_for_course_admin','1','', 0,'_self','admin','0')" |
|
|
|
|
); |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
|
|
|
|
VALUES ($course_id, 27, '".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible_for_course_admin','1','',0,'_self', 'admin','0')" |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$alert = api_get_setting('email_alert_manager_on_new_quiz'); |
|
|
|
|
if ($alert === 'true') { |
|
|
|
|
@ -636,46 +330,6 @@ class AddCourse |
|
|
|
|
$defaultEmailExerciseAlert = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* course_setting table (courseinfo tool) */ |
|
|
|
|
$settings = [ |
|
|
|
|
'email_alert_manager_on_new_doc' => ['title' => '', 'default' => 0, 'category' => 'work'], |
|
|
|
|
'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], |
|
|
|
|
'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], |
|
|
|
|
'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], |
|
|
|
|
'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], |
|
|
|
|
'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], |
|
|
|
|
'course_theme' => ['default' => '', 'category' => 'theme'], |
|
|
|
|
'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], |
|
|
|
|
'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], |
|
|
|
|
'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'], |
|
|
|
|
'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'], |
|
|
|
|
'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'], |
|
|
|
|
'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'], |
|
|
|
|
'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'], |
|
|
|
|
'enable_exercise_auto_launch' => ['default' => 0, 'category' => 'exercise'], |
|
|
|
|
'enable_document_auto_launch' => ['default' => 0, 'category' => 'document'], |
|
|
|
|
'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'], |
|
|
|
|
'allow_public_certificates' => [ |
|
|
|
|
'default' => api_get_setting('allow_public_certificates') === 'true' ? 1 : '', |
|
|
|
|
'category' => 'certificates', |
|
|
|
|
], |
|
|
|
|
'documents_default_visibility' => ['default' => 'visible', 'category' => 'document'], |
|
|
|
|
'show_course_in_user_language' => ['default' => 2, 'category' => null], |
|
|
|
|
'email_to_teachers_on_new_work_feedback' => ['default' => 1, 'category' => null], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$counter = 1; |
|
|
|
|
foreach ($settings as $variable => $setting) { |
|
|
|
|
$title = isset($setting['title']) ? $setting['title'] : ''; |
|
|
|
|
Database::query( |
|
|
|
|
"INSERT INTO $TABLESETTING (id, c_id, title, variable, value, category) |
|
|
|
|
VALUES ($counter, $course_id, '".$title."', '".$variable."', '".$setting['default']."', '".$setting['category']."')" |
|
|
|
|
); |
|
|
|
|
$counter++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Course homepage tools for platform admin only */ |
|
|
|
|
|
|
|
|
|
/* Group tool */ |
|
|
|
|
Database::insert( |
|
|
|
|
$TABLEGROUPCATEGORIES, |
|
|
|
|
@ -1200,240 +854,183 @@ class AddCourse |
|
|
|
|
*/ |
|
|
|
|
public static function register_course($params, $accessUrlId = 1) |
|
|
|
|
{ |
|
|
|
|
global $error_msg, $firstExpirationDelay; |
|
|
|
|
$title = $params['title']; |
|
|
|
|
// Fix amp |
|
|
|
|
$title = str_replace('&', '&', $title); |
|
|
|
|
$code = $params['code']; |
|
|
|
|
$visual_code = $params['visual_code']; |
|
|
|
|
$directory = $params['directory']; |
|
|
|
|
$tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null; |
|
|
|
|
$category_code = isset($params['course_category']) ? $params['course_category'] : ''; |
|
|
|
|
$course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting( |
|
|
|
|
'platformLanguage' |
|
|
|
|
); |
|
|
|
|
$user_id = empty($params['user_id']) ? api_get_user_id() : (int) $params['user_id']; |
|
|
|
|
$department_name = isset($params['department_name']) ? $params['department_name'] : null; |
|
|
|
|
$department_url = isset($params['department_url']) ? $params['department_url'] : null; |
|
|
|
|
$disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null; |
|
|
|
|
|
|
|
|
|
if (!isset($params['visibility'])) { |
|
|
|
|
$default_course_visibility = api_get_setting( |
|
|
|
|
'courses_default_creation_visibility' |
|
|
|
|
); |
|
|
|
|
if (isset($default_course_visibility)) { |
|
|
|
|
$visibility = $default_course_visibility; |
|
|
|
|
} else { |
|
|
|
|
$visibility = COURSE_VISIBILITY_OPEN_PLATFORM; |
|
|
|
|
$title = str_replace('&', '&', $params['title']); |
|
|
|
|
$code = array_key_exists('code', $params) ? $params['code'] : null; |
|
|
|
|
$visualCode = array_key_exists('visual_code', $params) ? $params['visual_code'] : null; |
|
|
|
|
$directory = array_key_exists('directory', $params) ? $params['directory'] : null; |
|
|
|
|
$tutorName = array_key_exists('tutor_name', $params) ? $params['tutor_name'] : null; |
|
|
|
|
$categoryCode = array_key_exists('course_category', $params) ? $params['course_category'] : ''; |
|
|
|
|
$courseLanguage = array_key_exists('course_language', $params) && !empty($params['course_language']) |
|
|
|
|
? $params['course_language'] |
|
|
|
|
: api_get_setting('platformLanguage'); |
|
|
|
|
$userId = empty($params['user_id']) ? api_get_user_id() : (int) $params['user_id']; |
|
|
|
|
$departmentName = array_key_exists('department_name', $params) ? $params['department_name'] : null; |
|
|
|
|
$departmentUrl = array_key_exists('department_url', $params) ? $params['department_url'] : null; |
|
|
|
|
$diskQuota = array_key_exists('disk_quota', $params) ? $params['disk_quota'] : null; |
|
|
|
|
$visibility = array_key_exists('visibility', $params) ? $params['visibility'] : null; |
|
|
|
|
$subscribe = array_key_exists('subscribe', $params) ? $params['subscribe'] : null; |
|
|
|
|
$unsubscribe = array_key_exists('unsubscribe', $params) ? $params['unsubscribe'] : null; |
|
|
|
|
$teachers = array_key_exists('teachers', $params) ? $params['teachers'] : null; |
|
|
|
|
|
|
|
|
|
$expirationDate = null; |
|
|
|
|
if (array_key_exists('expiration_date', $params)) { |
|
|
|
|
$date = $params['expiration_date']; |
|
|
|
|
try { |
|
|
|
|
$expirationDate = new DateTime(api_get_utc_datetime($date), new DateTimeZone('utc')); |
|
|
|
|
} catch (Exception $exception) { |
|
|
|
|
error_log(sprintf('expiration_date "%s" is invalid', $date)); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$visibility = $params['visibility']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($params['subscribe'])) { |
|
|
|
|
$subscribe = (int) $params['subscribe']; |
|
|
|
|
} else { |
|
|
|
|
$subscribe = $visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0; |
|
|
|
|
} |
|
|
|
|
$unsubscribe = isset($params['unsubscribe']) ? (int) $params['unsubscribe'] : 0; |
|
|
|
|
$expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null; |
|
|
|
|
$teachers = isset($params['teachers']) ? $params['teachers'] : null; |
|
|
|
|
$status = isset($params['status']) ? $params['status'] : null; |
|
|
|
|
$user = api_get_user_entity($userId); |
|
|
|
|
if (is_null($user)) { |
|
|
|
|
error_log(sprintf('user_id "%s" is invalid', $userId)); |
|
|
|
|
|
|
|
|
|
$TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE); |
|
|
|
|
$TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
|
|
|
|
|
|
|
|
|
$ok_to_register_course = true; |
|
|
|
|
|
|
|
|
|
// Check whether all the needed parameters are present. |
|
|
|
|
if (empty($code)) { |
|
|
|
|
$error_msg[] = 'courseSysCode is missing'; |
|
|
|
|
$ok_to_register_course = false; |
|
|
|
|
} |
|
|
|
|
if (empty($visual_code)) { |
|
|
|
|
$error_msg[] = 'courseScreenCode is missing'; |
|
|
|
|
$ok_to_register_course = false; |
|
|
|
|
} |
|
|
|
|
if (empty($directory)) { |
|
|
|
|
$error_msg[] = 'courseRepository is missing'; |
|
|
|
|
$ok_to_register_course = false; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($title)) { |
|
|
|
|
$error_msg[] = 'title is missing'; |
|
|
|
|
$ok_to_register_course = false; |
|
|
|
|
$course = (new \Chamilo\CoreBundle\Entity\Course()) |
|
|
|
|
->setCode($code) |
|
|
|
|
->setDirectory($directory) |
|
|
|
|
->setCourseLanguage($courseLanguage) |
|
|
|
|
->setTitle($title) |
|
|
|
|
->setCategoryCode($categoryCode) |
|
|
|
|
->setVisibility($visibility) |
|
|
|
|
->setDiskQuota($diskQuota) |
|
|
|
|
->setExpirationDate($expirationDate) |
|
|
|
|
->setTutorName($tutorName) |
|
|
|
|
->setDepartmentName($departmentName) |
|
|
|
|
->setDepartmentUrl($departmentUrl) |
|
|
|
|
->setSubscribe($subscribe) |
|
|
|
|
->setUnsubscribe($unsubscribe) |
|
|
|
|
->setVisualCode($visualCode) |
|
|
|
|
; |
|
|
|
|
Database::getManager()->persist($course); |
|
|
|
|
|
|
|
|
|
$addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true; |
|
|
|
|
if ($addTeacher) { |
|
|
|
|
$iCourseSort = CourseManager::userCourseSort($userId, $code); |
|
|
|
|
$courseRelTutor = (new CourseRelUser()) |
|
|
|
|
->setCourse($course) |
|
|
|
|
->setUser($user) |
|
|
|
|
->setStatus(true) |
|
|
|
|
->setTutor(true) |
|
|
|
|
->setSort($iCourseSort) |
|
|
|
|
->setRelationType(0) |
|
|
|
|
->setUserCourseCat(0) |
|
|
|
|
; |
|
|
|
|
Database::getManager()->persist($courseRelTutor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($expiration_date)) { |
|
|
|
|
$expiration_date = api_get_utc_datetime( |
|
|
|
|
time() + $firstExpirationDelay |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
$expiration_date = api_get_utc_datetime($expiration_date); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($visibility < 0 || $visibility > 4) { |
|
|
|
|
$error_msg[] = 'visibility is invalid'; |
|
|
|
|
$ok_to_register_course = false; |
|
|
|
|
if (!empty($teachers)) { |
|
|
|
|
$sort = $user->getMaxSortValue(); |
|
|
|
|
if (!is_array($teachers)) { |
|
|
|
|
$teachers = [$teachers]; |
|
|
|
|
} |
|
|
|
|
foreach ($teachers as $key) { |
|
|
|
|
// Just in case. |
|
|
|
|
if ($key == $userId) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (empty($key)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$teacher = api_get_user_entity($key); |
|
|
|
|
if (is_null($teacher)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$courseRelTeacher = (new CourseRelUser()) |
|
|
|
|
->setCourse($course) |
|
|
|
|
->setUser($teacher) |
|
|
|
|
->setStatus(true) |
|
|
|
|
->setTutor(false) |
|
|
|
|
->setSort($sort + 1) |
|
|
|
|
->setRelationType(0) |
|
|
|
|
->setUserCourseCat(0) |
|
|
|
|
; |
|
|
|
|
Database::getManager()->persist($courseRelTeacher); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($disk_quota)) { |
|
|
|
|
$disk_quota = api_get_setting('default_document_quotum'); |
|
|
|
|
// Adding the course to an URL. |
|
|
|
|
$url = api_get_access_url_entity($accessUrlId); |
|
|
|
|
if (!is_null($url)) { |
|
|
|
|
$urlRelCourse = (new AccessUrlRelCourse()) |
|
|
|
|
->setCourse($course) |
|
|
|
|
->setUrl($url); |
|
|
|
|
Database::getManager()->persist($urlRelCourse); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$time = api_get_utc_datetime(); |
|
|
|
|
try { |
|
|
|
|
Database::getManager()->flush(); |
|
|
|
|
} catch (OptimisticLockException $exception) { |
|
|
|
|
error_log($exception); |
|
|
|
|
|
|
|
|
|
if (stripos($department_url, 'http://') === false && stripos( |
|
|
|
|
$department_url, |
|
|
|
|
'https://' |
|
|
|
|
) === false |
|
|
|
|
) { |
|
|
|
|
$department_url = 'http://'.$department_url; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
// Just in case |
|
|
|
|
if ($department_url === 'http://') { |
|
|
|
|
$department_url = ''; |
|
|
|
|
} |
|
|
|
|
$course_id = 0; |
|
|
|
|
|
|
|
|
|
if ($ok_to_register_course) { |
|
|
|
|
// Here we must add 2 fields. |
|
|
|
|
$course_id = Database::insert( |
|
|
|
|
$TABLECOURSE, |
|
|
|
|
[ |
|
|
|
|
'code' => $code, |
|
|
|
|
'directory' => $directory, |
|
|
|
|
'course_language' => $course_language, |
|
|
|
|
'title' => $title, |
|
|
|
|
'description' => get_lang('CourseDescription'), |
|
|
|
|
'category_code' => $category_code, |
|
|
|
|
'visibility' => $visibility, |
|
|
|
|
'show_score' => 1, |
|
|
|
|
'disk_quota' => (int) $disk_quota, |
|
|
|
|
'creation_date' => $time, |
|
|
|
|
'expiration_date' => $expiration_date, |
|
|
|
|
'last_edit' => $time, |
|
|
|
|
'last_visit' => null, |
|
|
|
|
'tutor_name' => $tutor_name, |
|
|
|
|
'department_name' => $department_name, |
|
|
|
|
'department_url' => $department_url, |
|
|
|
|
'subscribe' => $subscribe, |
|
|
|
|
'unsubscribe' => $unsubscribe, |
|
|
|
|
'visual_code' => $visual_code, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($course_id) { |
|
|
|
|
$sort = api_max_sort_value('0', api_get_user_id()); |
|
|
|
|
// Default true |
|
|
|
|
$addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true; |
|
|
|
|
if ($addTeacher) { |
|
|
|
|
$i_course_sort = CourseManager:: userCourseSort( |
|
|
|
|
$user_id, |
|
|
|
|
$code |
|
|
|
|
); |
|
|
|
|
if (!empty($user_id)) { |
|
|
|
|
$sql = "INSERT INTO $TABLECOURSUSER SET |
|
|
|
|
c_id = $course_id, |
|
|
|
|
user_id = '".intval($user_id)."', |
|
|
|
|
status = '1', |
|
|
|
|
is_tutor = '0', |
|
|
|
|
sort = '".($i_course_sort)."', |
|
|
|
|
relation_type = 0, |
|
|
|
|
user_course_cat = '0'"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($teachers)) { |
|
|
|
|
if (!is_array($teachers)) { |
|
|
|
|
$teachers = [$teachers]; |
|
|
|
|
} |
|
|
|
|
foreach ($teachers as $key) { |
|
|
|
|
// Just in case. |
|
|
|
|
if ($key == $user_id) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (empty($key)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$sql = "INSERT INTO ".$TABLECOURSUSER." SET |
|
|
|
|
c_id = '".Database::escape_string($course_id)."', |
|
|
|
|
user_id = '".Database::escape_string($key)."', |
|
|
|
|
status = '1', |
|
|
|
|
is_tutor = '0', |
|
|
|
|
sort = '".($sort + 1)."', |
|
|
|
|
relation_type = 0, |
|
|
|
|
user_course_cat = '0'"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$courseId = $course->getId(); |
|
|
|
|
|
|
|
|
|
// Add event to the system log. |
|
|
|
|
$userId = api_get_user_id(); |
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_COURSE_CREATE, |
|
|
|
|
LOG_COURSE_CODE, |
|
|
|
|
$code, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
$userId, |
|
|
|
|
$courseId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Adding the course to an URL. |
|
|
|
|
UrlManager::add_course_to_url($course_id, $accessUrlId); |
|
|
|
|
|
|
|
|
|
// Add event to the system log. |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_COURSE_CREATE, |
|
|
|
|
LOG_COURSE_CODE, |
|
|
|
|
$code, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
$user_id, |
|
|
|
|
$course_id |
|
|
|
|
); |
|
|
|
|
$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'); |
|
|
|
|
// @todo Improve code to send to all current portal administrators. |
|
|
|
|
if ($send_mail_to_admin === 'true') { |
|
|
|
|
$siteName = api_get_setting('siteName'); |
|
|
|
|
$recipient_email = api_get_setting('emailAdministrator'); |
|
|
|
|
$recipient_name = api_get_person_name( |
|
|
|
|
api_get_setting('administratorName'), |
|
|
|
|
api_get_setting('administratorSurname') |
|
|
|
|
); |
|
|
|
|
$iname = api_get_setting('Institution'); |
|
|
|
|
$subject = get_lang('NewCourseCreatedIn').' '.$siteName.' - '.$iname; |
|
|
|
|
$message = get_lang( |
|
|
|
|
'Dear' |
|
|
|
|
).' '.$recipient_name.",\n\n".get_lang( |
|
|
|
|
'MessageOfNewCourseToAdmin' |
|
|
|
|
).' '.$siteName.' - '.$iname."\n"; |
|
|
|
|
$message .= get_lang('CourseName').' '.$title."\n"; |
|
|
|
|
$message .= get_lang( |
|
|
|
|
'Category' |
|
|
|
|
).' '.$categoryCode."\n"; |
|
|
|
|
$message .= get_lang('Tutor').' '.$tutorName."\n"; |
|
|
|
|
$message .= get_lang('Language').' '.$courseLanguage; |
|
|
|
|
|
|
|
|
|
$userInfo = api_get_user_info($userId); |
|
|
|
|
$additionalParameters = [ |
|
|
|
|
'smsType' => SmsPlugin::NEW_COURSE_BEEN_CREATED, |
|
|
|
|
'userId' => $userId, |
|
|
|
|
'courseName' => $title, |
|
|
|
|
'creatorUsername' => $userInfo['username'], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// @todo Improve code to send to all current portal administrators. |
|
|
|
|
if ($send_mail_to_admin === 'true') { |
|
|
|
|
$siteName = api_get_setting('siteName'); |
|
|
|
|
$recipient_email = api_get_setting('emailAdministrator'); |
|
|
|
|
$recipient_name = api_get_person_name( |
|
|
|
|
api_get_setting('administratorName'), |
|
|
|
|
api_get_setting('administratorSurname') |
|
|
|
|
); |
|
|
|
|
$iname = api_get_setting('Institution'); |
|
|
|
|
$subject = get_lang( |
|
|
|
|
'NewCourseCreatedIn' |
|
|
|
|
).' '.$siteName.' - '.$iname; |
|
|
|
|
$message = get_lang( |
|
|
|
|
'Dear' |
|
|
|
|
).' '.$recipient_name.",\n\n".get_lang( |
|
|
|
|
'MessageOfNewCourseToAdmin' |
|
|
|
|
).' '.$siteName.' - '.$iname."\n"; |
|
|
|
|
$message .= get_lang('CourseName').' '.$title."\n"; |
|
|
|
|
$message .= get_lang( |
|
|
|
|
'Category' |
|
|
|
|
).' '.$category_code."\n"; |
|
|
|
|
$message .= get_lang('Tutor').' '.$tutor_name."\n"; |
|
|
|
|
$message .= get_lang('Language').' '.$course_language; |
|
|
|
|
|
|
|
|
|
$userInfo = api_get_user_info($user_id); |
|
|
|
|
$additionalParameters = [ |
|
|
|
|
'smsType' => SmsPlugin::NEW_COURSE_BEEN_CREATED, |
|
|
|
|
'userId' => $user_id, |
|
|
|
|
'courseName' => $title, |
|
|
|
|
'creatorUsername' => $userInfo['username'], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
api_mail_html( |
|
|
|
|
$recipient_name, |
|
|
|
|
$recipient_email, |
|
|
|
|
$subject, |
|
|
|
|
$message, |
|
|
|
|
$siteName, |
|
|
|
|
$recipient_email, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$additionalParameters |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
api_mail_html( |
|
|
|
|
$recipient_name, |
|
|
|
|
$recipient_email, |
|
|
|
|
$subject, |
|
|
|
|
$message, |
|
|
|
|
$siteName, |
|
|
|
|
$recipient_email, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$additionalParameters |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $course_id; |
|
|
|
|
return $courseId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|