Example #1
0
 /**
  * Returns an array of course categories
  * @return array of course categories
  */
 function get_course_categories()
 {
     $displaylist = array();
     $parentlist = array();
     make_categories_list($displaylist, $parentlist);
     return array(0 => get_string('anycategory', 'filters')) + $displaylist;
 }
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $category = $this->_customdata;
     // get list of categories to use as parents, with site as the first one
     $options = array(get_string('top'));
     $parents = array();
     if ($category->id) {
         // Editing an existing category.
         make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
         $strsubmit = get_string('savechanges');
     } else {
         // Making a new category
         make_categories_list($options, $parents, 'moodle/category:manage');
         $strsubmit = get_string('createcategory');
     }
     $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
     $mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30'));
     $mform->addRule('name', get_string('required'), 'required', null);
     $mform->addElement('htmleditor', 'description', get_string('description'));
     $mform->setType('description', PARAM_RAW);
     if (!empty($CFG->allowcategorythemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $mform->setHelpButton('description', array('writing', 'richtext2'), false, 'editorhelpbutton');
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->setDefault('id', $category->id);
     $this->add_action_buttons(true, $strsubmit);
 }
Example #3
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     // get list of categories to use as parents, with site as the first one
     $options = array(get_string('top'));
     $parents = array();
     make_categories_list($options, $parents);
     $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
     $mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30'));
     $mform->addRule('name', get_string('required'), 'required', null);
     $mform->addElement('htmleditor', 'description', get_string('description'));
     $mform->setType('description', PARAM_RAW);
     if (!empty($CFG->allowcategorythemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton');
     $mform->addElement('hidden', 'id', null);
     $mform->addElement('hidden', 'categoryadd', 0);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('savechanges'));
 }
Example #4
0
 /**
  * Returns an array of course categories
  * @return array of course categories
  */
 function get_course_categories() {
     global $CFG;
     require_once($CFG->dirroot.'/course/lib.php');
     $displaylist = array();
     $parentlist = array();
     make_categories_list($displaylist, $parentlist);
     return array(0=> get_string('anycategory', 'filters')) + $displaylist;
 }
 public function definition()
 {
     $mform =& $this->_form;
     // General settings -------------------------------------------------------------
     /// Adding the "general" fieldset, where all the common settings are showed
     $mform->addElement('header', 'general', get_string('general', 'form'));
     /// Adding the standard "name" field
     $mform->addElement('text', 'name', get_string('subcoursename', 'subcourse'), array('size' => '64'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     /// Adding the optional "intro" and "introformat" pair of fields
     $this->add_intro_editor(true, get_string('subcourseintro', 'subcourse'));
     // Subcourse information --------------------------------------------------------
     $mform->addElement('header', 'subcoursefieldset', get_string('refcourse', 'subcourse'));
     /// Referenced course selector
     $mycourses = subcourse_available_courses();
     $catlist = array();
     $catparents = array();
     make_categories_list($catlist, $catparents);
     $options = array();
     foreach ($mycourses as $mycourse) {
         if (empty($options[$catlist[$mycourse->category]])) {
             $options[$catlist[$mycourse->category]] = array();
         }
         $courselabel = $mycourse->fullname . ' (' . $mycourse->shortname . ')';
         $options[$catlist[$mycourse->category]][$mycourse->id] = $courselabel;
         if (empty($mycourse->visible)) {
             $hiddenlabel = ' ' . get_string('hiddencourse', 'subcourse');
             $options[$catlist[$mycourse->category]][$mycourse->id] .= $hiddenlabel;
         }
     }
     unset($mycourse);
     /**
      * @var $refcourseelement HTML_QuickForm_input
      */
     $refcourseelement = $mform->addElement('selectgroups', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
     $mform->addHelpButton('refcourse', 'refcourse', 'subcourse');
     // Option to add a meta course enrolment to the other course.
     /**
      * @var $addmetaelement HTML_QuickForm_input
      */
     $addmetaelement = $mform->addElement('checkbox', 'addmeta', get_string('addmeta', 'subcourse'));
     // If there is a meta enrolment already, we don't want to allow people to delete it as we
     // may cause problems. Force them to delete the whole subcourse if they want to do this
     if (!empty($this->current->id)) {
         $metaexists = subcourse_meta_exists($this->current->course, $this->current->refcourse);
         if ($metaexists) {
             $mform->setDefault('addmeta', 'checked');
             $refcourseelement->updateAttributes(array('disabled' => true));
             $addmetaelement->updateAttributes(array('disabled' => true));
         }
     }
     // add standard elements, common to all modules
     $this->standard_coursemodule_elements();
     // add standard buttons, common to all modules
     $this->add_action_buttons();
 }
Example #6
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $category = $this->_customdata;
     $this->_category = $category;
     $mform->addElement('header', 'general', get_string('categorycurrentcontents', '', format_string($category->name)));
     $displaylist = array();
     $parentlist = array();
     $children = array();
     make_categories_list($displaylist, $parentlist);
     unset($displaylist[$category->id]);
     foreach ($displaylist as $catid => $unused) {
         // remove all children of $category
         if (isset($parentlist[$catid]) and in_array($category->id, $parentlist[$catid])) {
             $children[] = $catid;
             unset($displaylist[$catid]);
             continue;
         }
         if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $catid))) {
             unset($displaylist[$catid]);
         }
     }
     $candeletecontent = true;
     foreach ($children as $catid) {
         $context = get_context_instance(CONTEXT_COURSECAT, $catid);
         if (!has_capability('moodle/category:delete', $context)) {
             $candeletecontent = false;
             break;
         }
     }
     $options = array();
     if ($displaylist) {
         $options[0] = get_string('move');
     }
     if ($candeletecontent) {
         $options[1] = get_string('delete');
     }
     if (empty($options)) {
         print_error('nocategorydelete', 'error', 'index.php', format_string($category->name));
     }
     $mform->addElement('select', 'fulldelete', get_string('categorycontents'), $options);
     $mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
     $mform->setDefault('newparent', 0);
     if ($displaylist) {
         $mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
         if (in_array($category->parent, $displaylist)) {
             $mform->setDefault('newparent', $category->parent);
         }
     }
     $mform->addElement('hidden', 'delete');
     $mform->addElement('hidden', 'sure');
     $mform->setDefault('sure', md5(serialize($category)));
     //--------------------------------------------------------------------------------
     $this->add_action_buttons(true, get_string('delete'));
 }
 function definition()
 {
     global $USER, $CFG;
     $mform =& $this->_form;
     $mform->addElement('header', '', get_string('coursefield', 'block_configurable_reports'), '');
     $options = array(get_string('top'));
     $parents = array();
     make_categories_list($options, $parents);
     $mform->addElement('select', 'categoryid', get_string('category'), $options);
     // buttons
     $this->add_action_buttons(true, get_string('add'));
 }
 function definition()
 {
     global $DB, $USER, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     $mform =& $this->_form;
     $mform->addElement('header', '', get_string('coursefield', 'report_configreports'), '');
     $options = array(get_string('top'));
     $parents = array();
     make_categories_list($options, $parents);
     $mform->addElement('select', 'categoryid', get_string('category'), $options);
     $mform->addElement('checkbox', 'includesubcats', get_string('includesubcats', 'report_configreports'));
     // buttons
     $this->add_action_buttons(true, get_string('add'));
 }
 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $category = $this->_customdata['category'];
     $editoroptions = $this->_customdata['editoroptions'];
     // get list of categories to use as parents, with site as the first one
     $options = array();
     if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
         $options[0] = get_string('top');
     }
     $parents = array();
     if ($category->id) {
         // Editing an existing category.
         make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
         if (empty($options[$category->parent])) {
             $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id' => $category->parent));
         }
         $strsubmit = get_string('savechanges');
     } else {
         // Making a new category
         make_categories_list($options, $parents, 'moodle/category:manage');
         $strsubmit = get_string('createcategory');
     }
     $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
     $mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30'));
     $mform->addRule('name', get_string('required'), 'required', null);
     $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'), 'maxlength="100"  size="10"');
     $mform->addHelpButton('idnumber', 'idnumbercoursecategory');
     $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
     $mform->setType('description_editor', PARAM_RAW);
     if (!empty($CFG->allowcategorythemes)) {
         $themes = array('' => get_string('forceno'));
         $allthemes = get_list_of_themes();
         foreach ($allthemes as $key => $theme) {
             if (empty($theme->hidefromselector)) {
                 $themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
             }
         }
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $mform->addElement('static', 'label1', 'No of subject', '<div id="noofsubject"></div>');
     $mform->addElement('static', 'label1', 'Course Selection', '<div id="basic-modal"><a href="#" class="basic">View All</a></div>');
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->setDefault('id', $category->id);
     $this->add_action_buttons(true, $strsubmit);
 }
