示例#1
0
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    // Check we don't have a duplicate shortname.
    if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
            throw new moodle_exception('shortnametaken', '', '', $data->shortname);
        }
    }
    // Check we don't have a duplicate idnumber.
    if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
            throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
        }
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        $context->update_moved($newparent);
    }
    $fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
    if ($fixcoursesortorder) {
        fix_course_sortorder();
    }
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    // Trigger a course updated event.
    $event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
    $event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
    $event->trigger();
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
 /**
  * Returns all course overview files
  *
  * @return array array of stored_file objects
  */
 public function get_course_overviewfiles()
 {
     global $CFG;
     if (empty($CFG->courseoverviewfileslimit)) {
         return array();
     }
     require_once $CFG->libdir . '/filestorage/file_storage.php';
     require_once $CFG->dirroot . '/course/lib.php';
     $fs = get_file_storage();
     $context = context_course::instance($this->id);
     $files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
     if (count($files)) {
         $overviewfilesoptions = course_overviewfiles_options($this->id);
         $acceptedtypes = $overviewfilesoptions['accepted_types'];
         if ($acceptedtypes !== '*') {
             // Filter only files with allowed extensions.
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
                     unset($files[$key]);
                 }
             }
         }
         if (count($files) > $CFG->courseoverviewfileslimit) {
             // Return no more than $CFG->courseoverviewfileslimit files.
             $files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
         }
     }
     return $files;
 }
