Permalink
Browse files

A big clean up of all the forum functions (including renaming them all

to start with forum_ ) and all the follow-on effects that caused
Some miscellaneous bug fixes and code clean-ups along the way
  • Loading branch information...
1 parent 2199955 commit 11b0c469715d411399f609aa3cc52b8c312b5662 martin committed Aug 1, 2002
Showing with 378 additions and 401 deletions.
  1. +218 −0 course/lib.php
  2. +0 −220 course/mod.php
  3. +19 −26 course/social.php
  4. +3 −3 course/topics.php
  5. +3 −3 course/weeks.php
  6. +3 −3 index.php
  7. +2 −2 mod/forum/discuss.php
  8. +102 −116 mod/forum/lib.php
  9. +20 −20 mod/forum/post.php
  10. +1 −1 mod/forum/search.php
  11. +1 −1 mod/forum/subscribe.php
  12. +5 −5 mod/forum/view.php
  13. +1 −1 user/view.php
View
@@ -425,4 +425,222 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
}
+
+
+/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
+
+function add_course_module($mod) {
+ GLOBAL $db;
+
+ $timenow = time();
+
+ if (!$rs = $db->Execute("INSERT into course_modules
+ SET course = '$mod->course',
+ module = '$mod->module',
+ instance = '$mod->instance',
+ section = '$mod->section',
+ added = '$timenow' ")) {
+ return 0;
+ }
+
+ // Get it out again - this is the most compatible way to determine the ID
+ if ($rs = $db->Execute("SELECT id FROM course_modules
+ WHERE module = $mod->module AND added = $timenow")) {
+ return $rs->fields[0];
+ } else {
+ return 0;
+ }
+
+}
+
+function add_mod_to_section($mod) {
+// Returns the course_sections ID where the mod is inserted
+ GLOBAL $db;
+
+ if ($cw = get_record_sql("SELECT * FROM course_sections
+ WHERE course = '$mod->course' AND section = '$mod->section'") ) {
+
+ if ($cw->sequence) {
+ $newsequence = "$cw->sequence,$mod->coursemodule";
+ } else {
+ $newsequence = "$mod->coursemodule";
+ }
+ if (!$rs = $db->Execute("UPDATE course_sections SET sequence = '$newsequence' WHERE id = '$cw->id'")) {
+ return 0;
+ } else {
+ return $cw->id; // Return course_sections ID that was used.
+ }
+
+ } else { // Insert a new record
+ if (!$rs = $db->Execute("INSERT into course_sections
+ SET course = '$mod->course',
+ section = '$mod->section',
+ summary = '',
+ sequence = '$mod->coursemodule' ")) {
+ return 0;
+ }
+ // Get it out again - this is the most compatible way to determine the ID
+ if ($rs = $db->Execute("SELECT id FROM course_sections
+ WHERE course = '$mod->course' AND section = '$mod->section'")) {
+ return $rs->fields[0];
+ } else {
+ return 0;
+ }
+ }
+}
+
+function delete_course_module($mod) {
+ return set_field("course_modules", "deleted", 1, "id", $mod);
+}
+
+function delete_mod_from_section($mod, $section) {
+ GLOBAL $db;
+
+ if ($cw = get_record("course_sections", "id", "$section") ) {
+
+ $modarray = explode(",", $cw->sequence);
+
+ if ($key = array_keys ($modarray, $mod)) {
+ array_splice($modarray, $key[0], 1);
+ $newsequence = implode(",", $modarray);
+ return set_field("course_sections", "sequence", $newsequence, "id", $cw->id);
+ } else {
+ return false;
+ }
+
+ } else {
+ return false;
+ }
+}
+
+
+function move_module($id, $move) {
+ GLOBAL $db;
+
+ if (!$move) {
+ return true;
+ }
+
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("This course module doesn't exist");
+ }
+
+ if (! $thissection = get_record("course_sections", "id", $cm->section)) {
+ error("This course section doesn't exist");
+ }
+
+ $mods = explode(",", $thissection->sequence);
+
+ $len = count($mods);
+ $pos = array_keys($mods, $cm->id);
+ $thepos = $pos[0];
+
+ if ($len == 0 || count($pos) == 0 ) {
+ error("Very strange. Could not find the required module in this section.");
+ }
+
+ if ($len == 1) {
+ $first = true;
+ $last = true;
+ } else {
+ $first = ($thepos == 0);
+ $last = ($thepos == $len - 1);
+ }
+
+ if ($move < 0) { // Moving the module up
+
+ if ($first) {
+ if ($thissection->section == 1) { // First section, do nothing
+ return true;
+ } else { // Push onto end of previous section
+ $prevsectionnumber = $thissection->section - 1;
+ if (! $prevsection = get_record_sql("SELECT * FROM course_sections
+ WHERE course='$thissection->course'
+ AND section='$prevsectionnumber' ")) {
+ error("Previous section ($prevsection->id) doesn't exist");
+ }
+
+ if ($prevsection->sequence) {
+ $newsequence = "$prevsection->sequence,$cm->id";
+ } else {
+ $newsequence = "$cm->id";
+ }
+
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
+ error("Previous section could not be updated");
+ }
+
+ if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
+ error("Module could not be updated");
+ }
+
+ array_splice($mods, 0, 1);
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("Module could not be updated");
+ }
+
+ return true;
+
+ }
+ } else { // move up within this section
+ $swap = $mods[$thepos-1];
+ $mods[$thepos-1] = $mods[$thepos];
+ $mods[$thepos] = $swap;
+
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+ }
+
+ } else { // Moving the module down
+
+ if ($last) {
+ $nextsectionnumber = $thissection->section + 1;
+ if ($nextsection = get_record_sql("SELECT * FROM course_sections
+ WHERE course='$thissection->course'
+ AND section='$nextsectionnumber' ")) {
+
+ if ($nextsection->sequence) {
+ $newsequence = "$cm->id,$nextsection->sequence";
+ } else {
+ $newsequence = "$cm->id";
+ }
+
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
+ error("Next section could not be updated");
+ }
+
+ if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
+ error("Module could not be updated");
+ }
+
+ array_splice($mods, $thepos, 1);
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+
+ } else { // There is no next section, so just return
+ return true;
+
+ }
+ } else { // move down within this section
+ $swap = $mods[$thepos+1];
+ $mods[$thepos+1] = $mods[$thepos];
+ $mods[$thepos] = $swap;
+
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+ }
+ }
+}
+
+
?>
Oops, something went wrong.

0 comments on commit 11b0c46

Please sign in to comment.