. require_once($CFG->libdir.'/formslib.php'); define('APPLY_ITEM_NAME_TEXTBOX_SIZE', 40); define('APPLY_ITEM_LABEL_TEXTBOX_SIZE', 20); define('APPLY_ITEM_STYLE_TEXTBOX_SIZE', 40); abstract class apply_item_form extends moodleform { public function definition() { $item = $this->_customdata['item']; //the item object //common is an array like: // array('cmid'=>$cm->id, // 'id'=>isset($item->id) ? $item->id : NULL, // 'typ'=>$item->typ, // 'items'=>$applyitems, // 'apply_id'=>$apply->id); $common = $this->_customdata['common']; //positionlist is an array with possible positions for the item location $positionlist = $this->_customdata['positionlist']; //the current position of the item $position = $this->_customdata['position']; $mform =& $this->_form; if ($common['items']) { $mform->addElement('select', 'dependitem', get_string('dependitem', 'apply').' ', $common['items']); $mform->addHelpButton('dependitem', 'depending', 'apply'); $mform->addElement('text', 'dependvalue', get_string('dependvalue', 'apply'), array('size'=>APPLY_ITEM_LABEL_TEXTBOX_SIZE,'maxlength'=>255)); //$mform->setType('dependvalue', PARAM_ALPHA); $mform->setType('dependvalue', PARAM_TEXT); } else { $mform->addElement('hidden', 'dependitem', 0); $mform->setType('dependitem', PARAM_INT); $mform->addElement('hidden', 'dependvalue', ''); //$mform->setType('dependvalue', PARAM_ALPHA); $mform->setType('dependvalue', PARAM_TEXT); } $position_select = $mform->addElement('select', 'position', get_string('position', 'apply').' ', $positionlist); $position_select->setValue($position); $mform->addElement('hidden', 'cmid', $common['cmid']); $mform->setType('cmid', PARAM_INT); $mform->addElement('hidden', 'id', $common['id']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'apply_id', $common['apply_id']); $mform->setType('apply_id', PARAM_INT); $mform->addElement('hidden', 'template', 0); $mform->setType('template', PARAM_INT); $mform->setType('name', PARAM_RAW); $mform->setType('label', PARAM_ALPHAEXT); $mform->addElement('hidden', 'typ', $this->type); $mform->setType('typ', PARAM_ALPHA); $mform->addElement('hidden', 'hasvalue', 0); $mform->setType('hasvalue', PARAM_INT); $mform->addElement('hidden', 'options', ''); $mform->setType('options', PARAM_ALPHA); $buttonarray = array(); if (!empty($item->id)) { $buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'apply')); $buttonarray[] = &$mform->createElement('submit', 'clone_item', get_string('save_as_new_item', 'apply')); } else { $mform->addElement('hidden', 'clone_item', 0); $mform->setType('clone_item', PARAM_INT); $buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'apply')); } // $buttonarray[] = &$mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', ' ', array(' '), false); } }