Index: temp_moodle_dev/moodle/course/modedit-lams.php =================================================================== diff -u --- temp_moodle_dev/moodle/course/modedit-lams.php (revision 0) +++ temp_moodle_dev/moodle/course/modedit-lams.php (revision 49d09eadd0817437a212bead2eb82e6dce4d5a6d) @@ -0,0 +1,463 @@ +libdir.'/gradelib.php'); + + require_login(); + + $add = optional_param('add', 0, PARAM_ALPHA); + $update = optional_param('update', 0, PARAM_INT); + $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true + $type = optional_param('type', '', PARAM_ALPHANUM); + $toolcontentid = required_param('toolContentID', PARAM_INT); + $lamsupdateurl = required_param('lamsUpdateURL', PARAM_TEXT); + + if (!empty($add)) { + $section = required_param('section', PARAM_INT); + $course = required_param('course', PARAM_INT); + + if (! $course = get_record("course", "id", $course)) { + error("This course doesn't exist"); + } + + require_login($course); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + require_capability('moodle/course:manageactivities', $context); + + if (! $module = get_record("modules", "name", $add)) { + error("This module type doesn't exist"); + } + + $cw = get_course_section($section, $course->id); + + if (!course_allowed_module($course, $module->id)) { + error("This module has been disabled for this particular course"); + } + + $cm = null; + + $form->section = $section; // The section number itself - relative!!! (section column in course_sections) + $form->visible = $cw->visible; + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->groupmode = $course->groupmode; + $form->groupingid = $course->defaultgroupingid; + $form->groupmembersonly = 0; + $form->instance = ''; + $form->coursemodule = ''; + $form->add = $add; + $form->return = 0; //must be false if this is an add, go back to course view on cancel + + if (!empty($type)) { + $form->type = $type; + } + + $sectionname = get_section_name($course->format); + $fullmodulename = get_string("modulename", $module->name); + + if ($form->section && $course->format != 'site') { + $heading->what = $fullmodulename; + $heading->to = "$sectionname $form->section"; + $pageheading = get_string("addinganewto", "moodle", $heading); + } else { + $pageheading = get_string("addinganew", "moodle", $fullmodulename); + } + + $CFG->pagepath = 'mod/'.$module->name; + if (!empty($type)) { + $CFG->pagepath .= '/'.$type; + } else { + $CFG->pagepath .= '/mod'; + } + + $navlinksinstancename = ''; + } else if (!empty($update)) { + if (! $cm = get_record("course_modules", "id", $update)) { + error("This course module doesn't exist"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("This course doesn't exist"); + } + + require_login($course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:manageactivities', $context); + + if (! $module = get_record("modules", "id", $cm->module)) { + error("This module doesn't exist"); + } + + if (! $form = get_record($module->name, "id", $cm->instance)) { + error("The required instance of this module doesn't exist"); + } + + if (! $cw = get_record("course_sections", "id", $cm->section)) { + error("This course section doesn't exist"); + } + + $form->coursemodule = $cm->id; + $form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) + $form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides + $form->cmidnumber = $cm->idnumber; // The cm IDnumber + $form->groupmode = groups_get_activity_groupmode($cm); // locked later if forced + $form->groupingid = $cm->groupingid; + $form->groupmembersonly = $cm->groupmembersonly; + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->instance = $cm->instance; + $form->return = $return; + $form->update = $update; + + + if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename, + 'iteminstance'=>$form->instance, 'courseid'=>$COURSE->id))) { + // add existing outcomes + foreach ($items as $item) { + if (!empty($item->outcomeid)) { + $form->{'outcome_'.$item->outcomeid} = 1; + } + } + + // set category if present + $gradecat = false; + foreach ($items as $item) { + if ($gradecat === false) { + $gradecat = $item->categoryid; + continue; + } + if ($gradecat != $item->categoryid) { + //mixed categories + $gradecat = false; + break; + } + } + if ($gradecat !== false) { + // do not set if mixed categories present + $form->gradecat = $gradecat; + } + } + + $sectionname = get_section_name($course->format); + $fullmodulename = get_string("modulename", $module->name); + + if ($form->section && $course->format != 'site') { + $heading->what = $fullmodulename; + $heading->in = "$sectionname $cw->section"; + $pageheading = get_string("updatingain", "moodle", $heading); + } else { + $pageheading = get_string("updatinga", "moodle", $fullmodulename); + } + + $navlinksinstancename = array('name' => format_string($form->name,true), 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", 'type' => 'activityinstance'); + + $CFG->pagepath = 'mod/'.$module->name; + if (!empty($type)) { + $CFG->pagepath .= '/'.$type; + } else { + $CFG->pagepath .= '/mod'; + } + } else { + error('Invalid operation.'); + } + + $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form_lams.php"; + if (file_exists($modmoodleform)) { + require_once($modmoodleform); + + } else { + error('No formslib form description file found for this activity.'); + } + + $modlib = "$CFG->dirroot/mod/$module->name/lib.php"; + if (file_exists($modlib)) { + include_once($modlib); + } else { + error("This module is missing important code! ($modlib)"); + } + + $mformclassname = 'mod_'.$module->name.'_mod_form'; + $mform =& new $mformclassname($form->instance, $cw->section, $cm); + $mform->set_data($form); + $mform->_form->addElement('hidden', 'toolContentID', $toolcontentid); + $mform->_form->setType('toolContentID', PARAM_INT); + $mform->_form->_attributes['action'] = 'modedit-lams.php'; + $mform->_form->addElement('hidden', 'lamsUpdateURL', $lamsupdateurl); + $mform->_form->setType('lamsUpdateURL', PARAM_TEXT); + + + if ($mform->is_cancelled()) { + if ($return && !empty($cm->id)){ + redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); + } else { + redirect("view.php?id=$course->id#section-".$cw->section); + } + } else if ($fromform = $mform->get_data()) { + if (empty($fromform->coursemodule)) { //add + $cm = null; + if (! $course = get_record("course", "id", $fromform->course)) { + error("This course doesn't exist"); + } + $fromform->instance = ''; + $fromform->coursemodule = ''; + } else { //update + if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) { + error("This course module doesn't exist"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("This course doesn't exist"); + } + $fromform->instance = $cm->instance; + $fromform->coursemodule = $cm->id; + } + + $fromform->is_lams = 1; + + require_login($course->id); // needed to setup proper $COURSE + + if (!empty($fromform->coursemodule)) { + $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); + } else { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + } + require_capability('moodle/course:manageactivities', $context); + + $fromform->course = $course->id; + $fromform->modulename = clean_param($fromform->modulename, PARAM_SAFEDIR); // For safety + + $addinstancefunction = $fromform->modulename."_add_instance"; + $updateinstancefunction = $fromform->modulename."_update_instance"; + + if (!isset($fromform->groupingid)) { + $fromform->groupingid = 0; + } + + if (!isset($fromform->groupmembersonly)) { + $fromform->groupmembersonly = 0; + } + + if (!isset($fromform->name)) { //label + $fromform->name = $fromform->modulename; + } + + if (!empty($fromform->update)) { + + if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { + $fromform->groupmode = $cm->groupmode; // keep original + } + + $returnfromfunc = $updateinstancefunction($fromform); + if (!$returnfromfunc) { + error("Could not update the $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($returnfromfunc)) { + error($returnfromfunc, "view.php?id=$course->id"); + } + + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode); + set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid); + set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly); + + if (isset($fromform->cmidnumber)) { //label + // set cm idnumber + set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); + } + + add_to_log($course->id, "course", "update mod", + "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", + "$fromform->modulename $fromform->instance"); + add_to_log($course->id, $fromform->modulename, "update", + "view.php?id=$fromform->coursemodule", + "$fromform->instance", $fromform->coursemodule); + + } else if (!empty($fromform->add)){ + + if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { + $fromform->groupmode = 0; // do not set groupmode + } + + if (!course_allowed_module($course,$fromform->modulename)) { + error("This module ($fromform->modulename) has been disabled for this particular course"); + } + + $returnfromfunc = $addinstancefunction($fromform); + if (!$returnfromfunc) { + error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($returnfromfunc)) { + error($returnfromfunc, "view.php?id=$course->id"); + } + + $fromform->instance = $returnfromfunc; + + // course_modules and course_sections each contain a reference + // to each other, so we have to update one of them twice. + + if (! $fromform->coursemodule = add_course_module($fromform) ) { + error("Could not add a new course module"); + } + if (! $sectionid = add_mod_to_section($fromform) ) { + error("Could not add the new course module to that section"); + } + + if (! set_field("course_modules", "section", $sectionid, "id", $fromform->coursemodule)) { + error("Could not update the course module with the correct section"); + } + + // make sure visibility is set correctly (in particular in calendar) + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + + if (isset($fromform->cmidnumber)) { //label + // set cm idnumber + set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); + } + + add_to_log($course->id, "course", "add mod", + "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", + "$fromform->modulename $fromform->instance"); + add_to_log($course->id, $fromform->modulename, "add", + "view.php?id=$fromform->coursemodule", + "$fromform->instance", $fromform->coursemodule); + } else { + error("Data submitted is invalid."); + } + + // sync idnumber with grade_item + if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, + 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) { + if ($grade_item->idnumber != $fromform->cmidnumber) { + $grade_item->idnumber = $fromform->cmidnumber; + $grade_item->update(); + } + } + + $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, + 'iteminstance'=>$fromform->instance, 'courseid'=>$COURSE->id)); + + // create parent category if requested and move to correct parent category + if ($items and isset($fromform->gradecat)) { + if ($fromform->gradecat == -1) { + $grade_category = new grade_category(); + $grade_category->courseid = $COURSE->id; + $grade_category->fullname = stripslashes($fromform->name); + $grade_category->insert(); + if ($grade_item) { + $parent = $grade_item->get_parent_category(); + $grade_category->set_parent($parent->id); + } + $fromform->gradecat = $grade_category->id; + } + foreach ($items as $itemid=>$unused) { + $items[$itemid]->set_parent($fromform->gradecat); + if ($itemid == $grade_item->id) { + // use updated grade_item + $grade_item = $items[$itemid]; + } + } + } + + // add outcomes if requested + if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { + $grade_items = array(); + + // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes + $max_itemnumber = 999; + if ($items) { + foreach($items as $item) { + if ($item->itemnumber > $max_itemnumber) { + $max_itemnumber = $item->itemnumber; + } + } + } + + foreach($outcomes as $outcome) { + $elname = 'outcome_'.$outcome->id; + + if (array_key_exists($elname, $fromform) and $fromform->$elname) { + // so we have a request for new outcome grade item? + if ($items) { + foreach($items as $item) { + if ($item->outcomeid == $outcome->id) { + //outcome aready exists + continue 2; + } + } + } + + $max_itemnumber++; + + $outcome_item = new grade_item(); + $outcome_item->courseid = $COURSE->id; + $outcome_item->itemtype = 'mod'; + $outcome_item->itemmodule = $fromform->modulename; + $outcome_item->iteminstance = $fromform->instance; + $outcome_item->itemnumber = $max_itemnumber; + $outcome_item->itemname = $outcome->fullname; + $outcome_item->outcomeid = $outcome->id; + $outcome_item->gradetype = GRADE_TYPE_SCALE; + $outcome_item->scaleid = $outcome->scaleid; + $outcome_item->insert(); + + // move the new outcome into correct category and fix sortorder if needed + if ($grade_item) { + $outcome_item->set_parent($grade_item->categoryid); + $outcome_item->move_after_sortorder($grade_item->sortorder); + + } else if (isset($fromform->gradecat)) { + $outcome_item->set_parent($fromform->gradecat); + } + } + } + } + + rebuild_course_cache($course->id); + grade_regrade_final_grades($course->id); + + redirect("$lamsupdateurl?dispatch=updateContent&toolContentID=$toolcontentID&extToolContentID=$returnfromfunc"); + exit; + + } else { + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + } else { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + } + require_capability('moodle/course:manageactivities', $context); + + $streditinga = get_string("editinga", "moodle", $fullmodulename); + $strmodulenameplural = get_string("modulenameplural", $module->name); + + /* + $navlinks = array(); + $navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity'); + if ($navlinksinstancename) { + $navlinks[] = $navlinksinstancename; + } + $navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'title'); + */ + + $navigation = ''; //build_navigation($navlinks); + + print_header_simple($streditinga, "LAMS", $navigation, $mform->focus(), "", false); + + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $overridableroles = get_overridable_roles($context); + $assignableroles = get_assignable_roles($context); + $currenttab = 'update'; + include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php'); + } + $icon = ''; + + print_heading_with_help($pageheading, "mods", $module->name, $icon); + $mform->display(); + //print_footer($course); + } +?> Index: temp_moodle_dev/moodle/mod/forum/lib.php =================================================================== diff -u -r3163c863d928a9e392249661266bb38a09936312 -r49d09eadd0817437a212bead2eb82e6dce4d5a6d --- temp_moodle_dev/moodle/mod/forum/lib.php (.../lib.php) (revision 3163c863d928a9e392249661266bb38a09936312) +++ temp_moodle_dev/moodle/mod/forum/lib.php (.../lib.php) (revision 49d09eadd0817437a212bead2eb82e6dce4d5a6d) @@ -6691,10 +6691,34 @@ } /** - * Returns all other caps used in module + * */ -function forum_get_extra_capabilities() { - return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent'); +function forum_clone_instance($id, $courseid, $userid) { +# global $CFG; +# require_once($CFG->dirroot.'/course/lib.php'); + + if ( ! $existingforum = get_record('forum', 'id', $id) ) { + $existingforum->course = $courseid; + $existingforum->name = "Forum"; + $existingforum->intro = ""; + $existingforum->is_lams = 1; + $existingforum->id = insert_record('forum', $existingforum); + } else { + unset($existingforum->id); + $existingforum->course = $courseid; + $existingforum->is_lams = 1; + $existingforum->id = insert_record('forum', $existingforum); + } + + $module = get_record('modules', 'name', 'forum'); + + $cm->course = $courseid; + $cm->module = $module->id; + $cm->instance = $existingforum->id; + $cm->added = time(); +# $cm->id = add_course_module($cm); + $cm->id = insert_record('course_modules', $cm); } + ?> Index: temp_moodle_dev/moodle/mod/forum/mod_form_lams.php =================================================================== diff -u --- temp_moodle_dev/moodle/mod/forum/mod_form_lams.php (revision 0) +++ temp_moodle_dev/moodle/mod/forum/mod_form_lams.php (revision 49d09eadd0817437a212bead2eb82e6dce4d5a6d) @@ -0,0 +1,178 @@ +dirroot.'/course/moodleform_mod.php'); + +class mod_forum_mod_form extends moodleform_mod { + + function definition() { + + global $CFG, $COURSE; + $mform =& $this->_form; + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + + $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + + $forum_types = forum_get_forum_types(); + + asort($forum_types); + $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forum_types); + $mform->setHelpButton('type', array('forumtype', get_string('forumtype', 'forum'), 'forum')); + $mform->setDefault('type', 'general'); + + $mform->addElement('htmleditor', 'intro', get_string('forumintro', 'forum')); + $mform->setType('intro', PARAM_RAW); + $mform->addRule('intro', get_string('required'), 'required', null, 'client'); + $mform->setHelpButton('intro', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton'); + + $options = array(); + $options[0] = get_string('no'); + $options[1] = get_string('yesforever', 'forum'); + $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum'); + $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum'); + $mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options); + $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum')); + + $options = array(); + $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum'); + $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum'); + $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum'); + $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options); + $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum')); + + $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); + $choices[1] = get_string('uploadnotallowed'); + $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; + $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices); + $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum')); + $mform->setDefault('maxbytes', $CFG->forum_maxbytes); + + if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) { +//------------------------------------------------------------------------------- + $mform->addElement('header', '', get_string('rss')); + $choices = array(); + $choices[0] = get_string('none'); + $choices[1] = get_string('discussions', 'forum'); + $choices[2] = get_string('posts', 'forum'); + $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices); + $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum')); + + $choices = array(); + $choices[0] = '0'; + $choices[1] = '1'; + $choices[2] = '2'; + $choices[3] = '3'; + $choices[4] = '4'; + $choices[5] = '5'; + $choices[10] = '10'; + $choices[15] = '15'; + $choices[20] = '20'; + $choices[25] = '25'; + $choices[30] = '30'; + $choices[40] = '40'; + $choices[50] = '50'; + $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices); + $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum')); + } +//------------------------------------------------------------------------------- +/* $mform->addElement('header', '', get_string('grade')); + + $mform->addElement('select', 'assessed', get_string('aggregatetype', 'forum') , forum_get_aggregate_types()); + $mform->setDefault('assessed', 0); + $mform->setHelpButton('assessed', array('assessaggregate', get_string('aggregatetype', 'forum'), 'forum')); + + $mform->addElement('modgrade', 'scale', get_string('grade'), false); + $mform->disabledIf('scale', 'assessed', 'eq', 0); + + $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum')); + $mform->disabledIf('ratingtime', 'assessed', 'eq', 0); + + $mform->addElement('date_time_selector', 'assesstimestart', get_string('from')); + $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0); + $mform->disabledIf('assesstimestart', 'ratingtime'); + + $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to')); + $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);*/ +//------------------------------------------------------------------------------- + $mform->addElement('header', '', get_string('blockafter', 'forum')); + $options = array(); + $options[0] = get_string('blockperioddisabled','forum'); + $options[60*60*24] = '1 '.get_string('day'); + $options[60*60*24*2] = '2 '.get_string('days'); + $options[60*60*24*3] = '3 '.get_string('days'); + $options[60*60*24*4] = '4 '.get_string('days'); + $options[60*60*24*5] = '5 '.get_string('days'); + $options[60*60*24*6] = '6 '.get_string('days'); + $options[60*60*24*7] = '1 '.get_string('week'); + $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options); + $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum')); + + $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum')); + $mform->setType('blockafter', PARAM_INT); + $mform->setDefault('blockafter', '0'); + $mform->addRule('blockafter', null, 'numeric', null, 'client'); + $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum')); + $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0); + + + $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum')); + $mform->setType('warnafter', PARAM_INT); + $mform->setDefault('warnafter', '0'); + $mform->addRule('warnafter', null, 'numeric', null, 'client'); + $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum')); + $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0); + +//------------------------------------------------------------------------------- + /*$features = new stdClass; + $features->groups = false; + $features->groupings = true; + $features->groupmembersonly = true; + $features->gradecat = false; + $features->idnumber = false; + $this->standard_coursemodule_elements($features);*/ + $this->standard_hidden_coursemodule_elements(); +//------------------------------------------------------------------------------- +// buttons + $this->add_action_buttons(false, 'Save', false); + + } + + function definition_after_data(){ + parent::definition_after_data(); + $mform =& $this->_form; + $type =& $mform->getElement('type'); + $typevalue = $mform->getElementValue('type'); + + //we don't want to have these appear as possible selections in the form but + //we want the form to display them if they are set. + if ($typevalue[0]=='news'){ + $type->addOption(get_string('namenews', 'forum'), 'news'); + $type->setHelpButton(array('forumtypenews', get_string('forumtype', 'forum'), 'forum')); + $type->freeze(); + $type->setPersistantFreeze(true); + } + if ($typevalue[0]=='social'){ + $type->addOption(get_string('namesocial', 'forum'), 'social'); + $type->freeze(); + $type->setPersistantFreeze(true); + } + + } + + function data_preprocessing(&$default_values){ + if (empty($default_values['scale'])){ + $default_values['assessed'] = 0; + } + + if (empty($default_values['assessed'])){ + $default_values['ratingtime'] = 0; + } else { + $default_values['ratingtime']= + ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0; + } + } + +} +?> Index: temp_moodle_dev/moodle/mod/forum/view-lams.php =================================================================== diff -u --- temp_moodle_dev/moodle/mod/forum/view-lams.php (revision 0) +++ temp_moodle_dev/moodle/mod/forum/view-lams.php (revision 49d09eadd0817437a212bead2eb82e6dce4d5a6d) @@ -0,0 +1,269 @@ +libdir/rsslib.php"); + + + $id = optional_param('id', 0, PARAM_INT); // Course Module ID + $f = optional_param('f', 0, PARAM_INT); // Forum ID + $mode = optional_param('mode', 0, PARAM_INT); // Display mode (for single forum) + $showall = optional_param('showall', '', PARAM_INT); // show all discussions on one page + $changegroup = optional_param('group', -1, PARAM_INT); // choose the current group + $page = optional_param('page', 0, PARAM_INT); // which page to show + $search = optional_param('search', ''); // search string + + + $buttontext = ''; + + if ($id) { + if (! $cm = get_coursemodule_from_id('forum', 5)) { + error("Course Module ID was incorrect"); + } + if (! $forum = get_record("forum", "id", $id)) { + error("Forum ID was incorrect"); + } + if (! $course = get_record("course", "id", $forum->course)) { + error("Course is misconfigured"); + } + $strforums = get_string("modulenameplural", "forum"); + $strforum = get_string("modulename", "forum"); + $buttontext = update_module_button($cm->id, $course->id, $strforum); + + } else if ($f) { + + if (! $forum = get_record("forum", "id", $f)) { + error("Forum ID was incorrect or no longer exists"); + } + if (! $course = get_record("course", "id", $forum->course)) { + error("Forum is misconfigured - don't know what course it's from"); + } + + $strforums = get_string("modulenameplural", "forum"); + $strforum = get_string("modulename", "forum"); + + if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { + error("Course Module missing"); + } + + $buttontext = update_module_button($cm->id, $course->id, $strforum); + + } else { + error('Must specify a course module or a forum ID'); + } + + if (!$buttontext) { + $buttontext = forum_search_form($course, $search); + } + + +// require_course_login($course, true, $cm); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + + +/// Print header. + $navigation = build_navigation('', $cm); + print_header_simple(format_string($forum->name), "", + $navigation, "", "", true, $buttontext, navmenu($course, $cm)); + +/// Some capability checks. +/* if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) { + notice(get_string("activityiscurrentlyhidden")); + } + + if (!has_capability('mod/forum:viewdiscussion', $context)) { + notice(get_string('noviewdiscussionspermission', 'forum')); + }*/ + +/// find out current groups mode +/* groups_print_activity_menu($cm, 'view.php?id=' . $cm->id); + $currentgroup = groups_get_activity_group($cm); + $groupmode = groups_get_activity_groupmode($cm);*/ + +/// Okay, we can show the discussions. Log the forum view. +/* if ($cm->id) { + add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id); + } else { + add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); + }*/ + + + +/// Print settings and things across the top + + // If it's a simple single discussion forum, we need to print the display + // mode control. + if ($forum->type == 'single') { + if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) { + if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) { + $discussion = array_pop($discussions); + } + } + if ($discussion) { + if ($mode) { + set_user_preference("forum_displaymode", $mode); + } + $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); + forum_print_mode_form($forum->id, $displaymode, $forum->type); + } + } + + +// print_box_start('forumcontrol clearfix'); + +// print_box_start('subscription clearfix'); + echo '
'; + + if (!empty($USER->id) && !has_capability('moodle/legacy:guest', $context, NULL, false)) { + $SESSION->fromdiscussion = "$FULLME"; + if (forum_is_forcesubscribed($forum->id)) { + $streveryoneisnowsubscribed = get_string('everyoneisnowsubscribed', 'forum'); + $strallowchoice = get_string('allowchoice', 'forum'); + echo '' . get_string("forcessubscribe", 'forum') . '
'; + helpbutton("subscription", $strallowchoice, "forum"); + echo ' '; + if (has_capability('mod/forum:managesubscriptions', $context)) { + echo "id&force=no\">$strallowchoice"; + } else { + echo $streveryoneisnowsubscribed; + } + echo '
'; + + } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) { + $strsubscriptionsoff = get_string('disallowsubscribe','forum'); + echo $strsubscriptionsoff; + helpbutton("subscription", $strsubscriptionsoff, "forum"); + } else { + $streveryonecannowchoose = get_string("everyonecannowchoose", "forum"); + $strforcesubscribe = get_string("forcesubscribe", "forum"); + $strshowsubscribers = get_string("showsubscribers", "forum"); + echo '' . get_string("allowsallsubscribe", 'forum') . '
'; + helpbutton("subscription", $strforcesubscribe, "forum"); + echo ' '; + + if (has_capability('mod/forum:managesubscriptions', $context)) { + echo "id&force=yes\">$strforcesubscribe"; + } else { + echo ''.$streveryonecannowchoose.''; + } + + if(has_capability('mod/forum:viewsubscribers', $context)){ + echo "
"; + echo "id\">$strshowsubscribers"; + } + + echo ''; + } + + if (($forum->trackingtype == FORUM_TRACKING_OPTIONAL) && forum_tp_can_track_forums($forum)) { + echo ''; + } + + } + + /// If rss are activated at site and forum level and this forum has rss defined, show link + if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && + $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) { + + if ($forum->rsstype == 1) { + $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name)); + } else { + $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name)); + } + if (empty($USER->id)) { + $userid = 0; + } else { + $userid = $USER->id; + } +// print_box_start('rsslink'); + echo ''; + rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext); + echo ''; +// print_box_end(); // subscription + + } +// print_box_end(); // subscription + echo '
'; + +// print_box_end(); // forumcontrol + +// print_box(' ', 'clearer'); + + + if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { + $a->blockafter = $forum->blockafter; + $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); + notify(get_string('thisforumisthrottled','forum',$a)); + } + + if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) { + notify(get_string('qandanotify','forum')); + } + + $forum->intro = trim($forum->intro); + + switch ($forum->type) { + case 'single': + if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) { + if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) { + notify("Warning! There is more than one discussion in this forum - using the most recent"); + $discussion = array_pop($discussions); + } else { + error("Could not find the discussion in this forum"); + } + } + if (! $post = forum_get_post_full($discussion->firstpost)) { + error("Could not find the first post in this forum"); + } + if ($mode) { + set_user_preference("forum_displaymode", $mode); + } + $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); + $canrate = has_capability('mod/forum:rate', $context); + forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, NULL, $canrate); + break; + + case 'eachuser': + if (!empty($forum->intro)) { + print_box(format_text($forum->intro), 'generalbox', 'intro'); + } + echo '

'; + if (forum_user_can_post_discussion($forum, -1, -1, $cm)) { + print_string("allowsdiscussions", "forum"); + } else { + echo ' '; + } + echo '

'; + if (!empty($showall)) { + forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); + } else { + forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); + } + break; + + case 'teacher': + if (!empty($showall)) { + forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); + } else { + forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); + } + break; + + default: + if (!empty($forum->intro)) { + print_box(format_text($forum->intro), 'generalbox', 'intro'); + } + echo '
'; + if (!empty($showall)) { + forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); + } else { + forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); + } + + + break; + } + print_footer($course); + +?>