Example #10
0
    function definition() {
        global $CFG, $DB;
        $mform =& $this->_form;
        $category = $this->_customdata['category'];
        $editoroptions = $this->_customdata['editoroptions'];

        // get list of categories to use as parents, with site as the first one
        $options = array();
        if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
            $options[0] = get_string('top');
        }
        $parents = array();
        if ($category->id) {
            // Editing an existing category.
            make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
            if (empty($options[$category->parent])) {
                $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
            }
            $strsubmit = get_string('savechanges');
        } else {
            // Making a new category
            make_categories_list($options, $parents, 'moodle/category:manage');
            $strsubmit = get_string('createcategory');
        }

        $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
        $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
        $mform->addRule('name', get_string('required'), 'required', null);
        $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
        $mform->setType('description_editor', PARAM_RAW);
        if (!empty($CFG->allowcategorythemes)) {
            $themes = array(''=>get_string('forceno'));
            $allthemes = get_list_of_themes();
            foreach ($allthemes as $key=>$theme) {
                $themes[$key] = $theme->name;
            }
            $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
        }

        $mform->addElement('hidden', 'id', 0);
        $mform->setType('id', PARAM_INT);
        $mform->setDefault('id', $category->id);

        $this->add_action_buttons(true, $strsubmit);
    }
 function execute($data, $user, $courseid)
 {
     if (isset($data->includesubcats)) {
         if ($category = get_record('course_categories', 'id', $data->categoryid)) {
             make_categories_list($options, $parents, '', 0, $category);
         } else {
             make_categories_list($options, $parents);
         }
         unset($options[$data->categoryid]);
         return array_keys($options);
     } else {
         $categories = get_records('course_categories', 'parent', $data->categoryid);
         if ($categories) {
             return array_keys($categories);
         }
     }
     return array();
 }
 function execute($data, $user, $courseid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     if (isset($data->includesubcats)) {
         if ($category = $DB->get_record('course_categories', array('id' => $data->categoryid))) {
             make_categories_list($options, $parents, '', 0, $category);
         } else {
             make_categories_list($options, $parents);
         }
         unset($options[$data->categoryid]);
         return array_keys($options);
     } else {
         $categories = $DB->get_records('course_categories', array('parent' => $data->categoryid));
         if ($categories) {
             return array_keys($categories);
         }
     }
     return array();
 }
Example #13
0
 protected function get_category_options($currentcontextid)
 {
     $displaylist = array();
     $parentlist = array();
     make_categories_list($displaylist, $parentlist, 'moodle/cohort:manage');
     $options = array();
     $syscontext = context_system::instance();
     if (has_capability('moodle/cohort:manage', $syscontext)) {
         $options[$syscontext->id] = print_context_name($syscontext);
     }
     foreach ($displaylist as $cid => $name) {
         $context = context_coursecat::instance($cid);
         $options[$context->id] = $name;
     }
     // always add current - this is not likely, but if the logic gets changed it might be a problem
     if (!isset($options[$currentcontextid])) {
         $context = get_context_instance_by_id($currentcontextid, MUST_EXIST);
         $options[$context->id] = print_context_name($syscontext);
     }
     return $options;
 }
Example #14
0
 function definition()
 {
     global $CFG, $DB, $USER;
     $mform =& $this->_form;
     if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) {
         $mform->addElement('header', 'pendinglist', get_string('coursespending'));
         $list = array();
         foreach ($pending as $cp) {
             $list[] = format_string($cp->fullname);
         }
         $list = implode(', ', $list);
         $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
     }
     $mform->addElement('header', 'coursedetails', get_string('courserequestdetails'));
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->addHelpButton('fullname', 'fullnamecourse');
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_TEXT);
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->addHelpButton('shortname', 'shortnamecourse');
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_TEXT);
     if (!empty($CFG->requestcategoryselection)) {
         $displaylist = array();
         $parentlist = array();
         make_categories_list($displaylist, $parentlist, '');
         $mform->addElement('select', 'category', get_string('category'), $displaylist);
         $mform->setDefault('category', $CFG->defaultrequestcategory);
         $mform->addHelpButton('category', 'category');
     }
     $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
     $mform->addHelpButton('summary_editor', 'coursesummary');
     $mform->setType('summary_editor', PARAM_RAW);
     $mform->addElement('header', 'requestreason', get_string('courserequestreason'));
     $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows' => '15', 'cols' => '50'));
     $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
     $mform->setType('reason', PARAM_TEXT);
     $this->add_action_buttons(true, get_string('requestcourse'));
 }
Example #15
0
 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $category = $this->_customdata;
     $categorycontext = context_coursecat::instance($category->id);
     $this->_category = $category;
     /// Check permissions, to see if it OK to give the option to delete
     /// the contents, rather than move elsewhere.
     /// Are there any subcategories of this one, can they be deleted?
     $candeletecontent = true;
     $tocheck = get_child_categories($category->id);
     $containscategories = !empty($tocheck);
     $categoryids = array($category->id);
     while (!empty($tocheck)) {
         $checkcat = array_pop($tocheck);
         $childcategoryids[] = $checkcat->id;
         $tocheck = $tocheck + get_child_categories($checkcat->id);
         $chcontext = context_coursecat::instance($checkcat->id);
         if ($candeletecontent && !has_capability('moodle/category:manage', $chcontext)) {
             $candeletecontent = false;
         }
     }
     /// Are there any courses in here, can they be deleted?
     list($test, $params) = $DB->get_in_or_equal($categoryids);
     $containedcourses = $DB->get_records_sql("SELECT id,1 FROM {course} c WHERE c.category {$test}", $params);
     $containscourses = false;
     if ($containedcourses) {
         $containscourses = true;
         foreach ($containedcourses as $courseid => $notused) {
             if ($candeletecontent && !can_delete_course($courseid)) {
                 $candeletecontent = false;
                 break;
             }
         }
     }
     /// Are there any questions in the question bank here?
     $containsquestions = question_context_has_any_questions($categorycontext);
     /// Get the list of categories we might be able to move to.
     $testcaps = array();
     if ($containscourses) {
         $testcaps[] = 'moodle/course:create';
     }
     if ($containscategories || $containsquestions) {
         $testcaps[] = 'moodle/category:manage';
     }
     $displaylist = array();
     $notused = array();
     if (!empty($testcaps)) {
         make_categories_list($displaylist, $notused, $testcaps, $category->id);
     }
     /// Now build the options.
     $options = array();
     if ($displaylist) {
         $options[0] = get_string('movecontentstoanothercategory');
     }
     if ($candeletecontent) {
         $options[1] = get_string('deleteallcannotundo');
     }
     /// Now build the form.
     $mform->addElement('header', 'general', get_string('categorycurrentcontents', '', format_string($category->name, true, array('context' => $categorycontext))));
     if ($containscourses || $containscategories || $containsquestions) {
         if (empty($options)) {
             print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name, true, array('context' => $categorycontext)));
         }
         /// Describe the contents of this category.
         $contents = '<ul>';
         if ($containscategories) {
             $contents .= '<li>' . get_string('subcategories') . '</li>';
         }
         if ($containscourses) {
             $contents .= '<li>' . get_string('courses') . '</li>';
         }
         if ($containsquestions) {
             $contents .= '<li>' . get_string('questionsinthequestionbank') . '</li>';
         }
         $contents .= '</ul>';
         $mform->addElement('static', 'emptymessage', get_string('thiscategorycontains'), $contents);
         /// Give the options for what to do.
         $mform->addElement('select', 'fulldelete', get_string('whattodo'), $options);
         if (count($options) == 1) {
             $optionkeys = array_keys($options);
             $option = reset($optionkeys);
             $mform->hardFreeze('fulldelete');
             $mform->setConstant('fulldelete', $option);
         }
         if ($displaylist) {
             $mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
             if (in_array($category->parent, $displaylist)) {
                 $mform->setDefault('newparent', $category->parent);
             }
             $mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
         }
     } else {
         $mform->addElement('hidden', 'fulldelete', 1);
         $mform->setType('fulldelete', PARAM_INT);
         $mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
     }
     $mform->addElement('hidden', 'delete');
     $mform->setType('delete', PARAM_ALPHANUM);
     $mform->addElement('hidden', 'sure');
     $mform->setType('sure', PARAM_ALPHANUM);
     $mform->setDefault('sure', md5(serialize($category)));
     //--------------------------------------------------------------------------------
     $this->add_action_buttons(true, get_string('delete'));
 }
