diff --git a/course/format/topics.php b/course/format/topics.php
index 0ac240dd6fd..5709bab198b 100644
--- a/course/format/topics.php
+++ b/course/format/topics.php
@@ -92,6 +92,21 @@
echo "
";
+/// If currently moving a file then show the current clipboard
+ if (ismoving($course->id)) {
+ $stractivityclipboard = get_string("activityclipboard", "", addslashes($USER->activitycopyname));
+ $strcancel= get_string("cancel");
+ echo "";
+ echo "cellcontent\" class=\"topicoutlineclip\" width=\"100%\">";
+ echo " ";
+ echo "$stractivityclipboard ($strcancel)";
+ echo " ";
+ echo " | ";
+ echo "
";
+ echo " |
";
+ }
+
+
/// Print Section 0
$section = 0;
diff --git a/course/format/weeks.php b/course/format/weeks.php
index 9c9f7190988..92e31f63fd7 100644
--- a/course/format/weeks.php
+++ b/course/format/weeks.php
@@ -81,6 +81,20 @@
echo "";
+/// If currently moving a file then show the current clipboard
+ if (ismoving($course->id)) {
+ $stractivityclipboard = get_string("activityclipboard", "", addslashes($USER->activitycopyname));
+ $strcancel= get_string("cancel");
+ echo "";
+ echo "cellcontent\" class=\"weeklyoutlineclip\" width=\"100%\">";
+ echo " ";
+ echo "$stractivityclipboard ($strcancel)";
+ echo " ";
+ echo " | ";
+ echo "
";
+ echo " |
";
+ }
+
/// Print Section 0 with general activities
$section = 0;
diff --git a/course/lib.php b/course/lib.php
index ebcdb27d1eb..4a99cec357e 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -579,15 +579,12 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod
}
$mod = $mods[$modnumber];
if ($isediting) {
- $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible);
+ $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible, false);
}
if ($mod->visible or $isteacher) {
$instancename = urldecode($modinfo[$modnumber]->name);
- if ($mod->visible) {
- $link_css = "";
- } else {
- $link_css = " class=\"dimmed\" ";
- }
+ $link_css = $mod->visible ? "" : " class=\"dimmed\" ";
+
$modicon[] = "
wwwroot/mod/$mod->modname/icon.gif\"".
" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
$moddata[] = "modfullname\" $link_css ".
@@ -610,9 +607,13 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
/// Prints a section full of activity modules
- global $CFG;
+ global $CFG, $USER;
+
static $isteacher;
static $isediting;
+ static $ismoving;
+ static $strmovehere;
+ static $strmovefull;
if (!isset($isteacher)) {
$isteacher = isteacher($course->id);
@@ -620,6 +621,13 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
if (!isset($isediting)) {
$isediting = isediting($course->id);
}
+ if (!isset($ismoving)) {
+ $ismoving = ismoving($course->id);
+ }
+ if ($ismoving) {
+ $strmovehere = get_string("movehere");
+ $strmovefull = get_string("movefull", "", "'$USER->activitycopyname'");
+ }
$modinfo = unserialize($course->modinfo);
@@ -634,12 +642,15 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
}
$mod = $mods[$modnumber];
if ($mod->visible or $isteacher) {
- $instancename = urldecode($modinfo[$modnumber]->name);
- if ($mod->visible) {
- $link_css = "";
- } else {
- $link_css = " class=\"dimmed\" ";
+ if ($ismoving) {
+ if ($mod->id == $USER->activitycopy) {
+ continue;
+ }
+ echo " -> id\">$strmovehere
\n";
}
+ $instancename = urldecode($modinfo[$modnumber]->name);
+ $link_css = $mod->visible ? "" : " class=\"dimmed\" ";
echo "
wwwroot/mod/$mod->modname/icon.gif\"".
" height=16 width=16 alt=\"$mod->modfullname\">".
" modfullname\" $link_css ".
@@ -654,6 +665,10 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
}
}
}
+ if ($ismoving) {
+ echo " -> id\">$strmovehere
\n";
+ }
echo "
\n\n";
}
@@ -961,16 +976,36 @@ function add_course_module($mod) {
return insert_record("course_modules", $mod);
}
-function add_mod_to_section($mod) {
-// Returns the course_sections ID where the mod is inserted
- GLOBAL $db;
+function add_mod_to_section($mod, $beforemod=NULL) {
+/// Given a full mod object with section and course already defined
+/// If $before is specified, then this is an existing ID which we
+/// will insert the new module before
+///
+/// Returns the course_sections ID where the mod is inserted
if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
- if (!empty($section->sequence)) {
- $newsequence = "$section->sequence,$mod->coursemodule";
- } else {
+
+ $section->sequence = trim($section->sequence);
+
+ if (empty($section->sequence)) {
$newsequence = "$mod->coursemodule";
+
+ } else if ($beforemod) {
+ $modarray = explode(",", $section->sequence);
+
+ if ($key = array_keys ($modarray, $beforemod->id)) {
+ $insertarray = array($mod->id, $beforemod->id);
+ array_splice($modarray, $key[0], 1, $insertarray);
+ $newsequence = implode(",", $modarray);
+
+ } else { // Just tack it on the end anyway
+ $newsequence = "$section->sequence,$mod->coursemodule";
+ }
+
+ } else {
+ $newsequence = "$section->sequence,$mod->coursemodule";
}
+
if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
return $section->id; // Return course_sections ID that was used.
} else {
@@ -1012,9 +1047,8 @@ function delete_mod_from_section($mod, $section) {
return false;
}
- } else {
- return false;
}
+ return false;
}
function move_section($course, $section, $move) {
@@ -1051,6 +1085,43 @@ function move_section($course, $section, $move) {
}
+function moveto_module($mod, $section, $beforemod=NULL) {
+/// All parameters are objects
+/// Move the module object $mod to the specified $section
+/// If $beforemod exists then that is the module
+/// before which $modid should be inserted
+
+/// Remove original module from original section
+
+ if (! delete_mod_from_section($mod->id, $mod->section)) {
+ notify("Could not delete module from existing section");
+ }
+
+/// Update module itself if necessary
+
+ if ($mod->section != $section->id) {
+ $mod->section = $section->id;
+
+ if (!update_record("course_modules", $mod)) {
+ return false;
+ }
+ }
+
+/// Add the module into the new section
+
+ $mod->course = $section->course;
+ $mod->section = $section->section; // need relative reference
+ $mod->coursemodule = $mod->id;
+
+ if (! add_mod_to_section($mod, $beforemod)) {
+ return false;
+ }
+
+ return true;
+
+}
+
+
function move_module($cm, $move) {
/// Moves an activity module up and down within the course
@@ -1175,7 +1246,7 @@ function move_module($cm, $move) {
}
}
-function make_editing_buttons($moduleid, $absolute=false, $visible=true) {
+function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true) {
global $CFG, $THEME;
static $str = '';
@@ -1186,6 +1257,7 @@ function make_editing_buttons($moduleid, $absolute=false, $visible=true) {
$str->update = get_string("update");
$str->hide = get_string("hide");
$str->show = get_string("show");
+ $str->move = get_string("move");
}
if ($absolute) {
@@ -1201,21 +1273,26 @@ function make_editing_buttons($moduleid, $absolute=false, $visible=true) {
}
if ($visible) {
- $hideshow = " hide\" href=\"$path/mod.php?hide=$moduleid\">
";
+ $hideshow = "hide\" href=\"$path/mod.php?hide=$moduleid\">
";
} else {
- $hideshow = " show\" href=\"$path/mod.php?show=$moduleid\">
";
+ $hideshow = "show\" href=\"$path/mod.php?show=$moduleid\">
";
}
- return "delete\" href=\"$path/mod.php?delete=$moduleid\">
- moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\">
- movedown\" href=\"$path/mod.php?id=$moduleid&move=1\">
- update\" href=\"$path/mod.php?update=$moduleid\">
$hideshow";
+ if ($moveselect) {
+ $move = "move\" href=\"$path/mod.php?copy=$moduleid\">
";
+ }
+
+ return "delete\" href=\"$path/mod.php?delete=$moduleid\">
".
+ "moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\">
".
+ "movedown\" href=\"$path/mod.php?id=$moduleid&move=1\">
$move".
+ "update\" href=\"$path/mod.php?update=$moduleid\">
$hideshow";
}
?>
diff --git a/course/mod.php b/course/mod.php
index 4355ebd3f45..cda0b8c77c7 100644
--- a/course/mod.php
+++ b/course/mod.php
@@ -15,7 +15,7 @@
} else {
redirect("view.php?id=$mod->course");
}
- }
+ }
if (isset($_POST["course"])) { // add or update form submitted
@@ -127,6 +127,50 @@
}
exit;
+ } else if (isset($movetosection) or isset($moveto)) {
+
+ if (! $cm = get_record("course_modules", "id", $USER->activitycopy)) {
+ error("The copied course module doesn't exist!");
+ }
+
+ if (isset($movetosection)) {
+ if (! $section = get_record("course_sections", "id", $movetosection)) {
+ error("This section doesn't exist");
+ }
+ $beforecm = NULL;
+
+ } else { // normal moveto
+ if (! $beforecm = get_record("course_modules", "id", $moveto)) {
+ error("The destination course module doesn't exist");
+ }
+ if (! $section = get_record("course_sections", "id", $beforecm->section)) {
+ error("This section doesn't exist");
+ }
+ }
+
+ if (!isteacher($section->course)) {
+ error("You can't modify this course!");
+ }
+
+ if (!ismoving($section->course)) {
+ error("You need to copy something first!");
+ }
+
+ moveto_module($cm, $section, $beforecm);
+
+ unset($USER->activitycopy);
+ unset($USER->activitycopycourse);
+ unset($USER->activitycopyname);
+
+ rebuild_course_cache($section->course);
+
+ $site = get_site();
+ if ($site->id == $section->course) {
+ redirect($CFG->wwwroot);
+ } else {
+ redirect("view.php?id=$section->course");
+ }
+
} else if (isset($hide)) {
if (! $cm = get_record("course_modules", "id", $hide)) {
@@ -181,6 +225,44 @@
}
exit;
+ } else if (isset($copy)) { // value = course module
+
+ if (! $cm = get_record("course_modules", "id", $copy)) {
+ error("This course module doesn't exist");
+ }
+
+ if (!isteacher($cm->course)) {
+ error("You can't modify this course!");
+ }
+
+ if (! $section = get_record("course_sections", "id", $cm->section)) {
+ error("This module doesn't exist");
+ }
+
+ if (! $module = get_record("modules", "id", $cm->module)) {
+ error("This module doesn't exist");
+ }
+
+ if (! $instance = get_record($module->name, "id", $cm->instance)) {
+ error("Could not find the instance of this module");
+ }
+
+ $USER->activitycopy = $copy;
+ $USER->activitycopycourse = $cm->course;
+ $USER->activitycopyname = $instance->name;
+
+ redirect("view.php?id=$cm->course");
+
+ } else if (isset($cancelcopy)) { // value = course module
+
+ $courseid = $USER->activitycopycourse;
+
+ unset($USER->activitycopy);
+ unset($USER->activitycopycourse);
+ unset($USER->activitycopyname);
+
+ redirect("view.php?id=$courseid");
+
} else if (isset($delete)) { // value = course module
if (! $cm = get_record("course_modules", "id", $delete)) {
diff --git a/lang/en/moodle.php b/lang/en/moodle.php
index 3aa62257fd1..074a4600f1f 100644
--- a/lang/en/moodle.php
+++ b/lang/en/moodle.php
@@ -6,9 +6,11 @@ $string['thischarset'] = "iso-8859-1"; // The best charset to use for this lang
$string['action'] = "Action";
$string['activities'] = "Activities";
$string['activity'] = "Activity";
+$string['activityclipboard'] = "Moving this activity: \$a";
$string['activityiscurrentlyhidden'] = "Sorry, this activity is currently hidden";
$string['activitymodule'] = "Activity module";
$string['activityreport'] = "Activity report";
+$string['activityselect'] = "Select this activity to be moved elsewhere";
$string['activitysince'] = "Activity since \$a";
$string['add'] = "Add";
$string['added'] = "Added \$a";
@@ -411,7 +413,10 @@ $string['modulesetup'] = "Setting up module tables";
$string['modulesuccess'] = "\$a tables have been set up correctly";
$string['moodleversion'] = "Moodle Version";
$string['mostrecently'] = "most recently";
+$string['move'] = "Move";
$string['movedown'] = "Move down";
+$string['movefull'] = "Move \$a to this location";
+$string['movehere'] = "Move to here";
$string['moveup'] = "Move up";
$string['movetoanotherfolder'] = "Move to another folder";
$string['movefilestohere'] = "Move files to here";
@@ -677,4 +682,6 @@ $string['yourlastlogin'] = "Your last login was";
$string['yourself'] = "yourself";
$string['yourteacher'] = "your \$a";
+
+
?>
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 3103352cf01..b5012eccfa5 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -468,6 +468,16 @@ function isediting($courseid, $user=NULL) {
return ($user->editing and isteacher($courseid, $user->id));
}
+function ismoving($courseid) {
+/// Is the current user currently moving an activity?
+ global $USER;
+
+ if (!empty($USER->activitycopy)) {
+ return ($USER->activitycopycourse == $courseid);
+ }
+ return false;
+}
+
function set_moodle_cookie($thing) {
/// Sets a moodle cookie with an encrypted string
diff --git a/pix/t/move.gif b/pix/t/move.gif
new file mode 100755
index 00000000000..5878e20f8f0
Binary files /dev/null and b/pix/t/move.gif differ