/** Custom functions * */
 function handle_extra_actions()
 {
     global $DB;
     if (isset($_POST['sec0title'])) {
         if (!($course = $DB->get_record('course', array('id' => $_POST['id'])))) {
             print_error('This course doesn\'t exist.');
         }
         FN_get_course($course);
         $course->sec0title = $_POST['sec0title'];
         FN_update_course($course);
         $cm->course = $course->id;
     }
 }
 if (isset($_GET['mandatory']) and confirm_sesskey()) {
     if (!($cm = get_record("course_modules", "id", $_GET['id']))) {
         error("This course module doesn't exist");
     }
     if (!isadmin()) {
         error("You can't modify the mandatory settings!");
     }
     fn_set_mandatory_for_module($cm->id, $_GET['mandatory']);
 } else {
     if (isset($_POST['sec0title'])) {
         if (!($course = get_record('course', 'id', $_POST['id']))) {
             error('This course doesn\'t exist.');
         }
         FN_get_course($course);
         $course->sec0title = $_POST['sec0title'];
         FN_update_course($course);
         $cm->course = $course->id;
     } else {
         if (isset($_GET['openchat'])) {
             if (!($course = get_record('course', 'id', $_GET['id']))) {
                 error('This course doesn\'t exist.');
             }
             if ($varrec = get_record('course_config_FN', 'courseid', $course->id, 'variable', 'classchatopen')) {
                 $varrec->value = $_GET['openchat'];
                 update_record('course_config_FN', $varrec);
             } else {
                 $varrec->courseid = $course->id;
                 $varrec->variable = 'classchatopen';
                 $varrec->value = $_GET['openchat'];
                 insert_record('course_config_FN', $varrec);
             }
 function handle_extra_actions()
 {
     global $USER, $CFG;
     ///     Handle activity complete.
     ///
     if (($resid = optional_param('rescomplete', 0, PARAM_INT)) && confirm_sesskey()) {
         if (!($cm = get_record("course_modules", "id", optional_param('id', 0, PARAM_INT)))) {
             error("This course module doesn't exist");
         }
         set_resource_complete($resid, $USER->id);
     } else {
         if (($hide = optional_param('hidegrades', false, PARAM_INT)) !== false && confirm_sesskey()) {
             if (!($cm = get_record("course_modules", "id", optional_param('mid', 0, PARAM_INT)))) {
                 error("This course module doesn't exist");
             }
             /// Replace with a capability...
             if (!isadmin()) {
                 error("You can't modify the gradebook settings!");
             }
             $this->set_gradebook_for_module($cm->id, $hide);
         } else {
             if (isset($_GET['mandatory']) and confirm_sesskey()) {
                 if (!($cm = get_record("course_modules", "id", $_GET['id']))) {
                     error("This course module doesn't exist");
                 }
                 if (!isadmin()) {
                     error("You can't modify the mandatory settings!");
                 }
                 fn_set_mandatory_for_module($cm->id, $_GET['mandatory']);
             } else {
                 if (isset($_POST['sec0title'])) {
                     if (!($course = get_record('course', 'id', $_POST['id']))) {
                         error('This course doesn\'t exist.');
                     }
                     FN_get_course($course);
                     $course->sec0title = $_POST['sec0title'];
                     FN_update_course($course);
                     $cm->course = $course->id;
                 } else {
                     if (isset($_GET['openchat'])) {
                         if ($varrec = get_record('course_config_FN', 'courseid', $this->course->id, 'variable', 'classchatopen')) {
                             $varrec->value = $_GET['openchat'];
                             update_record('course_config_fn', $varrec);
                         } else {
                             $varrec->courseid = $this->course->id;
                             $varrec->variable = 'classchatopen';
                             $varrec->value = $_GET['openchat'];
                             insert_record('course_config_fn', $varrec);
                         }
                         $this->course->classchatopen = $varrec->value;
                         $cm->course = $tgis->course->id;
                     }
                 }
             }
         }
     }
 }