function print_whole_category_list2($category = NULL, $displaylist = NULL, $parentslist = NULL, $depth = -1, $showcourses = true)
{
    global $CFG;
    // maxcategorydepth == 0 meant no limit
    if (!empty($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth) {
        return;
    }
    if (!$displaylist) {
        make_categories_list($displaylist, $parentslist);
    }
    if ($category) {
        if ($category->visible or has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_SYSTEM))) {
            print_category_info2($category, $depth, $showcourses);
        } else {
            return;
            // Don't bother printing children of invisible categories
        }
    } else {
        $category->id = "0";
    }
    if ($categories = get_child_categories($category->id)) {
        // Print all the children recursively
        $countcats = count($categories);
        $count = 0;
        $first = true;
        $last = false;
        foreach ($categories as $cat) {
            $count++;
            if ($count == $countcats) {
                $last = true;
            }
            $up = $first ? false : true;
            $down = $last ? false : true;
            $first = false;
            print_whole_category_list2($cat, $displaylist, $parentslist, $depth + 1, $showcourses);
        }
    }
}
Example #17
0
    function definition() {
        global $USER, $CFG, $DB;

        $mform    = $this->_form;

        $course        = $this->_customdata['course']; // this contains the data of this form
        $category      = $this->_customdata['category'];
        $editoroptions = $this->_customdata['editoroptions'];
        $returnto = $this->_customdata['returnto'];

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

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

        $courseconfig = get_config('moodlecourse');

        $this->course  = $course;
        $this->context = $context;

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

        $mform->addElement('hidden', 'returnto', null);
        $mform->setType('returnto', PARAM_ALPHANUM);
        $mform->setConstant('returnto', $returnto);

        // verify permissions to change course category or keep current
        if (empty($course->id)) {
            if (has_capability('moodle/course:create', $categorycontext)) {
                $displaylist = array();
                $parentlist = array();
                make_categories_list($displaylist, $parentlist, 'moodle/course:create');
                $mform->addElement('select', 'category', get_string('category'), $displaylist);
                $mform->addHelpButton('category', 'category');
                $mform->setDefault('category', $category->id);
            } else {
                $mform->addElement('hidden', 'category', null);
                $mform->setType('category', PARAM_INT);
                $mform->setConstant('category', $category->id);
            }
        } else {
            if (has_capability('moodle/course:changecategory', $coursecontext)) {
                $displaylist = array();
                $parentlist = array();
                make_categories_list($displaylist, $parentlist, 'moodle/course:create');
                if (!isset($displaylist[$course->category])) {
                    //always keep current
                    $displaylist[$course->category] = format_string($DB->get_field('course_categories', 'name', array('id'=>$course->category)));
                }
                $mform->addElement('select', 'category', get_string('category'), $displaylist);
                $mform->addHelpButton('category', 'category');
            } else {
                //keep current
                $mform->addElement('hidden', 'category', null);
                $mform->setType('category', PARAM_INT);
                $mform->setConstant('category', $course->category);
            }
        }

        $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
        $mform->addHelpButton('fullname', 'fullnamecourse');
        $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
        $mform->setType('fullname', PARAM_MULTILANG);
        if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
            $mform->hardFreeze('fullname');
            $mform->setConstant('fullname', $course->fullname);
        }

        $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
        $mform->addHelpButton('shortname', 'shortnamecourse');
        $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
        $mform->setType('shortname', PARAM_MULTILANG);
        if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
            $mform->hardFreeze('shortname');
            $mform->setConstant('shortname', $course->shortname);
        }

        $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
        $mform->addHelpButton('idnumber', 'idnumbercourse');
        $mform->setType('idnumber', PARAM_RAW);
        if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
            $mform->hardFreeze('idnumber');
            $mform->setConstants('idnumber', $course->idnumber);
        }


        $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions);
        $mform->addHelpButton('summary_editor', 'coursesummary');
        $mform->setType('summary_editor', PARAM_RAW);

        if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
            $mform->hardFreeze('summary_editor');
        }

        $courseformats = get_plugin_list('format');
        $formcourseformats = array();
        foreach ($courseformats as $courseformat => $formatdir) {
            $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat");
        }
        $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
        $mform->addHelpButton('format', 'format');
        $mform->setDefault('format', $courseconfig->format);

        for ($i=1; $i<=52; $i++) {
          $sectionmenu[$i] = "$i";
        }
        $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
        $mform->setDefault('numsections', $courseconfig->numsections);

        $mform->addElement('date_selector', 'startdate', get_string('startdate'));
        $mform->addHelpButton('startdate', 'startdate');
        $mform->setDefault('startdate', time() + 3600 * 24);

        $choices = array();
        $choices['0'] = get_string('hiddensectionscollapsed');
        $choices['1'] = get_string('hiddensectionsinvisible');
        $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
        $mform->addHelpButton('hiddensections', 'hiddensections');
        $mform->setDefault('hiddensections', $courseconfig->hiddensections);

        $options = range(0, 10);
        $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
        $mform->addHelpButton('newsitems', 'newsitemsnumber');
        $mform->setDefault('newsitems', $courseconfig->newsitems);

        $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
        $mform->addHelpButton('showgrades', 'showgrades');
        $mform->setDefault('showgrades', $courseconfig->showgrades);

        $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
        $mform->addHelpButton('showreports', 'showreports');
        $mform->setDefault('showreports', $courseconfig->showreports);

        $choices = get_max_upload_sizes($CFG->maxbytes);
        $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
        $mform->addHelpButton('maxbytes', 'maximumupload');
        $mform->setDefault('maxbytes', $courseconfig->maxbytes);

        if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
            if (empty($course->legacyfiles)) {
                //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
                $choices = array('0'=>get_string('no'), '2'=>get_string('yes'));
            } else {
                $choices = array('1'=>get_string('no'), '2'=>get_string('yes'));
            }
            $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
            $mform->addHelpButton('legacyfiles', 'courselegacyfiles');
            if (!isset($courseconfig->legacyfiles)) {
                // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses
                $courseconfig->legacyfiles = 0;
            }
            $mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
        }

        if (!empty($CFG->allowcoursethemes)) {
            $themeobjects = get_list_of_themes();
            $themes=array();
            $themes[''] = get_string('forceno');
            foreach ($themeobjects as $key=>$theme) {
                $themes[$key] = $theme->name;
            }
            $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
        }

//--------------------------------------------------------------------------------
        enrol_course_edit_form($mform, $course, $context);

//--------------------------------------------------------------------------------
        $mform->addElement('header','', get_string('groups', 'group'));

        $choices = array();
        $choices[NOGROUPS] = get_string('groupsnone', 'group');
        $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
        $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
        $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
        $mform->addHelpButton('groupmode', 'groupmode', 'group');
        $mform->setDefault('groupmode', $courseconfig->groupmode);

        $choices = array();
        $choices['0'] = get_string('no');
        $choices['1'] = get_string('yes');
        $mform->addElement('select', 'groupmodeforce', get_string('groupmodeforce', 'group'), $choices);
        $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
        $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);

        //default groupings selector
        $options = array();
        $options[0] = get_string('none');
        $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);

//--------------------------------------------------------------------------------
        $mform->addElement('header','', get_string('availability'));

        $choices = array();
        $choices['0'] = get_string('courseavailablenot');
        $choices['1'] = get_string('courseavailable');
        $mform->addElement('select', 'visible', get_string('availability'), $choices);
        $mform->addHelpButton('visible', 'availability');
        $mform->setDefault('visible', $courseconfig->visible);
        if (!has_capability('moodle/course:visibility', $context)) {
            $mform->hardFreeze('visible');
            if (!empty($course->id)) {
                $mform->setConstant('visible', $course->visible);
            } else {
                $mform->setConstant('visible', $category->visible);
            }
        }

//--------------------------------------------------------------------------------
        $mform->addElement('header','', get_string('language'));

        $languages=array();
        $languages[''] = get_string('forceno');
        $languages += get_string_manager()->get_list_of_translations();
        $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
        $mform->setDefault('lang', $courseconfig->lang);

//--------------------------------------------------------------------------------
        if (completion_info::is_enabled_for_site()) {
            $mform->addElement('header','', get_string('progress','completion'));
            $mform->addElement('select', 'enablecompletion', get_string('completion','completion'),
                array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion')));
            $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);

            $mform->addElement('checkbox', 'completionstartonenrol', get_string('completionstartonenrol', 'completion'));
            $mform->setDefault('completionstartonenrol', $courseconfig->completionstartonenrol);
            $mform->disabledIf('completionstartonenrol', 'enablecompletion', 'eq', 0);
        } else {
            $mform->addElement('hidden', 'enablecompletion');
            $mform->setType('enablecompletion', PARAM_INT);
            $mform->setDefault('enablecompletion',0);

            $mform->addElement('hidden', 'completionstartonenrol');
            $mform->setType('completionstartonenrol', PARAM_INT);
            $mform->setDefault('completionstartonenrol',0);
        }

