} else {
            // Create a new category.
            $newcategory->description = $data->description_editor['text'];
            // Don't overwrite the $newcategory object as it'll be processed by file_postupdate_standard_editor in a moment
            $category = create_course_category($newcategory);
            $newcategory->id = $category->id;
            $categorycontext = $category->context;
            redirect($CFG->wwwroot . '/course/index.php');
            if ($data->batch == 1) {
                $batch = new stdClass();
                $batch->id = '';
                $batch->categoryid = $newcategory->id;
                $batch->startdate = $data->batchstart;
                $batch->enddate = $data->batchend;
                $batchObj = new batch();
                $batchObj->addnewbatch($batch);
            }
        }
        ?>

<?php 
        $newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'coursecat', 'description', 0);
        $DB->update_record('course_categories', $newcategory);
        //$categoryid=$newcategory->id;
        if ($newcategory->batch == 1) {
            echo "batch updated";
            echo "\n{$newcategory->batch}";
            $batchrecords = new stdclass();
            $batchrecords->id = $batchid;
            $batch->categoryid = $newcategory->id;
            $batchrecords->startdate = $data->batchstart;