From 264867fdebbdc3f028bb01d8449e19a5ba199bd2 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Thu, 9 Nov 2006 18:25:58 +0000 Subject: [PATCH] add code to redirect to modedit.php from course/mod.php for activities adding / updating using new formslib migrated chat/mod.html to formslib definition of form is in chat/mod_form.php --- course/lib.php | 106 ++++++++-------- course/mod.php | 37 ++++-- course/modedit.php | 287 ++++++++++++++++++++++++++++++++++++++++++ lang/en_utf8/form.php | 2 +- mod/chat/lib.php | 17 +-- mod/chat/mod.html | 110 ---------------- mod/chat/mod_form.php | 64 ++++++++++ 7 files changed, 441 insertions(+), 182 deletions(-) create mode 100644 course/modedit.php delete mode 100644 mod/chat/mod.html create mode 100644 mod/chat/mod_form.php diff --git a/course/lib.php b/course/lib.php index 5d866acf93..b0cb1f681d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -264,7 +264,7 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit // and so the next 86400 seconds worth of logs are printed. /// Setup for group handling. - + /// If the group mode is separate, and this user does not have editing privileges, /// then only the user's group can be viewed. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { @@ -332,26 +332,26 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit } $totalcount = 0; // Initialise - + $result = array(); $result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount); $result['totalcount'] = $totalcount; return $result; } - - + + function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100, $url="", $modname="", $modid=0, $modaction="", $groupid=0) { - + global $CFG; - + if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage, $modname, $modid, $modaction, $groupid)) { notify("No logs found!"); print_footer($course); exit; } - + if ($course->id == SITEID) { $courses[0] = ''; if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) { @@ -360,7 +360,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per } } } - + $totalcount = $logs['totalcount']; $count=0; $ldcache = array(); @@ -412,7 +412,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per } } - //Filter log->info + //Filter log->info $log->info = format_string($log->info); $log->url = strip_tags(urldecode($log->url)); // Some XSS protection @@ -451,12 +451,12 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t". get_string('fullname')."\t".get_string('action')."\t".get_string('info'); - + if (!$logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid)) { return false; } - + if ($course->id == SITEID) { $courses[0] = ''; if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) { @@ -465,7 +465,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, } } } - + $count=0; $ldcache = array(); $tt = getdate(time()); @@ -475,7 +475,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false); $filename .= '.txt'; - header("Content-Type: application/download\n"); + header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=$filename"); header("Expires: 0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); @@ -504,7 +504,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, } } - //Filter log->info + //Filter log->info $log->info = format_string($log->info); $log->url = strip_tags(urldecode($log->url)); // Some XSS protection @@ -523,16 +523,16 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $modid, $modaction, $groupid) { - + global $CFG; require_once("$CFG->libdir/excellib.class.php"); - + if (!$logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid)) { return false; } - + if ($course->id == SITEID) { $courses[0] = ''; if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) { @@ -541,7 +541,7 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, } } } - + $count=0; $ldcache = array(); $tt = getdate(time()); @@ -552,14 +552,14 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1)); $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false); $filename .= '.xls'; - + $workbook = new MoodleExcelWorkbook('-'); $workbook->send($filename); - + $worksheet = array(); $headers = array(get_string('course'), get_string('time'), get_string('ip_address'), get_string('fullname'), get_string('action'), get_string('info')); - + // Creating worksheets for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) { $sheettitle = get_string('excel_sheettitle', 'logs', $wsnumber).$nroPages; @@ -612,7 +612,7 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $row = FIRSTUSEDEXCELROW; } } - + $myxls->write($row, 0, $courses[$log->course], ''); // Excel counts from 1/1/1900 $excelTime=25569+$log->time/(3600*24); @@ -622,7 +622,7 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $myxls->write($row, 3, $fullname, ''); $myxls->write($row, 4, $log->module.' '.$log->action, ''); $myxls->write($row, 5, $log->info, ''); - + $row++; } @@ -636,15 +636,15 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, $modid, $modaction, $groupid) { - + global $CFG; require_once($CFG->libdir.'/phpdocwriter/lib/include.php'); - + if (!$logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid)) { return false; } - + if ($course->id == SITEID) { $courses[0] = ''; if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) { @@ -653,7 +653,7 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, } } } - + $count=0; $ldcache = array(); $tt = getdate(time()); @@ -681,10 +681,10 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, $sxw->AddPageDef(array('name'=>'Standard', 'margins'=>'1,1,1,1', 'w'=>'29.7', 'h'=>'21')); $sxw->Write(get_string('savedat').userdate(time(), $strftimedatetime)); $sxw->Ln(3); - + $headers = array(get_string('course'), get_string('time'), get_string('ip_address'), get_string('fullname'), get_string('action'), get_string('info')); - + foreach($headers as $key=>$header){ $headers[$key] = eregi_replace ("", " ",$header); } @@ -705,7 +705,7 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, } } - // Filter log->info + // Filter log->info $log->info = format_string($log->info); $log->url = strip_tags(urldecode($log->url)); // Some XSS protection @@ -720,7 +720,7 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, } $sxw->Table($headers,$data); $sxw->Output(); - + return true; } */ @@ -809,13 +809,13 @@ function print_recent_activity($course) { if ($users) { echo '
'; if (! $heading) { - print_headline(get_string("newusers").':', 3); + print_headline(get_string("newusers").':', 3); $heading = true; $content = true; } echo "
    \n"; foreach ($users as $user) { - + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); echo '
  1. id&course=$course->id\">$fullname
  2. \n"; } @@ -1201,7 +1201,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, } } elseif ($ismoving) { echo "
      \n"; - } + } if ($ismoving) { echo '
    • '. @@ -1253,7 +1253,7 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, if (!course_allowed_module($course,$key)) unset($modnames[$key]); } - + // this is stupid but labels get put into resource, so if resource is hidden and label is not, we're in trouble. if (course_allowed_module($course,'label') && empty($resourceallowed)) { $modnames['label'] = get_string('modulename', 'label'); @@ -1305,10 +1305,10 @@ function make_categories_list(&$list, &$parents, $category=NULL, $path="") { // initialize the arrays if needed if (!is_array($list)) { - $list = array(); + $list = array(); } if (!is_array($parents)) { - $parents = array(); + $parents = array(); } if ($category) { @@ -1549,8 +1549,8 @@ function print_course($course, $width="100%") { $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. $course->fullname.'
      '; - if ($teachers = get_users_by_capability($context, 'moodle/course:update', - 'u.*, ul.timeaccess as lastaccess, ra.hidden', + if ($teachers = get_users_by_capability($context, 'moodle/course:update', + 'u.*, ul.timeaccess as lastaccess, ra.hidden', 'r.sortorder ASC', '','','','', false)) { $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context); $namesarray = array(); @@ -1752,7 +1752,7 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) { /* * Delete a course module and any associated data at the course level (events) - * Until 1.5 this function simply marked a deleted flag ... now it + * Until 1.5 this function simply marked a deleted flag ... now it * deletes it completely. * */ @@ -1992,11 +1992,11 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=- } /** - * given a course object with shortname & fullname, this function will + * given a course object with shortname & fullname, this function will * truncate the the number of chars allowed and add ... if it was too long */ function course_format_name ($course,$max=100) { - + $str = $course->shortname.': '.$course->fullname; if (strlen($str) <= $max) { return $str; @@ -2080,7 +2080,7 @@ function print_visible_setting($form, $course=NULL) { if ($hiddensection) { $visible = false; } - + echo ''; echo ''.get_string('visible', '').':'; echo ''; @@ -2089,7 +2089,7 @@ function print_visible_setting($form, $course=NULL) { $choices[0] = get_string('hide'); choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection); echo ''; -} +} function update_restricted_mods($course,$mods) { delete_records("course_allowed_modules","course",$course->id); @@ -2110,7 +2110,7 @@ function update_restricted_mods($course,$mods) { /** * This function will take an int (module id) or a string (module name) * and return true or false, whether it's allowed in the given course (object) - * $mod is not allowed to be an object, as the field for the module id is inconsistent + * $mod is not allowed to be an object, as the field for the module id is inconsistent * depending on where in the code it's called from (sometimes $mod->id, sometimes $mod->module) */ @@ -2118,7 +2118,7 @@ function course_allowed_module($course,$mod) { if (empty($course->restrictmodules)) { return true; } - + // i am not sure this capability is correct if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { return true; @@ -2138,7 +2138,7 @@ function course_allowed_module($course,$mod) { /*** *** Efficiently moves many courses around while maintaining *** sortorder in order. - *** + *** *** $courseids is an array of course ids *** **/ @@ -2148,11 +2148,11 @@ function move_courses ($courseids, $categoryid) { global $CFG; if (!empty($courseids)) { - - $courseids = array_reverse($courseids); + + $courseids = array_reverse($courseids); foreach ($courseids as $courseid) { - + if (! $course = get_record("course", "id", $courseid)) { notify("Error finding course $courseid"); } else { @@ -2162,7 +2162,7 @@ function move_courses ($courseids, $categoryid) { if ($sortorder === false) { // the category is empty // rather than let the db default to 0 - // set it to > 100 and avoid extra work in fix_coursesortorder() + // set it to > 100 and avoid extra work in fix_coursesortorder() $sortorder = 200; } else if ($sortorder < 10) { fix_course_sortorder($categoryid); @@ -2178,14 +2178,14 @@ function move_courses ($courseids, $categoryid) { $course->teachers = addslashes($course->teachers); $course->student = addslashes($course->student); $course->students = addslashes($course->students); - + if (!update_record('course', $course)) { notify("An error occurred - course not moved!"); } } } fix_course_sortorder(); - } + } return true; } diff --git a/course/mod.php b/course/mod.php index 5df2b31d20..44d95b361b 100644 --- a/course/mod.php +++ b/course/mod.php @@ -41,8 +41,31 @@ } } + //check if we are adding / editing a module that has new forms using formslib + if (!empty($add)){ + $modname=$add; + if (file_exists("../mod/$modname/mod_form.php")) { + $id = required_param('id',PARAM_INT); + $section = required_param('section',PARAM_INT); + + redirect("modedit.php?add=$add&course=$id§ion=$section"); + } + }elseif (!empty($update)){ + if (!$modname=get_field_sql("SELECT md.name + FROM {$CFG->prefix}course_modules cm, + {$CFG->prefix}modules md + WHERE cm.id = '$update' AND + md.id = cm.module")){ + error('Invalid course module id!'); + } + if (file_exists("../mod/$modname/mod_form.php")) { + redirect("modedit.php?update=$update"); + } + } + //not adding / editing a module that has new forms using formslib + //carry on - if (!empty($course) and confirm_sesskey()) { // add or update form submitted + if (!empty($course) and confirm_sesskey()) { // add, delete or update form submitted if (empty($mod->coursemodule)) { //add if (! $course = get_record("course", "id", $mod->course)) { @@ -65,7 +88,7 @@ require_login($course->id); // needed to setup proper $COURSE $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); - + $mod->course = $course->id; $mod->modulename = clean_param($mod->modulename, PARAM_SAFEDIR); // For safety $modlib = "$CFG->dirroot/mod/$mod->modulename/lib.php"; @@ -418,7 +441,7 @@ require_login($cm->course); // needed to setup proper $COURSE $context = get_context_instance(CONTEXT_COURSE, $cm->course); require_capability('moodle/course:manageactivities', $context); - + if (! $module = get_record("modules", "id", $cm->module)) { error("This module doesn't exist"); } @@ -512,7 +535,7 @@ $pageheading = get_string("updatinga", "moodle", $fullmodulename); } $strnav = "wwwroot/mod/$module->name/view.php?id=$cm->id\">".format_string($form->name,true)." ->"; - + if ($module->name == 'resource') { $CFG->pagepath = 'mod/'.$module->name.'/'.$form->type; } else { @@ -533,7 +556,7 @@ require_login($course->id); // needed to setup proper $COURSE $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); - + if (! $module = get_record("modules", "id", $cm->module)) { error("This module doesn't exist"); } @@ -588,10 +611,10 @@ if (! $module = get_record("modules", "name", $add)) { error("This module type doesn't exist"); } - + $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); - + if (!course_allowed_module($course,$module->id)) { error("This module has been disabled for this particular course"); } diff --git a/course/modedit.php b/course/modedit.php new file mode 100644 index 0000000000..502ac54b44 --- /dev/null +++ b/course/modedit.php @@ -0,0 +1,287 @@ +id); + require_capability('moodle/course:manageactivities', $context); + + if (!course_allowed_module($course, $module->id)) { + error("This module has been disabled for this particular course"); + } + + require_login($course->id); // needed to setup proper $COURSE + + $form->section = $section; // The section number itself + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->instance = ""; + $form->coursemodule = ""; + $form->add=$add; + if (!empty($type)) { + $form->type = $type; + } + + $sectionname = get_string("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); + } + $strnav = ''; + + }elseif (!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->id); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $course->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 = $cm->section; // The section ID + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->instance = $cm->instance; + $form->update=$update; + + $sectionname = get_string("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); + } + $strnav = "wwwroot/mod/$module->name/view.php?id=$cm->id\">".format_string($form->name,true)." ->"; + }else{ + error('Invalid operation.'); + } + + $modmoodleform = "../mod/$module->name/mod_form.php"; + if (file_exists($modmoodleform)) { + require_once($modmoodleform); + $mformclassname=$module->name.'_mod_form'; + $mform=& new $mformclassname('modedit.php'); + + }else{ + error('No formslib form description file found for this activity.'); + } + if ($fromform=$mform->data_submitted()){ + if (empty($fromform->coursemodule)) { //add + 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; + } + + require_login($course->id); // needed to setup proper $COURSE + $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 + $modlib = "$CFG->dirroot/mod/$fromform->modulename/lib.php"; + + if (file_exists($modlib)) { + include_once($modlib); + } else { + error("This module is missing important code! ($modlib)"); + } + $addinstancefunction = $fromform->modulename."_add_instance"; + $updateinstancefunction = $fromform->modulename."_update_instance"; + + if (!empty($fromform->update)) { + + + if (isset($fromform->name)) { + if (trim($fromform->name) == '') { + unset($fromform->name); + } + } + + $return = $updateinstancefunction($fromform); + if (!$return) { + error("Could not update the $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($return)) { + error($return, "view.php?id=$course->id"); + } + + if (isset($fromform->visible)) { + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + } + + if (isset($fromform->groupmode)) { + set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode); + } + + if (isset($fromform->redirect)) { + $SESSION->returnpage = $fromform->redirecturl; + } else { + $SESSION->returnpage = "$CFG->wwwroot/mod/$fromform->modulename/view.php?id=$fromform->coursemodule"; + } + + 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); + }elseif (!empty($fromform->add)){ + + if (!course_allowed_module($course,$fromform->modulename)) { + error("This module ($fromform->modulename) has been disabled for this particular course"); + } + + if (!isset($fromform->name) || trim($fromform->name) == '') { + $fromform->name = get_string("modulename", $fromform->modulename); + } + + $return = $addinstancefunction($fromform); + if (!$return) { + /*if (file_exists($moderr)) { + $form = $fromform; + include_once($moderr); + die; + }*/ + error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($return)) { + error($return, "view.php?id=$course->id"); + } + + if (!isset($fromform->groupmode)) { // to deal with pre-1.5 modules + $fromform->groupmode = $course->groupmode; /// Default groupmode the same as course + } + + $fromform->instance = $return; + + // 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"); + } + + if (!isset($fromform->visible)) { // We get the section's visible field status + $fromform->visible = get_field("course_sections","visible","id",$sectionid); + } + // make sure visibility is set correctly (in particular in calendar) + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + + if (isset($fromform->redirect)) { + $SESSION->returnpage = $fromform->redirecturl; + } else { + $SESSION->returnpage = "$CFG->wwwroot/mod/$fromform->modulename/view.php?id=$fromform->coursemodule"; + } + + 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."); + } + + rebuild_course_cache($course->id); + + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect("view.php?id=$course->id#section-$sectionreturn"); + } + exit; + + }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); + + print_header_simple($streditinga, '', + "wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural -> + $strnav $streditinga", $mform->focus(), "", false); + + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $currenttab = 'update'; + include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php'); + } + $icon = ' '; + + print_heading_with_help($pageheading, "mods", $module->name, $icon); + $mform->standard_coursemodule_elements_setup($course, isset($cm)?$cm:null, $form->section); + $mform->set_defaults($form); + $mform->display(); + print_footer($course); + } +?> \ No newline at end of file diff --git a/lang/en_utf8/form.php b/lang/en_utf8/form.php index 62d16eb71c..d41afd043a 100644 --- a/lang/en_utf8/form.php +++ b/lang/en_utf8/form.php @@ -17,5 +17,5 @@ $string['nomethodforaddinghelpbutton'] = 'There is no method for adding a help b $string['nonexistentformelements'] = 'Trying to add help buttons to nonexistent form elements : $a'; $string['requiredelement'] = 'Required field.'; $string['general'] = 'General Settings'; - +$string['modstandardels']='Common Module Settings'; ?> diff --git a/mod/chat/lib.php b/mod/chat/lib.php index d69c9510dc..edd2f725e5 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -58,9 +58,6 @@ function chat_add_instance($chat) { $chat->timemodified = time(); - $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, - $chat->chathour, $chat->chatminute); - if ($returnid = insert_record("chat", $chat)) { $event = NULL; @@ -90,12 +87,10 @@ function chat_update_instance($chat) { $chat->timemodified = time(); $chat->id = $chat->instance; - $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, - $chat->chathour, $chat->chatminute); if ($returnid = update_record("chat", $chat)) { - $event = NULL; + $event = new object(); if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { @@ -197,11 +192,11 @@ function chat_print_recent_activity($course, $isteacher, $timestart) { $current = 0; } if ($chat = get_record('chat', 'id', $chatuser->chatid)) { - + // we find the course module id $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); - + // needs to be fixed if (!(has_capability('mod/chat:readlog', $context) or instance_is_visible('chat', $chat))) { // Chat hidden to students continue; @@ -574,7 +569,7 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser $text = format_text($text, FORMAT_MOODLE, $options, $courseid); // And now check for special cases if (substr($text, 0, 5) == 'beep ') { - /// It's a beep! + /// It's a beep! $beepwho = trim(substr($text, 5)); if ($beepwho == 'all') { // everyone @@ -587,7 +582,7 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser $outinfo = $message->strtime.': '.get_string('messagebeepsyou', 'chat', fullname($sender)); $outmain = ''; $output->beep = true; - + } else { //something is not caught? return false; } @@ -609,7 +604,7 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser $outinfo = $message->strtime.' '.$sender->firstname; $outmain = $text; } - + /// Format the message as a small table $output->text = strip_tags($outinfo.': '.$outmain); diff --git a/mod/chat/mod.html b/mod/chat/mod.html deleted file mode 100644 index 5eb226b56c..0000000000 --- a/mod/chat/mod.html +++ /dev/null @@ -1,110 +0,0 @@ -name)) { - $form->name = ''; - } - if (!isset($form->intro)) { - $form->intro = ''; - } - if (!isset($form->keepdays)) { - $form->keepdays = 30; - } - if (!isset($form->studentlogs)) { - $form->studentlogs = 0; - } - if (!isset($form->chattime)) { - $form->chattime = 0; - } - if (!isset($form->schedule)) { - $form->schedule = 0; - } -?> -
      - - - - - - - - - - - - - - - - - - - - - - - - - - -
      : - -
      :

      - '; - helpbutton('questions', get_string('helpquestions'), 'moodle', true, true); - echo '
      '; - emoticonhelpbutton('form', 'intro'); - echo '
      '; - ?> -
      - intro); ?> -
      :chattime); - echo ' - '; - print_time_selector('chathour', 'chatminute', $form->chattime); - ?>
      :schedule, '', '', ''); - ?>
      : - keepdays, '', '', ''); - ?> -
      : - studentlogs, '', '', ''); - ?> -
      -
      - - - - - - - - - - -
      -
      \ No newline at end of file diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php new file mode 100644 index 0000000000..2938dd7df2 --- /dev/null +++ b/mod/chat/mod_form.php @@ -0,0 +1,64 @@ +libdir.'/formslib.php'); +class chat_mod_form extends moodleform_mod { + + function definition() { + + global $CFG; + $mform =& $this->_form; + $renderer =& $mform->defaultRenderer(); + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + + $mform->addElement('text', 'name', get_string('chatname', 'chat')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + + $mform->addElement('htmleditor', 'intro', get_string('chatintro', 'chat')); + $mform->setType('intro', PARAM_RAW); + $mform->addRule('intro', get_string('required'), 'required', null, 'client'); + + $mform->addElement('date_time_selector', 'chattime', get_string('chattime', 'chat')); + + $options=array(); + $options[0] = get_string('donotusechattime', 'chat'); + $options[1] = get_string('repeatnone', 'chat'); + $options[2] = get_string('repeatdaily', 'chat'); + $options[3] = get_string('repeatweekly', 'chat'); + $mform->addElement('select', 'schedule', get_string('repeattimes', 'chat'), $options); + + + $options=array(); + $options[0] = get_string('neverdeletemessages', 'chat'); + $options[365] = get_string('numdays', '', 365); + $options[180] = get_string('numdays', '', 180); + $options[150] = get_string('numdays', '', 150); + $options[120] = get_string('numdays', '', 120); + $options[90] = get_string('numdays', '', 90); + $options[60] = get_string('numdays', '', 60); + $options[30] = get_string('numdays', '', 30); + $options[21] = get_string('numdays', '', 21); + $options[14] = get_string('numdays', '', 14); + $options[7] = get_string('numdays', '', 7); + $options[2] = get_string('numdays', '', 2); + $mform->addElement('select', 'keepdays', get_string('savemessages', 'chat'), $options); + + $options=array(); + $options[0] = get_string('no'); + $options[1] = get_string('yes'); + $mform->addElement('select', 'studentlogs', get_string('studentseereports', 'chat'), $options); + + $this->standard_coursemodule_elements(); + + $buttonarray=array(); + $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges')); + $buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel')); + $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $renderer->addStopFieldsetElements('buttonar'); + } + + + +} +?> \ No newline at end of file -- 2.39.5