//--------------------------------------------------------------------------------
        if (has_capability('moodle/site:config', $systemcontext)) {
            if (((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
                $mform->addElement('header', '', get_string('restrictmodules'));

                $options = array();
                $options['0'] = get_string('no');
                $options['1'] = get_string('yes');
                $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
                if (!empty($CFG->restrictbydefault)) {
                    $mform->setDefault('restrictmodules', 1);
                }

                $mods = array(0=>get_string('allownone'));
                $mods += $DB->get_records_menu('modules', array('visible'=>1), 'name', 'id, name');
                $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple'=>'multiple', 'size'=>'10'));
                $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
                // defaults are already in $course
            } else {
                // remove any mod restriction
                $mform->addElement('hidden', 'restrictmodules', 0);
                $mform->setType('restrictmodules', PARAM_INT);
            }
        } else {
            $mform->addElement('hidden', 'restrictmodules');
            $mform->setType('restrictmodules', PARAM_INT);
            if (empty($course->id)) {
                $mform->setConstant('restrictmodules', (int)($CFG->restrictmodulesfor == 'all'));
            } else {
                // keep previous
                $mform->setConstant('restrictmodules', $course->restrictmodules);
            }
        }

/// customizable role names in this course
//--------------------------------------------------------------------------------
        $mform->addElement('header','rolerenaming', get_string('rolerenaming'));
        $mform->addHelpButton('rolerenaming', 'rolerenaming');

        if ($roles = get_all_roles()) {
            if ($coursecontext) {
                $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW);
            }
            $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
            foreach ($roles as $role) {
                $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->name));
                if (isset($role->localname)) {
                    $mform->setDefault('role_'.$role->id, $role->localname);
                }
                $mform->setType('role_'.$role->id, PARAM_TEXT);
                if (!in_array($role->id, $assignableroles)) {
                    $mform->setAdvanced('role_'.$role->id);
                }
            }
        }

//--------------------------------------------------------------------------------
        $this->add_action_buttons();
//--------------------------------------------------------------------------------
        $mform->addElement('hidden', 'id', null);
        $mform->setType('id', PARAM_INT);

/// finally set the current form data
//--------------------------------------------------------------------------------
        $this->set_data($course);
    }
Example #18
0
 function definition()
 {
     global $USER, $CFG, $DB, $js_enabled;
     $courseconfig = get_config('moodlecourse');
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $completion = new completion_info($course);
     $params = array('course' => $course->id);
     /// form definition
     //--------------------------------------------------------------------------------
     // Check if there is existing criteria completions
     if ($completion->is_course_locked()) {
         $mform->addElement('header', '', get_string('completionsettingslocked', 'completion'));
         $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion'));
         $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion'));
     }
     // Get array of all available aggregation methods
     $aggregation_methods = $completion->get_aggregation_methods();
     // Overall criteria aggregation
     $mform->addElement('header', 'overallcriteria', get_string('overallcriteriaaggregation', 'completion'));
     $mform->addElement('select', 'overall_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
     $mform->setDefault('overall_aggregation', $completion->get_aggregation_method());
     // Course prerequisite completion criteria
     $mform->addElement('header', 'courseprerequisites', get_string('courseprerequisites', 'completion'));
     // Get applicable courses
     $courses = $DB->get_records_sql("\n                SELECT DISTINCT\n                    c.id,\n                    c.category,\n                    c.fullname,\n                    cc.id AS selected\n                FROM\n                    {course} c\n                LEFT JOIN\n                    {course_completion_criteria} cc\n                 ON cc.courseinstance = c.id\n                AND cc.course = {$course->id}\n                INNER JOIN\n                    {course_completion_criteria} ccc\n                 ON ccc.course = c.id\n                WHERE\n                    c.enablecompletion = " . COMPLETION_ENABLED . "\n                AND c.id <> {$course->id}\n            ");
     if (!empty($courses)) {
         if (count($courses) > 1) {
             $mform->addElement('select', 'course_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
             $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE));
         }
         // Get category list
         $list = array();
         $parents = array();
         make_categories_list($list, $parents);
         // Get course list for select box
         $selectbox = array();
         $selected = array();
         foreach ($courses as $c) {
             $selectbox[$c->id] = $list[$c->category] . ' / ' . s($c->fullname);
             // If already selected
             if ($c->selected) {
                 $selected[] = $c->id;
             }
         }
         // Show multiselect box
         $mform->addElement('select', 'criteria_course', get_string('coursesavailable', 'completion'), $selectbox, array('multiple' => 'multiple', 'size' => 6));
         // Select current criteria
         $mform->setDefault('criteria_course', $selected);
         // Explain list
         $mform->addElement('static', 'criteria_courses_explaination', '', get_string('coursesavailableexplaination', 'completion'));
     } else {
         $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion'));
     }
     // Manual self completion
     $mform->addElement('header', 'manualselfcompletion', get_string('manualselfcompletion', 'completion'));
     $criteria = new completion_criteria_self($params);
     $criteria->config_form_display($mform);
     // Role completion criteria
     $mform->addElement('header', 'roles', get_string('manualcompletionby', 'completion'));
     $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, get_context_instance(CONTEXT_COURSE, $course->id));
     if (!empty($roles)) {
         $mform->addElement('select', 'role_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
         $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE));
         foreach ($roles as $role) {
             $params_a = array('role' => $role->id);
             $criteria = new completion_criteria_role(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $role);
         }
     } else {
         $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion'));
     }
     // Activity completion criteria
     $mform->addElement('header', 'activitiescompleted', get_string('activitiescompleted', 'completion'));
     $activities = $completion->get_activities();
     if (!empty($activities)) {
         if (count($activities) > 1) {
             $mform->addElement('select', 'activity_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
             $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY));
         }
         foreach ($activities as $activity) {
             $params_a = array('moduleinstance' => $activity->id);
             $criteria = new completion_criteria_activity(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $activity);
         }
     } else {
         $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion'));
     }
     // Completion on date
     $mform->addElement('header', 'date', get_string('date'));
     $criteria = new completion_criteria_date($params);
     $criteria->config_form_display($mform);
     // Completion after enrolment duration
     $mform->addElement('header', 'duration', get_string('durationafterenrolment', 'completion'));
     $criteria = new completion_criteria_duration($params);
     $criteria->config_form_display($mform);
     // Completion on course grade
     $mform->addElement('header', 'grade', get_string('grade'));
     // Grade enable and passing grade
     $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
     $criteria = new completion_criteria_grade($params);
     $criteria->config_form_display($mform, $course_grade);
     // Completion on unenrolment
     $mform->addElement('header', 'unenrolment', get_string('unenrolment', 'completion'));
     $criteria = new completion_criteria_unenrol($params);
     $criteria->config_form_display($mform);
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', $course->id);
     $mform->setType('id', PARAM_INT);
     // If the criteria are locked, freeze values and submit button
     if ($completion->is_course_locked()) {
         $except = array('settingsunlock');
         $mform->hardFreezeAllVisibleExcept($except);
         $mform->addElement('cancel');
     }
 }
Example #19
0
/**
 * Show form to create a new moodle course from the existing Turnitin Course
 *
 * @global type $CFG
 * @global type $OUTPUT
 * @return html the form object to create a new course
 */
