. /** * The main lamslesson configuration form * * It uses the standard core Moodle formslib. For more info about them, please * visit: http://docs.moodle.org/en/Development:lib/formslib.php * * @package mod_lamslesson * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 */ defined('MOODLE_INTERNAL') || die(); $PAGE->requires->yui2_lib('yahoo-dom-event'); $PAGE->requires->yui2_lib('treeview'); $PAGE->requires->yui2_lib('event'); $PAGE->requires->yui2_lib('connection'); require_once($CFG->dirroot.'/course/moodleform_mod.php'); class mod_lamslesson_mod_form extends moodleform_mod { function definition() { global $COURSE, $USER, $CFG; $mform =& $this->_form; //------------------------------------------------------------------------------- /// 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('lamslessonname', 'lamslesson'), array('size'=>'64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEAN); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addHelpButton('name', 'lamslessonname', 'lamslesson'); /// Adding the standard "intro" and "introformat" fields $this->add_intro_editor(); //------------------------------------------------------------------------------- /// Adding the rest of lamslesson settings, spreeading all them into this fieldset /// or adding more fieldsets ('header' elements) if needed for better logic // Set needed vars $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $locale = lamslesson_get_locale($COURSE->id); $canmanage = has_capability('mod/lamslesson:manage', $context); //-- Open Author & Preview URL buttons // Check whether this person has the right permissions to see the open button. if ($canmanage) { $customcsv = "$USER->username,$COURSE->id,$CFG->lamslesson_serverid"; $authorurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], 0, $COURSE->id, $COURSE->fullname, $COURSE->timecreated, LAMSLESSON_PARAM_AUTHOR_METHOD, $customcsv); $previewurl = $CFG->wwwroot.'/mod/lamslesson/preview.php?'; $popupoptions = LAMSLESSON_POPUP_OPTIONS; $openauthorlabel = get_string('openauthor', 'lamslesson'); $openpreviewlabel = get_string('previewthislesson', 'lamslesson'); // html "chunk" for open Author button $authorpreviewbutton = << XXX; } $mform->addElement('hidden', 'sequence_id'); $mform->setType('sequence_id', PARAM_INT); $mform->addElement('hidden', 'customCSV', $customcsv); $mform->setType('customCSV', PARAM_TEXT); // display user's lams workspace $lds = lamslesson_get_sequences_rest($USER->username, $COURSE->id, $COURSE->fullname, $COURSE->timecreated, $USER->country, $USER->lang) ; // html "chuck" for YUI tree $html = <<
XXX; // Now we put the two html chunks together $html = $authorpreviewbutton . $html; $mform->addElement('header', 'selectsequence', get_string('selectsequence', 'lamslesson')); $mform->addElement('static', 'sequencemessage', '', $html); //------------------------------------------------------------------------------- // add standard elements, common to all modules $this->standard_coursemodule_elements(); //------------------------------------------------------------------------------- // add standard buttons, common to all modules $this->add_action_buttons(); } function validation($data) { $errors = array(); // a sequence needs to be selected if (empty($data['sequence_id']) || $data['sequence_id'] <= 0) { $errors['sequencemessage'] = get_string('sequencenotselected', 'lamslesson'); } return $errors; } function add_completion_rules() { $mform =& $this->_form; $mform->addElement('checkbox', 'completionfinish', '', get_string('completionfinish', 'lamslesson')); return array('completionfinish'); } function completion_rule_enabled($data) { return !empty($data['completionfinish']); } }