示例#3
0
 function definition()
 {
     global $USER, $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id'))));
     $course = $this->_customdata['course'];
     // this contains the data of this form
     $category = $this->_customdata['category'];
     $editoroptions = $this->_customdata['editoroptions'];
     $returnto = $this->_customdata['returnto'];
     $systemcontext = context_system::instance();
     $categorycontext = context_coursecat::instance($category->id);
     if (!empty($course->id)) {
         $coursecontext = context_course::instance($course->id);
         $context = $coursecontext;
     } else {
         $coursecontext = null;
         $context = $categorycontext;
     }
     $courseconfig = get_config('moodlecourse');
     $this->course = $course;
     $this->context = $context;
     /// form definition with new course defaults
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('hidden', 'returnto', null);
     $mform->setType('returnto', PARAM_ALPHANUM);
     $mform->setConstant('returnto', $returnto);
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->addHelpButton('fullname', 'fullnamecourse');
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
         $mform->hardFreeze('fullname');
         $mform->setConstant('fullname', $course->fullname);
     }
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->addHelpButton('shortname', 'shortnamecourse');
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
         $mform->hardFreeze('shortname');
         $mform->setConstant('shortname', $course->shortname);
     }
     // Verify permissions to change course category or keep current.
     if (empty($course->id)) {
         if (has_capability('moodle/course:create', $categorycontext)) {
             $displaylist = coursecat::make_categories_list('moodle/course:create');
             $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
             $mform->addHelpButton('category', 'coursecategory');
             $mform->setDefault('category', $category->id);
         } else {
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $category->id);
         }
     } else {
         if (has_capability('moodle/course:changecategory', $coursecontext)) {
             $displaylist = coursecat::make_categories_list('moodle/course:create');
             if (!isset($displaylist[$course->category])) {
                 //always keep current
                 $displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name();
             }
             $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
             $mform->addHelpButton('category', 'coursecategory');
         } else {
             //keep current
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $course->category);
         }
     }
     $choices = array();
     $choices['0'] = get_string('hide');
     $choices['1'] = get_string('show');
     $mform->addElement('select', 'visible', get_string('visible'), $choices);
     $mform->addHelpButton('visible', 'visible');
     $mform->setDefault('visible', $courseconfig->visible);
     if (!has_capability('moodle/course:visibility', $context)) {
         $mform->hardFreeze('visible');
         if (!empty($course->id)) {
             $mform->setConstant('visible', $course->visible);
         } else {
             $mform->setConstant('visible', $courseconfig->visible);
         }
     }
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->addHelpButton('startdate', 'startdate');
     $mform->setDefault('startdate', time() + 3600 * 24);
     $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100"  size="10"');
     $mform->addHelpButton('idnumber', 'idnumbercourse');
     $mform->setType('idnumber', PARAM_RAW);
     if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
         $mform->setConstants('idnumber', $course->idnumber);
     }
     // Description.
     $mform->addElement('header', 'descriptionhdr', get_string('description'));
     $mform->setExpanded('descriptionhdr');
     $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions);
     $mform->addHelpButton('summary_editor', 'coursesummary');
     $mform->setType('summary_editor', PARAM_RAW);
     $summaryfields = 'summary_editor';
     if ($overviewfilesoptions = course_overviewfiles_options($course)) {
         $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions);
         $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles');
         $summaryfields .= ',overviewfiles_filemanager';
     }
     if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
         // Remove the description header it does not contain anything any more.
         $mform->removeElement('descriptionhdr');
         $mform->hardFreeze($summaryfields);
     }
     // Course format.
     $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin'));
     $courseformats = get_sorted_course_formats(true);
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}");
     }
     if (isset($course->format)) {
         $course->format = course_get_format($course)->get_format();
         // replace with default if not found
         if (!in_array($course->format, $courseformats)) {
             // this format is disabled. Still display it in the dropdown
             $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format));
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->addHelpButton('format', 'format');
     $mform->setDefault('format', $courseconfig->format);
     // Button to update format-specific options on format change (will be hidden by JavaScript).
     $mform->registerNoSubmitButton('updatecourseformat');
     $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));
     // Just a placeholder for the course format options.
     $mform->addElement('hidden', 'addcourseformatoptionshere');
     $mform->setType('addcourseformatoptionshere', PARAM_BOOL);
     // Appearance.
     $mform->addElement('header', 'appearancehdr', get_string('appearance'));
     if (!empty($CFG->allowcoursethemes)) {
         $themeobjects = get_list_of_themes();
         $themes = array();
         $themes[''] = get_string('forceno');
         foreach ($themeobjects as $key => $theme) {
             if (empty($theme->hidefromselector)) {
                 $themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
             }
         }
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_string_manager()->get_list_of_translations();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     $mform->setDefault('lang', $courseconfig->lang);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->addHelpButton('newsitems', 'newsitemsnumber');
     $mform->setDefault('newsitems', $courseconfig->newsitems);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->addHelpButton('showgrades', 'showgrades');
     $mform->setDefault('showgrades', $courseconfig->showgrades);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->addHelpButton('showreports', 'showreports');
     $mform->setDefault('showreports', $courseconfig->showreports);
     // Files and uploads.
     $mform->addElement('header', 'filehdr', get_string('filesanduploads'));
     if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
         if (empty($course->legacyfiles)) {
             //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
             $choices = array('0' => get_string('no'), '2' => get_string('yes'));
         } else {
             $choices = array('1' => get_string('no'), '2' => get_string('yes'));
         }
         $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
         $mform->addHelpButton('legacyfiles', 'courselegacyfiles');
         if (!isset($courseconfig->legacyfiles)) {
             // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses
             $courseconfig->legacyfiles = 0;
         }
         $mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
     }
     // Handle non-existing $course->maxbytes on course creation.
     $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;
     // Let's prepare the maxbytes popup.
     $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->addHelpButton('maxbytes', 'maximumupload');
     $mform->setDefault('maxbytes', $courseconfig->maxbytes);
     // Completion tracking.
     if (completion_info::is_enabled_for_site()) {
         $mform->addElement('header', 'completionhdr', get_string('completion', 'completion'));
         $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion'));
         $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
         $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion');
     } else {
         $mform->addElement('hidden', 'enablecompletion');
         $mform->setType('enablecompletion', PARAM_INT);
         $mform->setDefault('enablecompletion', 0);
     }
     //--------------------------------------------------------------------------------
     enrol_course_edit_form($mform, $course, $context);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'groups', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('groupsnone', 'group');
     $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
     $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
     $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
     $mform->addHelpButton('groupmode', 'groupmode', 'group');
     $mform->setDefault('groupmode', $courseconfig->groupmode);
     $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group'));
     $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
     $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
     //default groupings selector
     $options = array();
     $options[0] = get_string('none');
     $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     //--------------------------------------------------------------------------------
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
     $mform->addHelpButton('rolerenaming', 'rolerenaming');
     if ($roles = get_all_roles()) {
         $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL);
         $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname));
             $mform->setType('role_' . $role->id, PARAM_TEXT);
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     /// finally set the current form data
     //--------------------------------------------------------------------------------
     $this->set_data($course);
 }
