]> git.mjollnir.org Git - moodle.git/commitdiff
add code to redirect to modedit.php from course/mod.php for activities adding / updat...
authorjamiesensei <jamiesensei>
Thu, 9 Nov 2006 18:25:58 +0000 (18:25 +0000)
committerjamiesensei <jamiesensei>
Thu, 9 Nov 2006 18:25:58 +0000 (18:25 +0000)
migrated chat/mod.html to formslib definition of form is in chat/mod_form.php

course/lib.php
course/mod.php
course/modedit.php [new file with mode: 0644]
lang/en_utf8/form.php
mod/chat/lib.php
mod/chat/mod.html [deleted file]
mod/chat/mod_form.php [new file with mode: 0644]

index 5d866acf93be7ac599d603fd641c9c4ca4b0068f..b0cb1f681d0b4cf2cccd03691933368a784d384a 100644 (file)
@@ -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 ("<br?>", " ",$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 '<div class="newusers">';
         if (! $heading) {
-            print_headline(get_string("newusers").':', 3);      
+            print_headline(get_string("newusers").':', 3);
             $heading = true;
             $content = true;
         }
         echo "<ol class=\"list\">\n";
         foreach ($users as $user) {
-            
+
             $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
             echo '<li class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
         }
@@ -1201,7 +1201,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
         }
     } elseif ($ismoving) {
         echo "<ul class=\"section\">\n";
-    }    
+    }
     if ($ismoving) {
         echo '<li><a title="'.$strmovefull.'"'.
              ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
@@ -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.'</a></b><br />';
 
-    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 '<tr valign="top">';
     echo '<td align="right"><b>'.get_string('visible', '').':</b></td>';
     echo '<td align="left">';
@@ -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 '</td></tr>';
-} 
+}
 
 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;
 }
 
index 5df2b31d206da41a225b5ece6878faa02e51203b..44d95b361b74ebe1bbe55ad578c11d748c5658bb 100644 (file)
         }
     }
 
+    //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&section=$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";
         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");
         }
             $pageheading = get_string("updatinga", "moodle", $fullmodulename);
         }
         $strnav = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">".format_string($form->name,true)."</a> ->";
-        
+
         if ($module->name == 'resource') {
             $CFG->pagepath = 'mod/'.$module->name.'/'.$form->type;
         } else {
         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 (! $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 (file)
index 0000000..502ac54
--- /dev/null
@@ -0,0 +1,287 @@
+<?php // $Id$
+
+//  adds or updates modules in a course using new formslib
+
+    require("../config.php");
+    require("lib.php");
+
+    require_login();
+
+    $add           = optional_param('add', '', PARAM_ALPHA);
+    $update        = optional_param('update', 0, PARAM_INT);
+
+    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");
+        }
+
+        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");
+        }
+
+        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 = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">".format_string($form->name,true)."</a> ->";
+    }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, '',
+         "<a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
+         $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 = '<img align="middle" height="16" width="16" src="'.$CFG->modpixpath.'/'.$module->name.'/icon.gif" alt="" style="vertical-align: middle;" />&nbsp;';
+
+        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
index 62d16eb71c3d30375c446b72d8c02d39fa6e4830..d41afd043acf8663309bc84be64e5e4ebda255ff 100644 (file)
@@ -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';
 ?>
index d69c9510dc2edbea290e43317b56f61dd003c7cd..edd2f725e5239d113052ce3e0eb0ee67e3297b56 100644 (file)
@@ -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 (file)
index 5eb226b..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php  // $Id$
-    if (!isset($form->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;
-    }
-?>
-<form name="form" method="post" action="mod.php">
-<table cellpadding="5">
-<tr valign="top">
-    <td align="right"><b><?php print_string('chatname', 'chat')?>:</b></td>
-    <td>
-        <input type="text" name="name" size="30" value="<?php p($form->name) ?>" alt="<?php print_string('chatname', 'chat') ?>" />
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right"><b><?php print_string('chatintro', 'chat')?>:</b><br /><br />
-     <?php
-        helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
-        echo '<br />';
-        helpbutton('questions', get_string('helpquestions'), 'moodle', true, true);
-        echo '<br />';
-        emoticonhelpbutton('form', 'intro');
-        echo '<br />';
-      ?>
-    </td>
-    <td>
-        <?php print_textarea($usehtmleditor, 20, 50, 680, 400, 'intro', $form->intro); ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right"><b><?php print_string('chattime', 'chat') ?>:</b></td>
-    <td><?php
-           print_date_selector('chatday', 'chatmonth', 'chatyear', $form->chattime);
-           echo '&nbsp;-&nbsp;';
-           print_time_selector('chathour', 'chatminute', $form->chattime);
-    ?></td>
-</tr>
-<tr valign="top">
-    <td align="right"><b><?php print_string('repeattimes', 'chat') ?>:</b></td>
-    <td><?php
-       unset($options);
-       $options[0]  = get_string('donotusechattime', 'chat');
-       $options[1]  = get_string('repeatnone', 'chat');
-       $options[2]  = get_string('repeatdaily', 'chat');
-       $options[3]  = get_string('repeatweekly', 'chat');
-       choose_from_menu ($options, 'schedule', $form->schedule, '', '', '');
-    ?></td>
-</tr>
-<tr valign="top">
-  <td align="right"><b><?php print_string('savemessages', 'chat')?>:</b></td>
-  <td>
-    <?php 
-       unset($options);
-       $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);
-
-       choose_from_menu ($options, 'keepdays', $form->keepdays, '', '', '');
-    ?>
-    </td>
-</tr>
-<tr valign="top">
-  <td align="right"><b><?php print_string('studentseereports', 'chat')?>:</b></td>
-  <td>
-    <?php 
-       unset($options);
-       $options[0]    = get_string('no');
-       $options[1]    = get_string('yes');
-       choose_from_menu ($options, 'studentlogs', $form->studentlogs, '', '', '');
-    ?>
-    </td>
-</tr>
-<?php print_standard_coursemodule_settings($form); ?>
-</table>
-<center>
-<input type="hidden" name="course"     value="<?php  p($form->course) ?>" />
-<input type="hidden" name="sesskey"    value="<?php  p($form->sesskey) ?>" />
-<input type="hidden" name="coursemodule"  value="<?php  p($form->coursemodule) ?>" />
-<input type="hidden" name="section"    value="<?php  p($form->section) ?>" />
-<input type="hidden" name="module"     value="<?php  p($form->module) ?>" />
-<input type="hidden" name="modulename" value="<?php  p($form->modulename) ?>" />
-<input type="hidden" name="instance"   value="<?php  p($form->instance) ?>" />
-<input type="hidden" name="mode"       value="<?php  p($form->mode) ?>" />
-<input type="submit" value="<?php  print_string('savechanges') ?>" />
-<input type="submit" name="cancel" value="<?php  print_string('cancel') ?>" />
-</center>
-</form> 
\ No newline at end of file
diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php
new file mode 100644 (file)
index 0000000..2938dd7
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+require_once ($CFG->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