, Ghent University * @author Roan Embrechts, refactoring * @package chamilo.create_course * "Course validation" feature: * @author Jose Manuel Abuin Mosquera , Centro de Supercomputacion de Galicia * "Course validation" feature, technical adaptation for Chamilo 1.8.8: * @author Ivan Tcholakov */ /** * Code */ // Name of the language file that needs to be included. $language_file = array('create_course', 'registration','admin','exercice', 'course_description', 'course_info'); // Flag forcing the "current course" reset. $cidReset = true; // Including the global initialization file. require_once '../inc/global.inc.php'; // Section for the tabs. $this_section = SECTION_COURSES; // "Course validation" feature. This value affects the way of a new course creation: // true - the new course is requested only and it is created after approval; // false - the new course is created immedialely, after filling this form. $course_validation_feature = api_get_setting('course_validation') == 'true'; // Require additional libraries. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php'; if ($course_validation_feature) { require_once api_get_path(LIBRARY_PATH).'course_request.lib.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; } $htmlHeadXtra[] = ''; $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses')); // Displaying the header. $tool_name = $course_validation_feature ? get_lang('CreateCourseRequest') : get_lang('CreateSite'); $tpl = new Template($tool_name); if (api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) { api_not_allowed(true); } // Check access rights. if (!api_is_allowed_to_create_course()) { api_not_allowed(true); exit; } global $_configuration; $dbnamelength = strlen($_configuration['db_prefix']); // Ensure the database prefix + database name do not get over 40 characters. $maxlength = 40 - $dbnamelength; // Build the form. $form = new FormValidator('add_course'); // Form title $form->addElement('header', '', $tool_name); // Title $form->addElement('text', 'title', array(get_lang('CourseName'), get_lang('Ex')), array('class' => 'span6', 'id' => 'title')); $form->applyFilter('title', 'html_filter'); $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); $advanced = '
 '.get_lang('AdvancedParameters').'
'; $form -> addElement('advanced_settings',$advanced); $form -> addElement('html',''); // Submit button. $form->addElement('style_submit_button', null, $course_validation_feature ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'), 'class="add"'); // The progress bar of this form. $form->add_progress_bar(); // Set default values. if (isset($_user['language']) && $_user['language'] != '') { $values['course_language'] = $_user['language']; } else { $values['course_language'] = api_get_setting('platformLanguage'); } $values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']); $form->setDefaults($values); // Validate the form. if ($form->validate()) { $course_values = $form->exportValues(); $wanted_code = $course_values['wanted_code']; $tutor_name = $course_values['tutor_name']; $category_code = $course_values['category_code']; $title = $course_values['title']; $course_language = $course_values['course_language']; $exemplary_content = !empty($course_values['exemplary_content']); if ($course_validation_feature) { $description = $course_values['description']; $objetives = $course_values['objetives']; $target_audience = $course_values['target_audience']; $status = '0'; } if ($wanted_code == '') { $wanted_code = generate_course_code(api_substr($title, 0, $maxlength)); } // Check whether the requested course code has already been occupied. if (!$course_validation_feature) { $course_code_ok = !CourseManager::course_code_exists($wanted_code); } else { $course_code_ok = !CourseRequestManager::course_code_exists($wanted_code); } if ($course_code_ok) { if (!$course_validation_feature) { $params = array(); $params['title'] = $title; $params['exemplary_content'] = $exemplary_content; $params['wanted_code'] = $wanted_code; //$params['tutor_name'] = $tutor_name; $params['category_code'] = $category_code; $params['course_language'] = $course_language; $course_info = CourseManager::create_course($params); if (!empty($course_info)) { $directory = $course_info['directory']; $title = $course_info['title']; // Preparing a confirmation message. $link = api_get_path(WEB_COURSE_PATH).$directory.'/'; $tpl->assign('course_url', $link); $tpl->assign('course_title', Display::url($title, $link)); $tpl->assign('course_id', $course_info['code']); $add_course_tpl = $tpl->get_template('create_course/add_course.tpl'); $message = $tpl->fetch($add_course_tpl); } else { $message = Display :: return_message(get_lang('CourseCreationFailed'), 'error', false); // Display the form. $content = $form->return_form(); } } else { // Create a request for a new course. $request_id = CourseRequestManager::create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, api_get_user_id(), $exemplary_content); if ($request_id) { $course_request_info = CourseRequestManager::get_course_request_info($request_id); $message = (is_array($course_request_info) ? ''.$course_request_info['code'].' : ' : '').get_lang('CourseRequestCreated'); $message = Display :: return_message($message, 'confirmation', false); $message .= '
' . ''.get_lang('Enter').'' . '
'; } else { $message = Display :: return_message(get_lang('CourseRequestCreationFailed'), 'error', false); // Display the form. $content = $form->return_form(); } } } else { $message = Display :: return_message(get_lang('CourseCodeAlreadyExists'), 'error', false); // Display the form. $content = $form->return_form(); } } else { if (!$course_validation_feature) { $message = Display :: return_message(get_lang('Explanation')); } // Display the form. $content = $form->return_form(); } $tpl->assign('actions', $actions); $tpl->assign('message', $message); $tpl->assign('content', $content); $template = $tpl->get_template('layout/layout_1_col.tpl'); $tpl->display($template);