function definition() { global $CFG; $mform =& $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('date_time_selector', 'scheduledtime', get_string('scheduledtime', 'podcaster')); $mform->addElement('text', 'title', get_string('itemtitle', 'podcaster'), array('size' => '48')); $mform->setType('title', PARAM_TEXT); $mform->addRule('title', null, 'required', null, 'client'); $mform->addElement('htmleditor', 'description', get_string('itemdescription', 'podcaster')); $mform->setType('description', PARAM_RAW); $mform->addRule('description', get_string('required'), 'required', null, 'client'); $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton'); $mform->addElement('format', 'introformat', get_string('format')); $format = $this->item->channelObj->format; $xmlformat =& podcaster_format::create_format($format); $xmlformat->define_itemform($mform, $this->item); if ($CFG->podcaster_copyright == 'user') { $mform->addElement('header', 'license_header', get_string('license', 'podcaster')); $mform->addElement('textarea', 'copyright', get_string('copyright', 'podcaster'), array('rows' => '5', 'cols' => '40')); } else { $license = podcaster_license::create_license($this->item->channelObj->license, $this->item->channelObj->repository); if ($license) { $mform->addElement('header', 'license_header', get_string('license', 'podcaster')); $mform->addElement('static', 'license_name', podcaster_util::get_string('license_' . $license->name . '_title')); $mform->addElement('static', 'license_desc', '', podcaster_util::get_string('license_' . $license->name . '_desc')); if ($license->confirm) { $mform->addElement('checkbox', 'confirm_license', get_string('confirm_license', 'podcaster')); $mform->addRule('confirm_license', get_string('must_confirm', 'podcaster'), 'required', null, 'client'); } } } $mform->addElement('hidden', 'cm', $this->coursemodule->id); $mform->addElement('hidden', 'channel', $this->item->channelObj->id); $mform->addElement('hidden', 'id', $this->item->id); $mform->setType('item', PARAM_TEXT); $this->add_action_buttons(); }
/** * This function prints out a number of upload form elements. * * @param int $numfiles The number of elements required (optional, defaults to 1) * @param array $names Array of element names to use (optional, defaults to FILE_n) * @param array $descriptions Array of strings to be printed out before each file bit. * @param boolean $uselabels -Whether to output text fields for file descriptions or not (optional, defaults to false) * @param array $labelnames Array of element names to use for labels (optional, defaults to LABEL_n) * @param int $coursebytes $coursebytes and $maxbytes are used to calculate upload max size ( using {@link get_max_upload_file_size}) * @param int $modbytes $coursebytes and $maxbytes are used to calculate upload max size ( using {@link get_max_upload_file_size}) * @param boolean $return -Whether to return the string (defaults to false - string is echoed) * @return string Form returned as string if $return is true */ function upload_print_form_fragment($numfiles = 1, $names = null, $descriptions = null, $uselabels = false, $labelnames = null, $coursebytes = 0, $modbytes = 0, $return = false) { global $CFG; # HU, CS Repository plugin support global $scheme, $repository; include_once $CFG->dirroot . '/mod/podcaster/locallib.php'; $maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $modbytes); $str = '<input type="hidden" name="MAX_FILE_SIZE" value="' . $maxbytes . '" />' . "\n"; # HU, CS Repository plugin support $str .= '<input type="hidden" name="repository" value="' . $scheme . '" />' . "\n"; $jsdummy = true; if ($CFG->podcaster_copyright != 'user' && ($license = podcaster_license::create_license(NULL, $repository->id)) && $license) { $str .= '<div id="mod-podcaster-upload"><div class="license">' . podcaster_util::get_string('license_' . $license->name . '_desc'); if ($license->confirm) { $jsdummy = false; $str .= '<script type="text/javascript"> function validate_confirm_license (e) { if (e && e.checked) { document.forms[0].elements.save.disabled = false; document.getElementById (\'confirm_license_span\').style.border = 0; } else { document.forms[0].elements.save.disabled = true; if (e) document.getElementById (\'confirm_license_span\').style.border = \'1px solid red;\'; } } </script>'; $str .= '<br/><br/><div style="display:inline;padding:4px;margin-left:-4px;" id="confirm_license_span">' . get_string('confirm_license', 'podcaster') . ' '; $str .= '<input name="confirm_license" type="checkbox" value="1" onblur="validate_confirm_license(this)" onchange="validate_confirm_license(this)" /></div><br/><br/>'; } $str .= '</div></div>'; } if ($jsdummy) { $str .= '<script type="text/javascript"> function validate_confirm_license (e) { return true; } </script>'; } for ($i = 0; $i < $numfiles; $i++) { if (is_array($descriptions) && !empty($descriptions[$i])) { $str .= '<strong>' . $descriptions[$i] . '</strong><br />'; } $name = is_array($names) && !empty($names[$i]) ? $names[$i] : 'FILE_' . $i; $str .= '<input type="file" size="50" name="' . $name . '" alt="' . $name . '" /><br />' . "\n"; if ($uselabels) { $lname = is_array($labelnames) && !empty($labelnames[$i]) ? $labelnames[$i] : 'LABEL_' . $i; $str .= get_string('uploadlabel') . ' <input type="text" size="50" name="' . $lname . '" alt="' . $lname . '" /><br /><br />' . "\n"; } } if ($return) { return $str; } else { echo $str; } }
function definition() { global $CFG; $mform =& $this->_form; // do some tests to determine if we have to choose a // podcast format, repository and / or license first if (isset($this->initial_data) && $this->initial_data->ismeta) { $formats = explode(',', $CFG->podcaster_metaformats); } else { $formats = explode(',', $CFG->podcaster_formats); } $repositories = get_records('podcaster_repository', 'enabled', '1'); $licenses = get_records('podcaster_license'); $format = isset($this->initial_data) ? $this->initial_data->format : ''; $repository = isset($this->initial_data) ? $this->initial_data->repository : 0; $license = isset($this->initial_data) ? $this->initial_data->license : 0; if ($format == '') { $format = optional_param('format', '', PARAM_TEXT); if ($format == '') { $typeOptions =& $this->parseTypeOptions(); if (array_key_exists('format', $typeOptions)) { $format = $typeOptions['format']; } } if (count($formats) == 1) { $format = $formats[0]; } } if ($repository == 0) { $repository = optional_param('repository', 0, PARAM_INT); if ($repository == 0) { $typeOptions =& $this->parseTypeOptions(); if (array_key_exists('repository', $typeOptions)) { $repository = $typeOptions['repository']; } } // there should be at least one if (count($repositories) == 1) { list($repository, ) = each($repositories); } } if ($license == 0) { $license = optional_param('license', 0, PARAM_INT); if ($license == 0) { $typeOptions =& $this->parseTypeOptions(); if (array_key_exists('license', $typeOptions)) { $license = $typeOptions['license']; } } if (count($licenses) == 1) { list($license, ) = each($licenses); } } if (!isset($this->initial_data)) { $this->initial_data = new object(); $this->initial_data->format = $format; $this->initial_data->repository = $repository; $this->initial_data->license = $license; } else { $updobj = new object(); $updobj->id = $this->initial_data->id; $dofix = false; if ($repository != 0 && (!isset($this->initial_data->repository) || $this->initial_data->repository == 0)) { $this->initial_data->repository = $repository; $updobj->repository = $repository; $dofix = true; } if ($format != '' && $format != '' && (!isset($this->initial_data->format) || $this->initial_data->format == '')) { $this->initial_data->format = $format; $updobj->format = $format; $dofix = true; } if ($license && (!isset($this->initial_data->license) || $this->initial_data->license == 0)) { $this->initial_data->license = $license; $updobj->license = $license; $dofix = true; } update_record('podcaster', $updobj); } // 1st step: repository, format or license cannot be determined automatically if (!$repository || !$format || !$license && $CFG->podcaster_copyright == 'menu') { $mform->addElement('header', 'firststep', get_string('create_step1', 'podcaster')); if (is_array($formats) && count($formats) > 1) { $options = array(); $mform->addElement('static', 'repository_hint', get_string('format_hint', 'podcaster')); for ($i = 0, $c = count($formats); $i < $c; ++$i) { $options[$formats[$i]] = podcaster_util::get_string('format_' . $formats[$i] . '_title'); } $mform->addElement('select', 'format', get_string('format', 'podcaster'), $options); } elseif ($format) { $mform->addElement('hidden', 'format', $format); } else { error('Module is misconfigured: no formats available. Please check module configuration.'); } if (is_array($repositories) && count($repositories) > 1) { $mform->addElement('static', 'repository_hint', get_string('repository_hint', 'podcaster')); $options = array(); foreach ($repositories as $r) { $options[$r->id] = podcaster_util::get_string('repository_' . $r->name . '_title'); } $mform->addElement('select', 'repository', get_string('repository', 'podcaster'), $options); } elseif ($repository) { $mform->addElement('hidden', 'repository', $repository); } else { error('Module is misconfigured: no repositories available. Please check module configuration.'); } if (is_array($licenses) && count($licenses) > 1 && $CFG->podcaster_copyright == 'menu') { $mform->addElement('static', 'license_hint', get_string('license_hint', 'podcaster')); $options = array(); foreach ($licenses as $l) { $options[$l->id] = podcaster_util::get_string('license_' . $l->name . '_title'); } $mform->addElement('select', 'license', get_string('license', 'podcaster'), $options); } elseif ($license && $CFG->podcaster_copyright == 'menu') { $mform->addElement('hidden', 'license', $licenses); } elseif ($CFG->podcaster_copyright == 'menu') { error('Module is misconfigured: no licenses available. Please check module configuration.'); } // add standard elements, common to all modules $this->standard_hidden_coursemodule_elements(); $this->add_action_buttons(true); $mform->removeElement('submitbutton2'); $mform->addElement('hidden', 'reloadform', 'true'); } else { // just submitted 1st step? if (optional_param('reloadform', '', PARAM_TEXT) == 'true') { $querystr = ''; $add = optional_param('add', 0, PARAM_TEXT); $update = optional_param('update', 0, PARAM_INT); if ($update != 0) { $querystr = '?update=' . $update; } else { $querystr = '?add=' . $add; } redirect($CFG->wwwroot . '/course/modedit.php' . $querystr . '&course=' . required_param('course', PARAM_INT) . '§ion=' . required_param('section', PARAM_INT) . '&format=' . $format . '&repository=' . $repository . '&license=' . $license . '&sesskey=' . required_param('sesskey', PARAM_TEXT)); } // show standard edit form $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('channelname', 'podcaster'), array('size' => '48')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('htmleditor', 'intro', get_string('channeldescription', 'podcaster')); $mform->setType('intro', PARAM_RAW); $mform->addRule('intro', get_string('required'), 'required', null, 'client'); $mform->setHelpButton('intro', array('writing', 'richtext'), false, 'editorhelpbutton'); $mform->addElement('format', 'introformat', get_string('format')); // include format specific elements $xmlformat =& podcaster_format::create_format($format); $xmlformat->define_channelform($mform, $this->initial_data); $mform->addElement('hidden', 'format', $format); $mform->setType('format', PARAM_TEXT); $mform->addElement('hidden', 'repository', $repository); $mform->setType('repository', PARAM_INT); $mform->addElement('hidden', 'license', $license); $mform->setType('license', PARAM_INT); // add standard elements, common to all modules $this->standard_coursemodule_elements(); if ($CFG->podcaster_copyright == 'user') { $mform->addElement('header', 'license_header', get_string('license', 'podcaster')); $mform->addElement('textarea', 'copyright', get_string('copyright', 'podcaster'), array('rows' => '5', 'cols' => '40')); } else { $license = podcaster_license::create_license($license, $repository); if ($license) { $mform->addElement('header', 'license_header', podcaster_util::get_string('license_' . $license->name . '_title')); // if (!isset($this->initial_data->copyright)) { $copyright = podcaster_util::get_string('license_' . $license->name . '_desc'); } else { $copyright = $this->initial_data->copyright; } $mform->addElement('static', 'license_desc', '', $copyright); $mform->addElement('hidden', 'copyright', $copyright); if ($license->confirm) { $mform->addElement('checkbox', 'confirm_license', get_string('confirm_license', 'podcaster')); $mform->addRule('confirm_license', get_string('must_confirm', 'podcaster'), 'required', null, 'client'); } } } // add standard buttons, common to all modules $this->add_action_buttons(false); } }