function turnitintooltwo_show_browser_new_course_form()
{
    global $OUTPUT, $CFG;
    $elements = array();
    $elements[] = array('header', 'create_course_fieldset', get_string('createcourse', 'turnitintooltwo'));
    $displaylist = array();
    $parentlist = array();
    require_once $CFG->dirroot . "/course/lib.php";
    if (file_exists($CFG->libdir . '/coursecatlib.php')) {
        require_once $CFG->libdir . '/coursecatlib.php';
        $displaylist = coursecat::make_categories_list('');
    } else {
        make_categories_list($displaylist, $parentlist, '');
    }
    $elements[] = array('select', 'coursecategory', get_string('category'), '', $displaylist);
    $elements[] = array('text', 'coursename', get_string('coursetitle', 'turnitintooltwo'), '');
    $elements[] = array('button', 'create_course', get_string('createcourse', 'turnitintooltwo'));
    $customdata["elements"] = $elements;
    $customdata["hide_submit"] = true;
    $customdata["disable_form_change_checker"] = true;
    $createcourseform = new turnitintooltwo_form('', $customdata);
    return $createcourseform->display();
}
Example #20
0
        $settings->add(new admin_setting_configselect('enrol_ldap/opt_deref', get_string('opt_deref_key', 'enrol_ldap'), get_string('opt_deref', 'enrol_ldap'), 0, $options));
        $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/idnumber_attribute', get_string('idnumber_attribute_key', 'enrol_ldap'), get_string('idnumber_attribute', 'enrol_ldap'), '', true, true));
        //--- course mapping settings ---
        $settings->add(new admin_setting_heading('enrol_ldap_course_settings', get_string('course_settings', 'enrol_ldap'), ''));
        $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/objectclass', get_string('objectclass_key', 'enrol_ldap'), get_string('objectclass', 'enrol_ldap'), ''));
        $coursefields = array('idnumber', 'shortname', 'fullname', 'summary');
        foreach ($coursefields as $field) {
            $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/course_' . $field, get_string('course_' . $field . '_key', 'enrol_ldap'), get_string('course_' . $field, 'enrol_ldap'), '', true, true));
        }
        $settings->add(new admin_setting_configcheckbox('enrol_ldap/ignorehiddencourses', get_string('ignorehiddencourses', 'enrol_database'), get_string('ignorehiddencourses_desc', 'enrol_database'), 0));
        $options = array(ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'), ENROL_EXT_REMOVED_KEEP => get_string('extremovedkeep', 'enrol'), ENROL_EXT_REMOVED_SUSPEND => get_string('extremovedsuspend', 'enrol'), ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'));
        $settings->add(new admin_setting_configselect('enrol_ldap/unenrolaction', get_string('extremovedaction', 'enrol'), get_string('extremovedaction_help', 'enrol'), ENROL_EXT_REMOVED_UNENROL, $options));
        //--- course creation settings ---
        $settings->add(new admin_setting_heading('enrol_ldap_autocreation_settings', get_string('autocreation_settings', 'enrol_ldap'), ''));
        $options = $yesno;
        $settings->add(new admin_setting_configselect('enrol_ldap/autocreate', get_string('autocreate_key', 'enrol_ldap'), get_string('autocreate', 'enrol_ldap'), 0, $options));
        if (!during_initial_install()) {
            require_once $CFG->dirroot . '/course/lib.php';
            $parentlist = array();
            $options = array();
            make_categories_list($options, $parentlist);
            $settings->add(new admin_setting_configselect('enrol_ldap/category', get_string('category_key', 'enrol_ldap'), get_string('category', 'enrol_ldap'), key($options), $options));
        }
        $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/template', get_string('template_key', 'enrol_ldap'), get_string('template', 'enrol_ldap'), ''));
        //--- nested groups settings ---
        $settings->add(new admin_setting_heading('enrol_ldap_nested_groups_settings', get_string('nested_groups_settings', 'enrol_ldap'), ''));
        $options = $yesno;
        $settings->add(new admin_setting_configselect('enrol_ldap/nested_groups', get_string('nested_groups_key', 'enrol_ldap'), get_string('nested_groups', 'enrol_ldap'), 0, $options));
        $settings->add(new admin_setting_configtext_trim_lower('enrol_ldap/group_memberofattribute', get_string('group_memberofattribute_key', 'enrol_ldap'), get_string('group_memberofattribute', 'enrol_ldap'), '', true, true));
    }
}
Example #21
0
                    foreach ($icons as $pix_icon) {
                        echo $OUTPUT->render($pix_icon);
                    }
                }
                if (!empty($acourse->summary)) {
                    $link = new moodle_url("/course/info.php?id={$acourse->id}");
                    echo $OUTPUT->action_link($link, '<img alt="' . get_string('info') . '" class="icon" src="' . $OUTPUT->pix_url('i/info') . '" />', new popup_action('click', $link, 'courseinfo'), array('title' => $strsummary));
                }
                echo "</td>";
            }
            echo "</tr>";
        }
        if ($abletomovecourses) {
            $movetocategories = array();
            $notused = array();
            make_categories_list($movetocategories, $notused, 'moodle/category:manage');
            $movetocategories[$category->id] = get_string('moveselectedcoursesto');
            echo '<tr><td colspan="3" align="right">';
            echo html_writer::select($movetocategories, 'moveto', $category->id, null, array('id' => 'movetoid'));
            $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false));
            echo '<input type="hidden" name="id" value="' . $category->id . '" />';
            echo '</td></tr>';
        }
        echo '</table>';
        echo '</div></form>';
        echo '<br />';
    }
}
echo '<div class="buttons">';
if (has_capability('moodle/category:manage', $context) and $numcourses > 1) {
    /// Print button to re-sort courses by name
Example #22
0
    $urlparams['page'] = $page;
}
if ($perpage) {
    $urlparams['perpage'] = $perpage;
}
// Begin output
$PAGE->set_pagelayout('coursecategory');
$site = get_site();
$PAGE->set_title("{$site->shortname}: {$category->name}");
$PAGE->set_heading($site->fullname);
$PAGE->set_button(print_course_search('', true, 'navbar'));
echo $OUTPUT->header();
/// Print the category selector
$displaylist = array();
$notused = array();
make_categories_list($displaylist, $notused);
echo '<div class="categorypicker">';
$select = new single_select(new moodle_url('/course/category.php'), 'id', $displaylist, $category->id, null, 'switchcategory');
$select->set_label(get_string('categories') . ':');
echo $OUTPUT->render($select);
echo '</div>';
/// Print current category description
echo $OUTPUT->box_start();
$options = new stdClass();
$options->noclean = true;
$options->para = false;
$options->overflowdiv = true;
if (!isset($category->descriptionformat)) {
    $category->descriptionformat = FORMAT_MOODLE;
}
$text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'coursecat', 'description', null);
Example #23
0
 /**
  * Build form content
  *
  */
 function buildForm()
 {
     require_login();
     $this->_formBuilt = true;
     global $category, $USER, $CFG;
     $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
     $coursecontext = null;
     $context = $categorycontext;
     //////// create formset around basic setting
     $this->addElement('header', 'basic_heading', get_string('heading.basic', 'samouk'));
     //must have create course capability in categories in order to create 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]);
             }
         }
         $el = $this->addElement('select', 'category', get_string('category'), $displaylist);
         $el->setSelected(array($category->id));
     } else {
         $this->addElement('hidden', 'category', null);
     }
     $this->setHelpButton('category', array('coursecategory', get_string('category')));
     $this->setType('category', PARAM_INT);
     // generate form for a Fullname of the new course
     $this->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
     $this->setDefault('fullname', get_string('defaultcoursefullname'));
     $this->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
     $this->registerRule("fullNameUnicity", "callback", "_checkFullNameUnicity", get_class($this));
     $this->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $this->addRule("fullname", get_string("newcourse.error.usedfullname", "samouk"), "fullNameUnicity");
     $this->setType('fullname', PARAM_MULTILANG);
     // generate form for a Summary of the new course
     $this->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65'));
     $this->setHelpButton('summary', array('text', get_string('helptext')), true);
     $this->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
     $this->setType('summary', PARAM_RAW);
     $this->setDefault('summary', get_string('defaultcoursesummary'));
     // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
     $enrol_object = $CFG;
     if (!empty($course)) {
         $enrol_oject = $course;
     }
     // generate form for a Price of the new course
     if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && $enrol_object->enrol != 'manual') {
         $costgroup = array();
         $currencies = get_list_of_currencies();
         $costgroup[0] =& HTML_QuickForm::createElement('text', 'cost', '', 'maxlength="6" size="6"');
         $costgroup[1] =& HTML_QuickForm::createElement('select', 'currency', '', $currencies);
         $this->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
         $this->setDefault('cost', '');
         //defining a rule for a form element within a group :
         $costgrprules = array();
         //set the message to null to tell Moodle to use a default message
         //available for most rules, fetched from language pack (err_{rulename}).
         $costgrprules['cost'][] = array(null, 'numeric', null, 'client');
         $this->addGroupRule('costgrp', $costgrprules);
         $this->setHelpButton('costgrp', array('cost', get_string('cost')), true);
         $this->setDefault('currency', empty($CFG->enrol_currency) ? 'CZK' : $CFG->enrol_currency);
     }
     $buttons[0] =& HTML_QuickForm::createElement('button', 'cancel', get_string('cancel'), array('onclick' => "javascript:location.href='index.php';"));
     $buttons[1] =& HTML_QuickForm::createElement('submit', $this->getButtonName('next'), get_string('button.next', 'samouk'));
     $this->addGroup($buttons, 'buttons', '', array(' '), true);
     $this->closeHeaderBefore('buttons');
     // print close tag for element Fieldset (heading)
     $this->setDefaultAction('next');
 }
Example #24
0
/**
 * This function will return $options array for html_writer::select(), with whitespace to denote nesting.
 */