示例#4
0
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        context_moved($context, $newparent);
    }
    fix_course_sortorder();
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
    // Trigger events
    events_trigger('course_updated', $course);
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
示例#5
0
文件: edit.php 项目: evltuma/moodle
    if ($categoryid) {
        // Creating new course in this category.
        $course = null;
        require_login();
        $category = $DB->get_record('course_categories', array('id' => $categoryid), '*', MUST_EXIST);
        $catcontext = context_coursecat::instance($category->id);
        require_capability('moodle/course:create', $catcontext);
        $PAGE->set_context($catcontext);
    } else {
        require_login();
        print_error('needcoursecategroyid');
    }
}
// Prepare course and the editor.
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'noclean' => true);
$overviewfilesoptions = course_overviewfiles_options($course);
if (!empty($course)) {
    // Add context for editor.
    $editoroptions['context'] = $coursecontext;
    $editoroptions['subdirs'] = file_area_contains_subdirs($coursecontext, 'course', 'summary', 0);
    $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course', 'summary', 0);
    if ($overviewfilesoptions) {
        file_prepare_standard_filemanager($course, 'overviewfiles', $overviewfilesoptions, $coursecontext, 'course', 'overviewfiles', 0);
    }
    // Inject current aliases.
    $aliases = $DB->get_records('role_names', array('contextid' => $coursecontext->id));
    foreach ($aliases as $alias) {
        $course->{'role_' . $alias->roleid} = $alias->name;
    }
    // Populate course tags.
    $course->tags = core_tag_tag::get_item_tags_array('core', 'course', $course->id);
示例#6
0
    /**
     * Form definition.
     */
    function definition() {
        global $CFG, $PAGE,$USER,$DB;

        $mform    = $this->_form;
        $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser',
                array(array('formid' => $mform->getAttribute('id'))));

        $course        = $this->_customdata['course']; // this contains the data of this form
        //print_object($course);
        $category      = $this->_customdata['category'];
        $editoroptions = $this->_customdata['editoroptions'];
        $returnto = $this->_customdata['returnto'];

        $systemcontext   = context_system::instance();
        $categorycontext = context_coursecat::instance($category->id);

        if (!empty($course->id)) {
            $coursecontext = context_course::instance($course->id);
            $context = $coursecontext;
        } else {
            $coursecontext = null;
            $context = $categorycontext;
        }

        $courseconfig = get_config('moodlecourse');

        $this->course  = $course;
        $this->context = $context;

        // Form definition with new course defaults.
        $mform->addElement('header','general', get_string('general', 'form'));

        $mform->addElement('hidden', 'returnto', null);
        $mform->setType('returnto', PARAM_ALPHANUM);
        $mform->setConstant('returnto', $returnto);
         /*
         * EA_NK23-02-2015
         * Added cost center field
         */
       
        $is_manager = $DB->record_exists_sql("SELECT ra.userid
                                                FROM {role_assignments} as ra
                                                JOIN {role} as r ON ra.roleid=r.id
                                               WHERE r.archetype='manager' AND ra.userid={$USER->id}");
        if(is_siteadmin()) {
        /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/    
           $admincostcenters=user_wise_department();
        //print_object($admincostcenters);
            $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters);        
       
      /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/    
        }elseif(!is_siteadmin()){
           $admincostcenters=user_wise_department();
          
           $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters);   
        
        }
            //$costcenter = $DB->get_records_sql_menu("SELECT cc.id,cc.fullname FROM mdl_local_userdata ud JOIN mdl_local_costcenter cc ON ud.costcenterid=cc.id WHERE ud.userid={$USER->id}");
            //$mform->addElement('hidden','costcenter');
            //$mform->setDefault('costcenter',$costcenter->id);
            //$mform->addElement('static', 'costcenterid', get_string('pluginname', 'local_costcenter'), $costcenter->fullname);
        
        $mform->setType('costcenter', PARAM_RAW);
        
        /* EA_NK23-02-2015 Customization ends here */
        $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
        $mform->addHelpButton('fullname', 'fullnamecourse');
        $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
        $mform->setType('fullname', PARAM_TEXT);
        if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
            $mform->hardFreeze('fullname');
            $mform->setConstant('fullname', $course->fullname);
        }

        $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
        $mform->addHelpButton('shortname', 'shortnamecourse');
        $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
        $mform->setType('shortname', PARAM_TEXT);
        if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
            $mform->hardFreeze('shortname');
            $mform->setConstant('shortname', $course->shortname);
        }

        // Verify permissions to change course category or keep current.
        if (empty($course->id)) {
            if (has_capability('moodle/course:create', $categorycontext)) {
                $displaylist = coursecat::make_categories_list('moodle/course:create');
                
            /*======================Started By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/   
                if(is_siteadmin()){
                    $admincoursecategory=department_category_course();
                    $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory);
            
             /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/        
                }else{
    
            /*======================Ended By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/   
               $admincoursecategory=department_category_course();
                $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory);
            
            
                 $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id));
                    if($userdepartment_exist==1){
                       $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id));
                       if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){
                            $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager');
                            $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options);
                            //$mform->setConstant('category', $category->id);
                            //$mform->setDefault('assignedto', $course->assignedto);
                       }
                    }
            /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/    
                
                }
                $mform->addHelpButton('category', 'coursecategory');
                $mform->setDefault('category', $category->id);
                
                    $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100"  size="10"');
                   if(!empty($course->assignedto)){
                      $mform->setDefault('duration', $course->duration);
                   }else{
                      $mform->setDefault('duration','0');
                   }
                  
                    $mform->setType('duration', PARAM_RAW);
                    $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#');
            } else {
                $mform->addElement('hidden', 'category', null);
                $mform->setType('category', PARAM_INT);
                $mform->setConstant('category', $category->id);
            }
        } else {
            if (has_capability('moodle/course:changecategory', $coursecontext)) {
                 $admincoursecategory=department_category_course();
                $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory);
            } else {
                //keep current
                $mform->addElement('hidden', 'category', null);
                $mform->setType('category', PARAM_INT);
                $mform->setConstant('category', $course->category);
            }
                    $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id));
                    if($userdepartment_exist==1){
                       $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id));
                       if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){
                            $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager');
                            $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options);
                            //$mform->setConstant('category', $category->id);
                            //$mform->setDefault('assignedto', $course->assignedto);
                       }
                    }
                    /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/    
                    $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100"  size="10"');
                   if(!empty($course->assignedto)){
                      $mform->setDefault('duration', $course->duration);
                   }else{
                      $mform->setDefault('duration','0');
                   }
                  
                    $mform->setType('duration', PARAM_RAW);
                    $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#');
        }

        $choices = array();
        $choices['0'] = get_string('hide');
        $choices['1'] = get_string('show');
        $mform->addElement('select', 'visible', get_string('visible'), $choices);
        $mform->addHelpButton('visible', 'visible');
        $mform->setDefault('visible', $courseconfig->visible);
        if (!empty($course->id)) {
            if (!has_capability('moodle/course:visibility', $coursecontext)) {
                $mform->hardFreeze('visible');
                $mform->setConstant('visible', $course->visible);
            }
        } else {
            if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) {
                $mform->hardFreeze('visible');
                $mform->setConstant('visible', $courseconfig->visible);
            }
        }

        $mform->addElement('date_selector', 'startdate', get_string('startdate'));
        $mform->addHelpButton('startdate', 'startdate');
        $mform->setDefault('startdate', time() + 3600 * 24);

        $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
        $mform->addHelpButton('idnumber', 'idnumbercourse');
        $mform->setType('idnumber', PARAM_RAW);
        if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
            $mform->hardFreeze('idnumber');
            $mform->setConstants('idnumber', $course->idnumber);
        }

        // Description.
        $mform->addElement('header', 'descriptionhdr', get_string('description'));
        $mform->setExpanded('descriptionhdr');

        $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions);
        $mform->addHelpButton('summary_editor', 'coursesummary');
        $mform->setType('summary_editor', PARAM_RAW);
        $summaryfields = 'summary_editor';

        if ($overviewfilesoptions = course_overviewfiles_options($course)) {
            $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions);
            $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles');
            $summaryfields .= ',overviewfiles_filemanager';
        }

        if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
            // Remove the description header it does not contain anything any more.
            $mform->removeElement('descriptionhdr');
            $mform->hardFreeze($summaryfields);
        }

        // Course format.
        $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin'));

        $courseformats = get_sorted_course_formats(true);
        $formcourseformats = array();
        foreach ($courseformats as $courseformat) {
            $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat");
        }
        if (isset($course->format)) {
            $course->format = course_get_format($course)->get_format(); // replace with default if not found
            if (!in_array($course->format, $courseformats)) {
                // this format is disabled. Still display it in the dropdown
                $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle',
                        get_string('pluginname', 'format_'.$course->format));
            }
        }

        $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
        $mform->addHelpButton('format', 'format');
        $mform->setDefault('format', $courseconfig->format);

        // Button to update format-specific options on format change (will be hidden by JavaScript).
        $mform->registerNoSubmitButton('updatecourseformat');
        $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));

        // Just a placeholder for the course format options.
        $mform->addElement('hidden', 'addcourseformatoptionshere');
        $mform->setType('addcourseformatoptionshere', PARAM_BOOL);

        // Appearance.
        $mform->addElement('header', 'appearancehdr', get_string('appearance'));

        if (!empty($CFG->allowcoursethemes)) {
            $themeobjects = get_list_of_themes();
            $themes=array();
            $themes[''] = get_string('forceno');
            foreach ($themeobjects as $key=>$theme) {
                if (empty($theme->hidefromselector)) {
                    $themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
                }
            }
            $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
        }

        $languages=array();
        $languages[''] = get_string('forceno');
        $languages += get_string_manager()->get_list_of_translations();
        $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
        $mform->setDefault('lang', $courseconfig->lang);

        // Multi-Calendar Support - see MDL-18375.
        $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
        // We do not want to show this option unless there is more than one calendar type to display.
        if (count($calendartypes) > 1) {
            $calendars = array();
            $calendars[''] = get_string('forceno');
            $calendars += $calendartypes;
            $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars);
        }

        $options = range(0, 10);
        $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
        $mform->addHelpButton('newsitems', 'newsitemsnumber');
        $mform->setDefault('newsitems', $courseconfig->newsitems);

        $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
        $mform->addHelpButton('showgrades', 'showgrades');
        $mform->setDefault('showgrades', $courseconfig->showgrades);

        $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
        $mform->addHelpButton('showreports', 'showreports');
        $mform->setDefault('showreports', $courseconfig->showreports);

        // Files and uploads.
        $mform->addElement('header', 'filehdr', get_string('filesanduploads'));

        if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
            if (empty($course->legacyfiles)) {
                //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
                $choices = array('0'=>get_string('no'), '2'=>get_string('yes'));
            } else {
                $choices = array('1'=>get_string('no'), '2'=>get_string('yes'));
            }
            $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
            $mform->addHelpButton('legacyfiles', 'courselegacyfiles');
            if (!isset($courseconfig->legacyfiles)) {
                // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses
                $courseconfig->legacyfiles = 0;
            }
            $mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
        }

        // Handle non-existing $course->maxbytes on course creation.
        $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;

        // Let's prepare the maxbytes popup.
        $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
        $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
        $mform->addHelpButton('maxbytes', 'maximumupload');
        $mform->setDefault('maxbytes', $courseconfig->maxbytes);

        // Completion tracking.
        if (completion_info::is_enabled_for_site()) {
            $mform->addElement('header', 'completionhdr', get_string('completion', 'completion'));
            $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion'));
            $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
            $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion');
        } else {
            $mform->addElement('hidden', 'enablecompletion');
            $mform->setType('enablecompletion', PARAM_INT);
            $mform->setDefault('enablecompletion', 0);
        }

        enrol_course_edit_form($mform, $course, $context);

        $mform->addElement('header','groups', get_string('groupsettingsheader', 'group'));

        $choices = array();
        $choices[NOGROUPS] = get_string('groupsnone', 'group');
        $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
        $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
        $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
        $mform->addHelpButton('groupmode', 'groupmode', 'group');
        $mform->setDefault('groupmode', $courseconfig->groupmode);

        $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group'));
        $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
        $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);

        //default groupings selector
        $options = array();
        $options[0] = get_string('none');
        $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);

        // Customizable role names in this course.
        $mform->addElement('header','rolerenaming', get_string('rolerenaming'));
        $mform->addHelpButton('rolerenaming', 'rolerenaming');

        if ($roles = get_all_roles()) {
            $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL);
            $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
            foreach ($roles as $role) {
                $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->localname));
                $mform->setType('role_'.$role->id, PARAM_TEXT);
            }
        }

        $this->add_action_buttons();

        $mform->addElement('hidden', 'id', null);
        $mform->setType('id', PARAM_INT);

        // Finally set the current form data
        $this->set_data($course);
    }
<?php

global $CFG, $COURSE;
if (empty($CFG->courseoverviewfileslimit)) {
    return array();
}
require_once $CFG->libdir . '/filestorage/file_storage.php';
require_once $CFG->dirroot . '/course/lib.php';
$fs = get_file_storage();
$context = context_course::instance($COURSE->id);
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
if (count($files)) {
    $overviewfilesoptions = course_overviewfiles_options($COURSE->id);
    $acceptedtypes = $overviewfilesoptions['accepted_types'];
    if ($acceptedtypes !== '*') {
        // Filter only files with allowed extensions.
        require_once $CFG->libdir . '/filelib.php';
        foreach ($files as $key => $file) {
            if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
                unset($files[$key]);
            }
        }
    }
    if (count($files) > $CFG->courseoverviewfileslimit) {
        // Return no more than $CFG->courseoverviewfileslimit files.
        $files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
    }
}
// Display course overview files.
$courseimage = '';
foreach ($files as $file) {