diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 7324c5ca45..ef56c7575b 100644 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -151,7 +151,7 @@ if ($form->validate()) { $course_info = CourseManager::create_course($course); - header('Location: course_list.php'); + header('Location: course_list.php'.($course_info===false?'?action=show_msg&warn='.api_get_last_failure():'')); exit; } @@ -162,4 +162,4 @@ $tpl = new Template($tool_name); $tpl->assign('actions', $actions); $tpl->assign('message', $message); $tpl->assign('content', $content); -$tpl->display_one_col_template(); \ No newline at end of file +$tpl->display_one_col_template(); diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index eab67c2142..387750b33e 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -118,6 +118,16 @@ class CourseManager { function create_course($params) { global $_configuration; + $access_url_id = 1; + if (api_get_multiple_access_url()) { + $access_url_id = api_get_current_access_url_id(); + } + if ($_configuration[$access_url_id]['hosting_limit_courses'] > 0) { + $num = self::count_courses(); + if ($num >= $_configuration[$access_url_id]['hosting_limit_courses']) { + return api_set_failure('PortalCoursesLimitReached'); + } + } if (empty($params['title'])) { return false; } @@ -2044,7 +2054,7 @@ class CourseManager { $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." WHERE course_code='".$course_code."'"; // TODO: Ivan: This is a mistake, please, have a look at it. Intention here is diffcult to be guessed. - //if ($send_to_tutor_also = true) { + //if ($send_to_tutor_also = true) // Proposed change: if ($send_to_tutor_also) { // @@ -3737,6 +3747,16 @@ class CourseManager { return ResultSet::create($sql); } - + + /** + * Get courses count + */ + public function count_courses() { + $table_course = Database::get_main_table(TABLE_MAIN_COURSE); + $sql = "SELECT count(id) FROM $table_course"; + $res = Database::query($sql); + $row = Database::fetch_array($res,0); + return $row; + } -} //end class CourseManager \ No newline at end of file +} //end class CourseManager