function make_categories_options()
{
    make_categories_list($cats, $parents);
    foreach ($cats as $key => $value) {
        if (array_key_exists($key, $parents)) {
            if ($indent = count($parents[$key])) {
                for ($i = 0; $i < $indent; $i++) {
                    $cats[$key] = '&nbsp;' . $cats[$key];
                }
            }
        }
    }
    return $cats;
}
Example #25
0
 function definition()
 {
     global $USER, $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id'))));
     $course = $this->_customdata['course'];
     // this contains the data of this form
     $category = $this->_customdata['category'];
     $editoroptions = $this->_customdata['editoroptions'];
     $returnto = $this->_customdata['returnto'];
     $systemcontext = context_system::instance();
     $categorycontext = context_coursecat::instance($category->id);
     if (!empty($course->id)) {
         $coursecontext = context_course::instance($course->id);
         $context = $coursecontext;
     } else {
         $coursecontext = null;
         $context = $categorycontext;
     }
     $courseconfig = get_config('moodlecourse');
     $this->course = $course;
     $this->context = $context;
     /// form definition with new course defaults
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('hidden', 'returnto', null);
     $mform->setType('returnto', PARAM_ALPHANUM);
     $mform->setConstant('returnto', $returnto);
     // verify permissions to change course category or keep current
     if (empty($course->id)) {
         if (has_capability('moodle/course:create', $categorycontext)) {
             $displaylist = array();
             $parentlist = array();
             make_categories_list($displaylist, $parentlist, 'moodle/course:create');
             $mform->addElement('select', 'category', get_string('category'), $displaylist);
             $mform->addHelpButton('category', 'category');
             $mform->setDefault('category', $category->id);
         } else {
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $category->id);
         }
     } else {
         if (has_capability('moodle/course:changecategory', $coursecontext)) {
             $displaylist = array();
             $parentlist = array();
             make_categories_list($displaylist, $parentlist, 'moodle/course:create');
             if (!isset($displaylist[$course->category])) {
                 //always keep current
                 $displaylist[$course->category] = format_string($DB->get_field('course_categories', 'name', array('id' => $course->category)));
             }
             $mform->addElement('select', 'category', get_string('category'), $displaylist);
             $mform->addHelpButton('category', 'category');
         } else {
             //keep current
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $course->category);
         }
     }
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->addHelpButton('fullname', 'fullnamecourse');
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
         $mform->hardFreeze('fullname');
         $mform->setConstant('fullname', $course->fullname);
     }
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->addHelpButton('shortname', 'shortnamecourse');
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
         $mform->hardFreeze('shortname');
         $mform->setConstant('shortname', $course->shortname);
     }
     $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100"  size="10"');
     $mform->addHelpButton('idnumber', 'idnumbercourse');
     $mform->setType('idnumber', PARAM_RAW);
     if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
         $mform->setConstants('idnumber', $course->idnumber);
     }
     $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions);
     $mform->addHelpButton('summary_editor', 'coursesummary');
     $mform->setType('summary_editor', PARAM_RAW);
     if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
         $mform->hardFreeze('summary_editor');
     }
     $courseformats = get_sorted_course_formats(true);
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}");
     }
     if (isset($course->format)) {
         $course->format = course_get_format($course)->get_format();
         // replace with default if not found
         if (!in_array($course->format, $courseformats)) {
             // this format is disabled. Still display it in the dropdown
             $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format));
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->addHelpButton('format', 'format');
     $mform->setDefault('format', $courseconfig->format);
     // button to update format-specific options on format change (will be hidden by JavaScript)
     $mform->registerNoSubmitButton('updatecourseformat');
     $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->addHelpButton('startdate', 'startdate');
     $mform->setDefault('startdate', time() + 3600 * 24);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->addHelpButton('newsitems', 'newsitemsnumber');
     $mform->setDefault('newsitems', $courseconfig->newsitems);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->addHelpButton('showgrades', 'showgrades');
     $mform->setDefault('showgrades', $courseconfig->showgrades);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->addHelpButton('showreports', 'showreports');
     $mform->setDefault('showreports', $courseconfig->showreports);
     // Handle non-existing $course->maxbytes on course creation.
     $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;
     // Let's prepare the maxbytes popup.
     $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->addHelpButton('maxbytes', 'maximumupload');
     $mform->setDefault('maxbytes', $courseconfig->maxbytes);
     if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
         if (empty($course->legacyfiles)) {
             //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
             $choices = array('0' => get_string('no'), '2' => get_string('yes'));
         } else {
             $choices = array('1' => get_string('no'), '2' => get_string('yes'));
         }
         $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
         $mform->addHelpButton('legacyfiles', 'courselegacyfiles');
         if (!isset($courseconfig->legacyfiles)) {
             // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses
             $courseconfig->legacyfiles = 0;
         }
         $mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
     }
     if (!empty($CFG->allowcoursethemes)) {
         $themeobjects = get_list_of_themes();
         $themes = array();
         $themes[''] = get_string('forceno');
         foreach ($themeobjects as $key => $theme) {
             if (empty($theme->hidefromselector)) {
                 $themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
             }
         }
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'addcourseformatoptionshere');
     //--------------------------------------------------------------------------------
     enrol_course_edit_form($mform, $course, $context);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('groupsnone', 'group');
     $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
     $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
     $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
     $mform->addHelpButton('groupmode', 'groupmode', 'group');
     $mform->setDefault('groupmode', $courseconfig->groupmode);
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'groupmodeforce', get_string('groupmodeforce', 'group'), $choices);
     $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
     $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
     //default groupings selector
     $options = array();
     $options[0] = get_string('none');
     $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('availability'));
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $mform->addElement('select', 'visible', get_string('availability'), $choices);
     $mform->addHelpButton('visible', 'availability');
     $mform->setDefault('visible', $courseconfig->visible);
     if (!has_capability('moodle/course:visibility', $context)) {
         $mform->hardFreeze('visible');
         if (!empty($course->id)) {
             $mform->setConstant('visible', $course->visible);
         } else {
             $mform->setConstant('visible', $courseconfig->visible);
         }
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('language'));
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_string_manager()->get_list_of_translations();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     $mform->setDefault('lang', $courseconfig->lang);
     //--------------------------------------------------------------------------------
     if (completion_info::is_enabled_for_site()) {
         $mform->addElement('header', '', get_string('progress', 'completion'));
         $mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'), array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion')));
         $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
         $mform->addElement('advcheckbox', 'completionstartonenrol', get_string('completionstartonenrol', 'completion'));
         $mform->setDefault('completionstartonenrol', $courseconfig->completionstartonenrol);
         $mform->disabledIf('completionstartonenrol', 'enablecompletion', 'eq', 0);
     } else {
         $mform->addElement('hidden', 'enablecompletion');
         $mform->setType('enablecompletion', PARAM_INT);
         $mform->setDefault('enablecompletion', 0);
         $mform->addElement('hidden', 'completionstartonenrol');
         $mform->setType('completionstartonenrol', PARAM_INT);
         $mform->setDefault('completionstartonenrol', 0);
     }
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
     $mform->addHelpButton('rolerenaming', 'rolerenaming');
     if ($roles = get_all_roles()) {
         $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL);
         $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname));
             $mform->setType('role_' . $role->id, PARAM_TEXT);
             if (!in_array($role->id, $assignableroles)) {
                 $mform->setAdvanced('role_' . $role->id);
             }
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     /// finally set the current form data
     //--------------------------------------------------------------------------------
     $this->set_data($course);
 }
