Пример #1
0
/// first create the form
$editform = new course_edit_form('edit.php', compact('course', 'category'));
// now override defaults if course already exists
if (!empty($course)) {
    $course->enrolpassword = $course->password;
    // we need some other name for password field MDL-9929
    $editform->set_data($course);
}
if ($editform->is_cancelled()) {
    if (empty($course)) {
        redirect($CFG->wwwroot);
    } else {
        redirect($CFG->wwwroot . '/course/view.php?id=' . $course->id);
    }
} else {
    if ($data = $editform->get_data()) {
        $data->password = $data->enrolpassword;
        // we need some other name for password field MDL-9929
        /// process data if submitted
        //preprocess data
        if ($data->enrolstartdisabled) {
            $data->enrolstartdate = 0;
        }
        if ($data->enrolenddisabled) {
            $data->enrolenddate = 0;
        }
        $data->timemodified = time();
        if (empty($course)) {
            if (!($course = create_course($data))) {
                print_error('coursenotcreated');
            }
Пример #2
0
function createCourse($categoryId)
{
    global $Out;
    $course = null;
    $category = null;
    // Must define as the compact function below expects a category variable
    if ($categoryId) {
        // creating new course in this category
        require_login();
        if (!($category = get_record('course_categories', 'id', $categoryId))) {
            error('Category ID was incorrect');
        }
        require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
    } else {
        require_login();
        error('Either course id or category must be specified');
    }
    // We're pretending a form has been submitted
    // Create the form
    $editform = new course_edit_form('edit.php', compact('course', 'category'));
    $editform->_form->_flagSubmitted = true;
    // Set the values for certain elements
    $elements = new object();
    $elements->name = 'SRV ' . date('Ymd H:i');
    $elements->time = time();
    // Create a data object of elements for the form
    $data = createNewCourseData($elements);
    // Set the form with the data object
    $editform->set_data($data);
    //$elements = $editform->_form->_elements;
    //$Out->print_r($elements, '$elements (1) = ', 0, true);
    // Set the submit data as the form checks these values match the form elements
    $submitData = $editform->_form->_submitValues = (array) $data;
    //$Out->print_r($submitData, '$submitData (1) = ', 0, true);
    $data = $editform->get_data();
    // Password fields must match
    $data->password = $data->enrolpassword;
    // we need some other name for password field MDL-9929
    //preprocess data
    if ($data->enrolstartdisabled) {
        $data->enrolstartdate = 0;
    }
    if ($data->enrolenddisabled) {
        $data->enrolenddate = 0;
    }
    $data->timemodified = time();
    // Now create the course from the form
    if (!($course = create_course($data))) {
        print_error('coursenotcreated');
    }
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    // assign default role to creator if not already having permission to manage course assignments
    if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
        role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
    }
    // ensure we can use the course right after creating it
    // this means trigger a reload of accessinfo...
    mark_context_dirty($context->path);
    print_box('course successfully created.');
    return $course;
}
if ($isadding) {
    $title = 'addnewcourse';
}
$PAGE->navbar->add(get_string($title, 'block_iomad_commerce'));
$blockpage = new blockpage($PAGE, $OUTPUT, 'iomad_commerce', 'block', $title);
$blockpage->setup($urlparams);
require_login(null, false);
// Adds to $PAGE, creates $OUTPUT.
/* next line copied from /course/edit.php */
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'noclean' => true);
$mform = new course_edit_form($PAGE->url, $isadding, $shopsettingsid, $course, $priceblocks, $editoroptions);
$mform->set_data($shopsettings);
if ($mform->is_cancelled()) {
    redirect($companylist);
} else {
    if ($data = $mform->get_data()) {
        $data->userid = $USER->id;
        $transaction = $DB->start_delegated_transaction();
        if ($isadding) {
            $shopsettingsid = $DB->insert_record('course_shopsettings', $data);
        } else {
            $data->id = $shopsettingsid;
            $DB->update_record('course_shopsettings', $data);
        }
        if (!isset($data->courseid) && isset($course->id)) {
            $data->courseid = $course->id;
        }
        $DB->delete_records('course_shopblockprice', array('courseid' => $data->courseid));
        foreach ($priceblocks as $priceblock) {
            $priceblock->courseid = $data->courseid;
            $priceblock->currency = $_POST["currency"];
Пример #4
0
}
/// first create the form
$editform = new course_edit_form('edit.php', compact('course', 'category'));
$editform->_form->_flagSubmitted = true;
$elements = new object();
$elements->name = 'SRV ' . date('Ymd H:i');
$Out->print_r($elements->name, '$data (1) = ', 0, true);
$elements->time = time();
$data = createNewCourseData($elements);
$Out->print_r($data, '$data (1) = ', 0, true);
$editform->set_data($data);
$elements = $editform->_form->_elements;
//$Out->print_r($elements, '$elements (1) = ', 0, true);
$submitData = $editform->_form->_submitValues = (array) $data;
//$Out->print_r($submitData, '$submitData (1) = ', 0, true);
$data = $editform->get_data();
//$Out->print_r($data, '$data (2) = ', 0, true);
//exit();
$data->password = $data->enrolpassword;
// we need some other name for password field MDL-9929
/// process data if submitted
//preprocess data
if ($data->enrolstartdisabled) {
    $data->enrolstartdate = 0;
}
if ($data->enrolenddisabled) {
    $data->enrolenddate = 0;
}
$data->timemodified = time();
if (empty($course)) {
    if (!($course = create_course($data))) {