public function definition()
 {
     global $CFG, $COURSE, $DB;
     $mform =& $this->_form;
     $coursecontext = context_course::instance($COURSE->id);
     $forumng = $this->_instance ? $DB->get_record('forumng', array('id' => $this->_instance)) : null;
     $this->clone = $forumng ? $forumng->originalcmid : 0;
     // If this is a clone, don't show the normal form
     if ($this->clone) {
         $mform->addElement('hidden', 'name', $forumng->name);
         if (!empty($CFG->formatstringstriptags)) {
             $mform->setType('name', PARAM_TEXT);
         } else {
             $mform->setType('name', PARAM_NOTAGS);
         }
         $mform->addElement('static', 'sharedthing', '', get_string('sharedinfo', 'forumng', $CFG->wwwroot . '/course/modedit.php?update=' . $this->clone . '&return=1'));
         $this->shared_definition_part($coursecontext);
         return;
     }
     $mform->addElement('header', 'general', get_string('general', 'form'));
     // Forum name
     $mform->addElement('text', 'name', get_string('forumname', 'forumng'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_NOTAGS);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     // Forum types
     $types = forumngtype::get_all();
     $options = array();
     foreach ($types as $type) {
         if ($type->is_user_selectable()) {
             $options[$type->get_id()] = $type->get_name();
         }
     }
     $mform->addElement('select', 'type', get_string('forumtype', 'forumng'), $options);
     $mform->addHelpButton('type', 'forumtype', 'forumng');
     $mform->setDefault('type', 'general');
     $this->standard_intro_elements(get_string('forumintro', 'forumng'));
     // Subscription option displays only if enabled at site level
     if ($CFG->forumng_subscription == -1) {
         $options = mod_forumng::get_subscription_options();
         $mform->addElement('select', 'subscription', get_string('subscription', 'forumng'), $options);
         $mform->setDefault('subscription', mod_forumng::SUBSCRIPTION_PERMITTED);
         $mform->addHelpButton('subscription', 'subscription', 'forumng');
     } else {
         // Hidden element contains default value (not used anyhow)
         $mform->addElement('hidden', 'subscription', mod_forumng::SUBSCRIPTION_PERMITTED);
         $mform->setType('subscription', PARAM_INT);
     }
     // Max size of attachments
     $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
     $choices[-1] = get_string('uploadnotallowed');
     $mform->addElement('select', 'attachmentmaxbytes', get_string('attachmentmaxbytes', 'forumng'), $choices);
     $mform->addHelpButton('attachmentmaxbytes', 'attachmentmaxbytes', 'forumng');
     $mform->setDefault('attachmentmaxbytes', $CFG->forumng_attachmentmaxbytes);
     // Email address for reporting unacceptable post for this forum, default is blank.
     $mform->addElement('text', 'reportingemail', get_string('reportingemail', 'forumng'), array('size' => 64));
     $mform->setType('reportingemail', PARAM_NOTAGS);
     $mform->addRule('reportingemail', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addHelpButton('reportingemail', 'reportingemail', 'forumng');
     $mform->addElement('checkbox', 'canpostanon', get_string('canpostanon', 'forumng'));
     $mform->addHelpButton('canpostanon', 'canpostanon', 'forumng');
     // Atom/RSS feed on/off/discussions-only
     if ($CFG->enablerssfeeds && !empty($CFG->forumng_enablerssfeeds)) {
         if ($CFG->forumng_feedtype == -1 || $CFG->forumng_feeditems == -1) {
             $mform->addElement('header', '', get_string('feeds', 'forumng'));
         }
         if ($CFG->forumng_feedtype == -1) {
             $mform->addElement('select', 'feedtype', get_string('feedtype', 'forumng'), mod_forumng::get_feedtype_options());
             $mform->setDefault('feedtype', mod_forumng::FEEDTYPE_ALL_POSTS);
             $mform->addHelpButton('feedtype', 'feedtype', 'forumng');
         }
         // Atom/RSS feed item count
         if ($CFG->forumng_feeditems == -1) {
             $mform->addElement('select', 'feeditems', get_string('feeditems', 'forumng'), mod_forumng::get_feeditems_options());
             $mform->setDefault('feeditems', 20);
             $mform->addHelpButton('feeditems', 'feeditems', 'forumng');
         }
     }
     // Add tagging to discussions.
     if ($CFG->usetags) {
         $mform->addElement('header', '', get_string('tagging', 'forumng'));
         // Enable tagging.
         $mform->addElement('checkbox', 'tags', get_string('enabletagging', 'forumng'));
         $mform->addHelpButton('tags', 'tagging', 'forumng');
         // Add 'Set' forumng wide named tags to discussion tagging dropdowns.
         $settags = null;
         if ($forumng) {
             $settags = mod_forumng::get_set_tags($this->_instance);
             // Create 'Set' forumng wide tags.
             $mform->addElement('tags', 'settags', get_string('setforumtags', 'forumng'), array('display' => 'noofficial'));
             $mform->disabledIf('settags', 'tags', 'notchecked');
             $mform->setType('settags', PARAM_TAGLIST);
             $mform->setDefault('settags', $settags);
             $mform->addHelpButton('settags', 'settags', 'forumng');
         }
     }
     // Ratings header
     /*///////////////*/
     $mform->addElement('header', '', get_string('ratings', 'forumng'));
     $options = array(mod_forumng::FORUMNG_NO_RATING => get_string('noratings', 'forumng'), mod_forumng::FORUMNG_RATING_OBSOLETE => get_string('forumngratingsobsolete', 'forumng'), mod_forumng::FORUMNG_STANDARD_RATING => get_string('standardratings', 'forumng'));
     $mform->addElement('select', 'enableratings', get_string('enableratings', 'forumng'), $options);
     $mform->addHelpButton('enableratings', 'enableratings', 'forumng');
     // Scale
     $mform->addElement('modgrade', 'ratingscale', get_string('scale'), null, true);
     $mform->disabledIf('ratingscale', 'enableratings', 'eq', 0);
     $mform->setDefault('ratingscale', 5);
     // From/until times
     $mform->addElement('date_time_selector', 'ratingfrom', get_string('ratingfrom', 'forumng'), array('optional' => true));
     $mform->disabledIf('ratingfrom', 'enableratings', 'eq', 0);
     $mform->addElement('date_time_selector', 'ratinguntil', get_string('ratinguntil', 'forumng'), array('optional' => true));
     $mform->disabledIf('ratinguntil', 'enableratings', 'eq', 0);
     $mform->addElement('text', 'ratingthreshold', get_string('ratingthreshold', 'forumng'));
     $mform->setType('ratingthreshold', PARAM_INT);
     $mform->setDefault('ratingthreshold', 1);
     $mform->addRule('ratingthreshold', get_string('error_ratingthreshold', 'forumng'), 'regex', '/[1-9][0-9]*/', 'client');
     $mform->addHelpButton('ratingthreshold', 'ratingthreshold', 'forumng');
     $mform->disabledIf('ratingthreshold', 'enableratings', 'neq', mod_forumng::FORUMNG_RATING_OBSOLETE);
     // Grading.
     $mform->addElement('header', '', get_string('grading', 'forumng'));
     $mform->addElement('select', 'grading', get_string('grade'), mod_forumng::get_grading_options());
     $mform->setDefault('grading', mod_forumng::GRADING_NONE);
     $mform->addHelpButton('grading', 'grading', 'forumng');
     $mform->addElement('modgrade', 'gradingscale', get_string('gradingscale', 'forumng'));
     $mform->disabledIf('gradingscale', 'grading', 'ne', mod_forumng::GRADING_MANUAL);
     $mform->setDefault('gradingscale', 5);
     // Blocking header
     /*////////////////*/
     $mform->addElement('header', '', get_string('limitposts', 'forumng'));
     // Post dates
     $mform->addElement('date_time_selector', 'postingfrom', get_string('postingfrom', 'forumng'), array('optional' => true));
     $mform->addElement('date_time_selector', 'postinguntil', get_string('postinguntil', 'forumng'), array('optional' => true));
     // User limits
     $limitgroup = array();
     $limitgroup[] = $mform->createElement('checkbox', 'enablelimit', '');
     $options = mod_forumng::get_max_posts_period_options();
     $limitgroup[] = $mform->createElement('text', 'maxpostsblock', '', array('size' => 3));
     $limitgroup[] = $mform->createElement('static', 'staticthing', '', ' ' . get_string('postsper', 'forumng') . ' ');
     $limitgroup[] = $mform->createElement('select', 'maxpostsperiod', '', $options);
     $mform->addGroup($limitgroup, 'limitgroup', get_string('enablelimit', 'forumng'));
     $mform->disabledIf('limitgroup[maxpostsblock]', 'limitgroup[enablelimit]');
     $mform->disabledIf('limitgroup[maxpostsperiod]', 'limitgroup[enablelimit]');
     $mform->addHelpButton('limitgroup', 'enablelimit', 'forumng');
     $mform->setType('limitgroup[maxpostsblock]', PARAM_INT);
     $mform->setDefault('limitgroup[maxpostsblock]', '10');
     // Remove old discussion
     $options = array();
     $options[0] = get_string('removeolddiscussionsdefault', 'forumng');
     for ($i = 1; $i <= 36; $i++) {
         $options[$i * 2592000] = $i > 1 ? get_string('nummonths', 'moodle', $i) : get_string('onemonth', 'forumng');
     }
     $mform->addElement('header', '', get_string('removeolddiscussions', 'forumng'));
     $mform->addElement('select', 'removeafter', get_string('removeolddiscussionsafter', 'forumng'), $options);
     $mform->addHelpButton('removeafter', 'removeolddiscussions', 'forumng');
     $options = array();
     $options[0] = get_string('deletepermanently', 'forumng');
     $options[-1] = get_string('automaticallylock', 'forumng');
     $modinfo = get_fast_modinfo($COURSE);
     $targetforumngid = $this->_instance ? $this->_instance : 0;
     // Add all instances to drop down if the user can access them and
     // it's not the same as the current forum
     if (array_key_exists('forumng', $modinfo->instances)) {
         foreach ($modinfo->instances['forumng'] as $info) {
             if ($info->uservisible && $targetforumngid != $info->instance) {
                 $options[$info->instance] = $info->name;
             }
         }
     }
     $mform->addElement('select', 'removeto', get_string('withremoveddiscussions', 'forumng'), $options);
     $mform->disabledIf('removeto', 'removeafter', 'eq', 0);
     $mform->addHelpButton('removeto', 'withremoveddiscussions', 'forumng');
     // Sharing options are advanced and for administrators only
     if ($CFG->forumng_enableadvanced && has_capability('mod/forumng:addinstance', context_system::instance())) {
         $mform->addElement('header', '', get_string('sharing', 'forumng'));
         $mform->addElement('advcheckbox', 'shared', get_string('shared', 'forumng'));
         $mform->addHelpButton('shared', 'shared', 'forumng');
         // Only when creating a forum, you can choose to make it a clone
         if (!$this->_instance) {
             $sharegroup = array();
             $sharegroup[] = $mform->createElement('checkbox', 'useshared', '');
             $sharegroup[] = $mform->createElement('text', 'originalcmidnumber', '');
             $mform->setType('usesharedgroup[originalcmidnumber]', PARAM_RAW);
             $mform->addGroup($sharegroup, 'usesharedgroup', get_string('useshared', 'forumng'));
             $mform->disabledIf('usesharedgroup[originalcmidnumber]', 'usesharedgroup[useshared]', 'notchecked');
             $mform->addHelpButton('usesharedgroup', 'useshared', 'forumng');
         }
     }
     // Do definition that is shared with clone version of form
     $this->shared_definition_part($coursecontext);
     if (count(mod_forumng_utils::get_convertible_forums($COURSE)) > 0 && !$this->_instance) {
         $mform->addElement('static', '', '', '<div class="forumng-convertoffer">' . get_string('offerconvert', 'forumng', $CFG->wwwroot . '/mod/forumng/convert.php?course=' . $COURSE->id) . '</div>');
     }
 }