Example #26
0
 function definition()
 {
     global $USER, $CFG, $DB;
     $courseconfig = get_config('moodlecourse');
     $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 ($DB->count_records('course_meta', array('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, 'moodle/course:create');
         $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);
     $fullname = get_string('defaultcoursefullname');
     $shortname = get_string('defaultcourseshortname');
     while ($DB->record_exists('course', array('fullname' => $fullname)) or $DB->record_exists('course', array('fullname' => $fullname))) {
         $fullname++;
         $shortname++;
     }
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_MULTILANG);
     if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
         $mform->hardFreeze('fullname');
         $mform->setConstant('fullname', $course->fullname);
     }
     $mform->setDefault('fullname', $fullname);
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_MULTILANG);
     if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
         $mform->hardFreeze('shortname');
         $mform->setConstant('shortname', $course->shortname);
     }
     $mform->setDefault('shortname', $shortname);
     $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);
     if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
         $mform->setConstants('idnumber', $course->idnumber);
     }
     $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65'));
     $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
     $mform->setType('summary', PARAM_RAW);
     $courseformats = get_list_of_plugins('course/format');
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
         if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
             $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
     $mform->setDefault('format', $courseconfig->format);
     for ($i = 1; $i <= 52; $i++) {
         $sectionmenu[$i] = "{$i}";
     }
     $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
     $mform->setDefault('numsections', $courseconfig->numsections);
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
     $mform->setDefault('startdate', time() + 3600 * 24);
     $choices = array();
     $choices['0'] = get_string('hiddensectionscollapsed');
     $choices['1'] = get_string('hiddensectionsinvisible');
     $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
     $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
     $mform->setDefault('hiddensections', $courseconfig->hiddensections);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
     $mform->setDefault('newsitems', $courseconfig->newsitems);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
     $mform->setDefault('showgrades', $courseconfig->showgrades);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
     $mform->setDefault('showreports', $courseconfig->showreports);
     $choices = get_max_upload_sizes($CFG->maxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
     $mform->setDefault('maxbytes', $courseconfig->maxbytes);
     if (!empty($CFG->allowcoursethemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $meta = array();
     $meta[0] = get_string('no');
     $meta[1] = get_string('yes');
     if ($disable_meta === false) {
         $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
         $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
         $mform->setDefault('metacourse', $courseconfig->metacourse);
     } else {
         // no metacourse element - we do not want to change it anyway!
         $mform->addElement('static', 'nometacourse', get_string('managemeta'), (empty($course->metacourse) ? $meta[0] : $meta[1]) . " - {$disable_meta} ");
         $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'enrolhdr', get_string('enrolments'));
     $choices = array();
     $modules = explode(',', $CFG->enrol_plugins_enabled);
     foreach ($modules as $module) {
         $name = get_string('enrolname', "enrol_{$module}");
         $plugin = enrolment_factory::factory($module);
         if (method_exists($plugin, 'print_entry')) {
             $choices[$name] = $module;
         }
     }
     asort($choices);
     $choices = array_flip($choices);
     $choices = array_merge(array('' => get_string('sitedefault') . ' (' . get_string('enrolname', "enrol_{$CFG->enrol}") . ')'), $choices);
     $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
     $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
     $mform->setDefault('enrol', $courseconfig->enrol);
     $roles = get_assignable_roles($context);
     if (!empty($course)) {
         // add current default role, so that it is selectable even when user can not assign it
         if ($current_role = $DB->get_record('role', array('id' => $course->defaultrole))) {
             $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
         }
     }
     $choices = array();
     if ($sitedefaultrole = $DB->get_record('role', array('id' => $CFG->defaultcourseroleid))) {
         $choices[0] = get_string('sitedefault') . ' (' . $sitedefaultrole->name . ')';
     } else {
         $choices[0] = get_string('sitedefault');
     }
     $choices = $choices + $roles;
     // fix for MDL-9197
     foreach ($choices as $choiceid => $choice) {
         $choices[$choiceid] = format_string($choice);
     }
     $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
     $mform->setDefault('defaultrole', 0);
     $radio = array();
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
     $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
     $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true);
     $mform->setDefault('enrollable', $courseconfig->enrollable);
     $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate'), array('optional' => true));
     $mform->setDefault('enrolstartdate', 0);
     $mform->disabledIf('enrolstartdate', 'enrollable', 'neq', 2);
     $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate'), array('optional' => true));
     $mform->setDefault('enrolenddate', 0);
     $mform->disabledIf('enrolenddate', 'enrollable', 'neq', 2);
     $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod'), array('optional' => true, 'defaultunit' => 86400));
     $mform->setDefault('enrolperiod', $courseconfig->enrolperiod);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'expirynotifyhdr', get_string('expirynotify'));
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'expirynotify', get_string('notify'), $choices);
     $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
     $mform->setDefault('expirynotify', $courseconfig->expirynotify);
     $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
     $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
     $mform->setDefault('notifystudents', $courseconfig->notifystudents);
     $thresholdmenu = array();
     for ($i = 1; $i <= 30; $i++) {
         $seconds = $i * 86400;
         $thresholdmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
     $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
     $mform->setDefault('expirythreshold', $courseconfig->expirythreshold);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('groupsnone', 'group');
     $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
     $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
     $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices);
     $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
     $mform->setDefault('groupmode', $courseconfig->groupmode);
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
     $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
     $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
     if (!empty($CFG->enablegroupings)) {
         //default groupings selector
         $options = array();
         $options[0] = get_string('none');
         $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('availability'));
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $mform->addElement('select', 'visible', get_string('availability'), $choices);
     $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
     $mform->setDefault('visible', $courseconfig->visible);
     if ($course and !has_capability('moodle/course:visibility', $coursecontext)) {
         $mform->hardFreeze('visible');
         $mform->setConstant('visible', $course->visible);
     }
     $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"');
     $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true);
     $mform->setDefault('enrolpassword', '');
     $mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
     $mform->setType('enrolpassword', PARAM_RAW);
     if (empty($course) or $course->password !== '' and $course->id != SITEID) {
         // do not require password in existing courses that do not have password yet - backwards compatibility ;-)
         if (!empty($CFG->enrol_manual_requirekey)) {
             $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client');
         }
     }
     $choices = array();
     $choices['0'] = get_string('guestsno');
     $choices['1'] = get_string('guestsyes');
     $choices['2'] = get_string('guestskey');
     $mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
     $mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
     $mform->setDefault('guest', $courseconfig->guest);
     // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
     $enrol_object = $CFG;
     if (!empty($course)) {
         $enrol_object = $course;
     }
     // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
     if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && !($enrol_object->enrol == 'manual' || empty($enrol_object->enrol) && $CFG->enrol == 'manual')) {
         $costgroup = array();
         $currencies = get_list_of_currencies();
         $costgroup[] =& MoodleQuickForm::createElement('text', 'cost', '', 'maxlength="6" size="6"');
         $costgroup[] =& MoodleQuickForm::createElement('select', 'currency', '', $currencies);
         $mform->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
         //defining a rule for a form element within a group :
         $costgrprules = array();
         //set the message to null to tell Moodle to use a default message
         //available for most rules, fetched from language pack (err_{rulename}).
         $costgrprules['cost'][] = array(null, 'numeric', null, 'client');
         $mform->addGroupRule('costgrp', $costgrprules);
         $mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
         $mform->setDefault('cost', '');
         $mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('language'));
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_list_of_languages();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     $mform->setDefault('lang', $courseconfig->lang);
     //--------------------------------------------------------------------------------
     require_once $CFG->libdir . '/completionlib.php';
     if (completion_info::is_enabled_for_site()) {
         $mform->addElement('header', '', get_string('progress', 'completion'));
         $mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'), array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion')));
         $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
     } else {
         $mform->addElement('hidden', 'enablecompletion');
         $mform->setDefault('enablecompletion', 0);
     }
     //--------------------------------------------------------------------------------
     if (has_capability('moodle/site:config', $systemcontext) && (!empty($course->requested) && $CFG->restrictmodulesfor == 'requested' || $CFG->restrictmodulesfor == 'all')) {
         $mform->addElement('header', '', get_string('restrictmodules'));
         $options = array();
         $options['0'] = get_string('no');
         $options['1'] = get_string('yes');
         $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
         $mods = array(0 => get_string('allownone'));
         $mods += $DB->get_records_menu('modules', array(), 'name', 'id, name');
         $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple' => 'multiple', 'size' => '10'));
         $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
     } else {
         $mform->addElement('hidden', 'restrictmodules', null);
     }
     if ($CFG->restrictmodulesfor == 'all') {
         $mform->setDefault('allowedmods', explode(',', $CFG->defaultallowedmodules));
         if (!empty($CFG->restrictbydefault)) {
             $mform->setDefault('restrictmodules', 1);
         }
     }
     $mform->setType('restrictmodules', PARAM_INT);
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
     $mform->setHelpButton('rolerenaming', array('rolerenaming', get_string('rolerenaming')), true);
     if ($roles = get_all_roles()) {
         if ($coursecontext) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW);
         }
         $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->name));
             if (isset($role->localname)) {
                 $mform->setDefault('role_' . $role->id, $role->localname);
             }
             $mform->setType('role_' . $role->id, PARAM_TEXT);
             if (!in_array($role->id, $assignableroles)) {
                 $mform->setAdvanced('role_' . $role->id);
             }
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
 }
