mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
Arbitrary moving of activities (aka cut and paste)
Some of this code was sent by Howard Miller, but I rewrote most of it to make it shorter and to fit in better with current code.
This commit is contained in:
parent
29ee5550d3
commit
7977cffdb0
@ -92,6 +92,21 @@
|
||||
|
||||
echo "<table class=\"topicsoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
|
||||
|
||||
/// 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 "<tr>";
|
||||
echo "<td colspan=3 valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicoutlineclip\" width=\"100%\">";
|
||||
echo "<p><font size=2>";
|
||||
echo "$stractivityclipboard (<a href=\"mod.php?cancelcopy=true\">$strcancel</a>)";
|
||||
echo "</font></p>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
|
||||
}
|
||||
|
||||
|
||||
/// Print Section 0
|
||||
|
||||
$section = 0;
|
||||
|
@ -81,6 +81,20 @@
|
||||
|
||||
echo "<table class=\"weeklyoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
|
||||
|
||||
/// 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 "<tr>";
|
||||
echo "<td colspan=3 valign=top bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlineclip\" width=\"100%\">";
|
||||
echo "<p><font size=2>";
|
||||
echo "$stractivityclipboard (<a href=\"mod.php?cancelcopy=true\">$strcancel</a>)";
|
||||
echo "</font></p>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
|
||||
}
|
||||
|
||||
/// Print Section 0 with general activities
|
||||
|
||||
$section = 0;
|
||||
|
143
course/lib.php
143
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[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"".
|
||||
" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
|
||||
$moddata[] = "<a title=\"$mod->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 "<font size=\"2\"> -> <a title=\"$strmovefull\"".
|
||||
" href=\"mod.php?moveto=$mod->id\">$strmovehere</a></font><br />\n";
|
||||
}
|
||||
$instancename = urldecode($modinfo[$modnumber]->name);
|
||||
$link_css = $mod->visible ? "" : " class=\"dimmed\" ";
|
||||
echo "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"".
|
||||
" height=16 width=16 alt=\"$mod->modfullname\">".
|
||||
" <font size=2><a title=\"$mod->modfullname\" $link_css ".
|
||||
@ -654,6 +665,10 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($ismoving) {
|
||||
echo "<font size=\"2\"> -> <a title=\"$strmovefull\"".
|
||||
" href=\"mod.php?movetosection=$section->id\">$strmovehere</a></font><br />\n";
|
||||
}
|
||||
echo "</td></tr></table><br />\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 = " <a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img
|
||||
src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a>";
|
||||
$hideshow = "<a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img".
|
||||
" src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a> ";
|
||||
} else {
|
||||
$hideshow = " <a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img
|
||||
src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a>";
|
||||
$hideshow = "<a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img".
|
||||
" src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a> ";
|
||||
}
|
||||
|
||||
return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img
|
||||
src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a>
|
||||
<a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img
|
||||
src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a>
|
||||
<a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img
|
||||
src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a>
|
||||
<a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img
|
||||
src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow";
|
||||
if ($moveselect) {
|
||||
$move = "<a title=\"$str->move\" href=\"$path/mod.php?copy=$moduleid\"><img".
|
||||
" src=\"$pixpath/t/move.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
|
||||
}
|
||||
|
||||
return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img".
|
||||
" src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a> ".
|
||||
"<a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img".
|
||||
" src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> ".
|
||||
"<a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img".
|
||||
" src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> $move".
|
||||
"<a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img".
|
||||
" src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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)) {
|
||||
|
@ -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: <b>\$a</b>";
|
||||
$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";
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
@ -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
|
||||
|
BIN
pix/t/move.gif
Executable file
BIN
pix/t/move.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 108 B |
Loading…
x
Reference in New Issue
Block a user