<commit_before><?php  //$Id$

require_once($CFG->libdir.'/formslib.php');

class course_edit_form extends moodleform {

    function definition() {
        global $USER, $CFG;

        $mform    =& $this->_form;

        $course   = $this->_customdata['course'];
        $category = $this->_customdata['category'];

        $systemcontext = get_context_instance(CONTEXT_SYSTEM);
        $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);

        $disable_meta = false; // basic meta course state protection; server-side security checks not needed

        if (!empty($course)) {
            $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
            $context = $coursecontext;

            if (course_in_meta($course)) {
                $disable_meta = get_string('metaalreadyinmeta');

            } else if ($course->metacourse) {
                if (count_records('course_meta', 'parent_course', $course->id) > 0) {
                    $disable_meta = get_string('metaalreadyhascourses');
                }

            } else {
                // if users already enrolled directly into coures, do not allow switching to meta,
                // users with metacourse manage permission are exception
                // please note that we do not need exact results - anything unexpected here prevents metacourse
                $managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id');
                $enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext);
                if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) {
                    foreach($users as $user) {
                        if (!isset($managers[$user->id])) {
                            $disable_meta = get_string('metaalreadyhasenrolments');
                            break;
                        }
                    }
                }
                unset($managers);
                unset($users);
                unset($enrolroles);
            }
        } else {
            $coursecontext = null;
            $context = $categorycontext;
        }

/// form definition with new course defaults
//--------------------------------------------------------------------------------
        $mform->addElement('header','general', get_string('general', 'form'));

        //must have create course capability in both categories in order to move course
        if (has_capability('moodle/course:create', $categorycontext)) {
            $displaylist = array();
            $parentlist = array();
            make_categories_list($displaylist, $parentlist);
            foreach ($displaylist as $key=>$val) {
                if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
                    unset($displaylist[$key]);
                }
            }
            $mform->addElement('select', 'category', get_string('category'), $displaylist);
        } else {
            $mform->addElement('hidden', 'category', null);
        }
        $mform->setHelpButton('category', array('coursecategory', get_string('category')));
        $mform->setDefault('category', $category->id);
        $mform->setType('category', PARAM_INT);

        $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
        $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
        $mform->setDefault('fullname', get_string('defaultcoursefullname'));
        $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
        $mform->setType('fullname', PARAM_MULTILANG);

        $mform->addElement('text','shortname', get_string('shortnamecourse'),'maxlength="100" size="20"');
        $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
        $mform->setDefault('shortname', get_string('defaultcourseshortname'));
        $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
        $mform->setType('shortname', PARAM_MULTILANG);

        $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
        $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
        $mform->setType('idnumber', PARAM_RAW);

        $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
        $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
        $mform->setDefault('summary', get_string('defaultcoursesummary'));
        $mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
        $mform->setType('summary', PARAM_RAW);

        $courseformats = get_list_of_plugins('course/format');
        $formcourseformats = array();
        foreach ($courseformats as $courseformat) {<commit_msg>MDL-13815 - Course summary text is optional and empty by default now<commit_after><?php  //$Id$

require_once($CFG->libdir.'/formslib.php');

class course_edit_form extends moodleform {

    function definition() {
        global $USER, $CFG;

        $mform    =& $this->_form;

        $course   = $this->_customdata['course'];
        $category = $this->_customdata['category'];

        $systemcontext = get_context_instance(CONTEXT_SYSTEM);
        $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);

        $disable_meta = false; // basic meta course state protection; server-side security checks not needed

        if (!empty($course)) {
            $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
            $context = $coursecontext;

            if (course_in_meta($course)) {
                $disable_meta = get_string('metaalreadyinmeta');

            } else if ($course->metacourse) {
                if (count_records('course_meta', 'parent_course', $course->id) > 0) {
                    $disable_meta = get_string('metaalreadyhascourses');
                }

            } else {
                // if users already enrolled directly into coures, do not allow switching to meta,
                // users with metacourse manage permission are exception
                // please note that we do not need exact results - anything unexpected here prevents metacourse
                $managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id');
                $enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext);
                if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) {
                    foreach($users as $user) {
                        if (!isset($managers[$user->id])) {
                            $disable_meta = get_string('metaalreadyhasenrolments');
                            break;
                        }
                    }
                }
                unset($managers);
                unset($users);
                unset($enrolroles);
            }
        } else {
            $coursecontext = null;
            $context = $categorycontext;
        }

/// form definition with new course defaults
//--------------------------------------------------------------------------------
        $mform->addElement('header','general', get_string('general', 'form'));

        //must have create course capability in both categories in order to move course
        if (has_capability('moodle/course:create', $categorycontext)) {
            $displaylist = array();
            $parentlist = array();
            make_categories_list($displaylist, $parentlist);
            foreach ($displaylist as $key=>$val) {
                if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
                    unset($displaylist[$key]);
                }
            }
            $mform->addElement('select', 'category', get_string('category'), $displaylist);
        } else {
            $mform->addElement('hidden', 'category', null);
        }
        $mform->setHelpButton('category', array('coursecategory', get_string('category')));
        $mform->setDefault('category', $category->id);
        $mform->setType('category', PARAM_INT);

        $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
        $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
        $mform->setDefault('fullname', get_string('defaultcoursefullname'));
        $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
        $mform->setType('fullname', PARAM_MULTILANG);

        $mform->addElement('text','shortname', get_string('shortnamecourse'),'maxlength="100" size="20"');
        $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
        $mform->setDefault('shortname', get_string('defaultcourseshortname'));
        $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
        $mform->setType('shortname', PARAM_MULTILANG);

        $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
        $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
        $mform->setType('idnumber', PARAM_RAW);

        $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
        $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
        $mform->setType('summary', PARAM_RAW);

        $courseformats = get_list_of_plugins('course/format');
        $formcourseformats = array();
        foreach ($courseformats as $courseformat) {
{'fraction_non_alphanumeric': 0.16178535606820463, 'fraction_numerical': 0.004513540621865597, 'mean_word_length': 2.60093896713615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '617088', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2690, 'n_words': 493}