Example #27
0
 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 {
                 $managers = count(get_users_by_capability($coursecontext, 'moodle/course:managemetacourse'));
                 $participants = count(get_users_by_capability($coursecontext, 'moodle/course:view'));
                 if ($participants > $managers) {
                     $disable_meta = get_string('metaalreadyhasenrolments');
                 }
             }
         }
     } 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('fullname'), 'maxlength="254" size="50"');
     $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), 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('shortname'), 'maxlength="100" size="20"');
     $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), 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) {
         $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
         if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
             $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
     $mform->setDefault('format', 'weeks');
     for ($i = 1; $i <= 52; $i++) {
         $sectionmenu[$i] = "{$i}";
     }
     $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
     $mform->setDefault('numsections', 10);
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
     $mform->setDefault('startdate', time() + 3600 * 24);
     $choices = array();
     $choices['0'] = get_string('hiddensectionscollapsed');
     $choices['1'] = get_string('hiddensectionsinvisible');
     $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
     $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
     $mform->setDefault('hiddensections', 0);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
     $mform->setDefault('newsitems', 5);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
     $mform->setDefault('showgrades', 1);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
     $mform->setDefault('showreports', 0);
     $choices = get_max_upload_sizes($CFG->maxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
     if (!empty($CFG->allowcoursethemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $meta = array();
     $meta[0] = get_string('no');
     $meta[1] = get_string('yes');
     if ($disable_meta === false) {
         $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
         $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
         $mform->setDefault('metacourse', 0);
     } else {
         // no metacourse element - we do not want to change it anyway!
         $mform->addElement('static', 'nometacourse', get_string('managemeta'), (empty($course->metacourse) ? $meta[0] : $meta[1]) . " - {$disable_meta} ");
         $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'enrolhdr', get_string('enrolments'));
     $choices = array();
     $modules = explode(',', $CFG->enrol_plugins_enabled);
     foreach ($modules as $module) {
         $name = get_string('enrolname', "enrol_{$module}");
         $plugin = enrolment_factory::factory($module);
         if (method_exists($plugin, 'print_entry')) {
             $choices[$name] = $module;
         }
     }
     asort($choices);
     $choices = array_flip($choices);
     $choices = array_merge(array('' => get_string('sitedefault') . ' (' . get_string('enrolname', "enrol_{$CFG->enrol}") . ')'), $choices);
     $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
     $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
     $roles = get_assignable_roles($context);
     if (!empty($course)) {
         // add current default role, so that it is selectable even when user can not assign it
         if ($current_role = get_record('role', 'id', $course->defaultrole)) {
             $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
         }
     }
     $choices = array();
     if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) {
         $choices[0] = get_string('sitedefault') . ' (' . $sitedefaultrole->name . ')';
     } else {
         $choices[0] = get_string('sitedefault');
     }
     $choices = $choices + $roles;
     // fix for MDL-9197
     foreach ($choices as $choiceid => $choice) {
         $choices[$choiceid] = format_string($choice);
     }
     $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
     $mform->setDefault('defaultrole', 0);
     $radio = array();
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
     $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
     $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true);
     $mform->setDefault('enrollable', 1);
     $enroldatestartgrp = array();
     $enroldatestartgrp[] =& MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
     $enroldatestartgrp[] =& MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
     $mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false);
     $mform->setDefault('enrolstartdate', 0);
     $mform->setDefault('enrolstartdisabled', 1);
     $mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked');
     $enroldateendgrp = array();
     $enroldateendgrp[] =& MoodleQuickForm::createElement('date_selector', 'enrolenddate');
     $enroldateendgrp[] =& MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
     $mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
     $mform->setDefault('enrolenddate', 0);
     $mform->setDefault('enrolenddisabled', 1);
     $mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked');
     $periodmenu = array();
     $periodmenu[0] = get_string('unlimited');
     for ($i = 1; $i <= 365; $i++) {
         $seconds = $i * 86400;
         $periodmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'enrolperiod', get_string('enrolperiod'), $periodmenu);
     $mform->setDefault('enrolperiod', 0);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'expirynotifyhdr', get_string('expirynotify'));
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'expirynotify', get_string('notify'), $choices);
     $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
     $mform->setDefault('expirynotify', 0);
     $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
     $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
     $mform->setDefault('notifystudents', 0);
     $thresholdmenu = array();
     for ($i = 1; $i <= 30; $i++) {
         $seconds = $i * 86400;
         $thresholdmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
     $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
     $mform->setDefault('expirythreshold', 10 * 86400);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('no');
     $choices[SEPARATEGROUPS] = get_string('separate');
     $choices[VISIBLEGROUPS] = get_string('visible');
     $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices);
     $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
     $mform->setDefault('groupmode', 0);
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
     $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
     $mform->setDefault('groupmodeforce', 0);
     if (!empty($CFG->enablegroupings)) {
         //default groupings selector
         $options = array();
         $options[0] = get_string('none');
         $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('availability'));
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $mform->addElement('select', 'visible', get_string('availability'), $choices);
     $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
     $mform->setDefault('visible', 1);
     $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"');
     $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true);
     $mform->setDefault('enrolpassword', '');
     $mform->setType('enrolpassword', PARAM_RAW);
     $choices = array();
     $choices['0'] = get_string('guestsno');
     $choices['1'] = get_string('guestsyes');
     $choices['2'] = get_string('guestskey');
     $mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
     $mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
     $mform->setDefault('guest', 0);
     // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
     $enrol_object = $CFG;
     if (!empty($course)) {
         $enrol_object = $course;
     }
     if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && $enrol_object->enrol != 'manual') {
         $costgroup = array();
         $currencies = get_list_of_currencies();
         $costgroup[] =& MoodleQuickForm::createElement('text', 'cost', '', 'maxlength="6" size="6"');
         $costgroup[] =& MoodleQuickForm::createElement('select', 'currency', '', $currencies);
         $mform->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
         //defining a rule for a form element within a group :
         $costgrprules = array();
         //set the message to null to tell Moodle to use a default message
         //available for most rules, fetched from language pack (err_{rulename}).
         $costgrprules['cost'][] = array(null, 'numeric', null, 'client');
         $mform->addGroupRule('costgrp', $costgrprules);
         $mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
         $mform->setDefault('cost', '');
         $mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('language'));
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_list_of_languages();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     //--------------------------------------------------------------------------------
     if (has_capability('moodle/site:config', $systemcontext) && (!empty($course->requested) && $CFG->restrictmodulesfor == 'requested' || $CFG->restrictmodulesfor == 'all')) {
         $mform->addElement('header', '', get_string('restrictmodules'));
         $options = array();
         $options['0'] = get_string('no');
         $options['1'] = get_string('yes');
         $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
         $mods = array(0 => get_string('allownone'));
         $mods += get_records_menu('modules', '', '', '', 'id, name');
         $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple' => 'multiple', 'size' => '10'));
         $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
     } else {
         $mform->addElement('hidden', 'restrictmodules', null);
     }
     if ($CFG->restrictmodulesfor == 'all') {
         $mform->setDefault('allowedmods', explode(',', $CFG->defaultallowedmodules));
         if (!empty($CFG->restrictbydefault)) {
             $mform->setDefault('restrictmodules', 1);
         }
     }
     $mform->setType('restrictmodules', PARAM_INT);
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('roles'));
     if ($roles = get_records('role')) {
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, $role->name);
             if ($coursecontext) {
                 if ($rolename = get_record('role_names', 'roleid', $role->id, 'contextid', $coursecontext->id)) {
                     $mform->setDefault('role_' . $role->id, $rolename->text);
                 }
             }
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     // fill in default teacher and student names to keep backwards compatibility for a while
     $mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher'));
     $mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers'));
     $mform->addElement('hidden', 'student', get_string('defaultcoursestudent'));
     $mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
 }
    }
    // finally reorder courses
    fix_course_sortorder();
}
/// Print headings
echo $OUTPUT->header();
echo $OUTPUT->heading($strcategories);
/// Print out the categories with all the knobs
$strcategories = 'Materias';
$strcourses = get_string('courses');
$strmovecategoryto = 'Mover materia a';
$stredit = get_string('edit');
$displaylist = array();
$parentlist = array();
$displaylist[0] = get_string('top');
make_categories_list($displaylist, $parentlist);
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">' . $strcategories . '</th>';
echo '<th class="header" scope="col">' . $strcourses . '</th>';
echo '<th class="header" scope="col">' . $stredit . '</th>';
//echo '<th class="header" scope="col">'.$strmovecategoryto.'</th>';
echo '</tr>';
print_category_edit(NULL, $displaylist, $parentlist);
echo '</table>';
echo '<div class="buttons">';
if (has_capability('moodle/course:create', $systemcontext)) {
    // print create course link to first category
    $options = array('category' => $CFG->defaultrequestcategory);
    $options['returnto'] = 'topcat';
    /*    echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');*/
}
 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $category = $this->_customdata['category'];
     $editoroptions = $this->_customdata['editoroptions'];
     // get list of categories to use as parents, with site as the first one
     $options = array();
     if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
         $options[0] = get_string('top');
     }
     $parents = array();
     if ($category->id) {
         // Editing an existing category.
         /*
         //			$sql= 'SELECT * FROM {course_categories} c, {vrsspl_course_subject_info} b WHERE c.id= ? AND b.categoryid= ? AND c.batch= ?';
         			$ifbatch = $DB->get_record_sql('SELECT * FROM {course_categories} WHERE id= ? AND batch= ?', array($category->id, 1), IGNORE_MISSING);
         //			$ifbatch = get_record_sql('SELECT * ');
         			if($ifbatch)
         			{
         				echo "Batch has already been started, you cannot edit settings now.";
         				$mform->disabledIf('mform','ifbatch','neq','0');
         			}
         			else
         			{
         */
         make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
         if (empty($options[$category->parent])) {
             $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id' => $category->parent));
         }
         $strsubmit = get_string('savechanges');
         //		}
     } else {
         // Making a new category
         make_categories_list($options, $parents, 'moodle/category:manage');
         $strsubmit = get_string('createcategory');
     }
     $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
     $mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30'));
     $mform->addRule('name', get_string('required'), 'required', null);
     $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'), 'maxlength="100"  size="10"');
     $mform->addHelpButton('idnumber', 'idnumbercoursecategory');
     $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
     $mform->setType('description_editor', PARAM_RAW);
     if (!empty($CFG->allowcategorythemes)) {
         $themes = array('' => get_string('forceno'));
         $allthemes = get_list_of_themes();
         foreach ($allthemes as $key => $theme) {
             if (empty($theme->hidefromselector)) {
                 $themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
             }
         }
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $meta = array();
     $meta[0] = get_string('no');
     $meta[1] = get_string('yes');
     $mform->addElement('select', 'batch', 'Course Batch', $meta);
     $mform->addElement('date_selector', 'batchstart', 'Start Date');
     $mform->disabledIf('batchstart', 'batch', 'eq', 0);
     $mform->addElement('date_selector', 'batchend', 'End Date');
     $mform->disabledIf('batchend', 'batch', 'eq', 0);
     $mform->addElement('static', 'label1', 'No Of Subject', '<div id="coursecount" style="margin-bottom:-15px;"></div>');
     $mform->addElement('static', 'label1', 'Subject Selection', '<div id="basic-modal" style="margin-bottom:-15px;"><a href="#" class="basic">View All</a></div>');
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->setDefault('id', $category->id);
     //$this->add_action_buttons(true, $strsubmit);
     //normally you use add_action_buttons instead of this code
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
     $buttonarray[] =& $mform->createElement('button', 'startbatch', 'Start Batch', '<div id="basic-modal-button"><a href="#" class="basic"></div>');
     $mform->disabledIf('startbatch', 'batch', 'eq', 0);
     $buttonarray[] =& $mform->createElement('cancel');
     //		$mform->disabledIf('submitbutton', 'batch', 'eq', 1);
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
     $mform->addElement('static', 'label1', '', '<div id="errormessage" style="color:#AA0000; font-size:14px;"></div>');
     //$mform->addElement('html', '<div>ramesh</div>');
 }