Skip to content

Commit

Permalink
Allow moving courses and editing courses and stuff from the course re…
Browse files Browse the repository at this point in the history
…sults search page (now has turn editing on button)
  • Loading branch information
mjollnir_ committed Sep 1, 2005
1 parent f2f3893 commit 861efb1
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 45 deletions.
38 changes: 10 additions & 28 deletions course/category.php
Expand Up @@ -132,35 +132,14 @@
error("Error finding the category");
}

unset($data->moveto);
unset($data->id);
unset($data->sesskey);

if ($data) {
foreach ($data as $code => $junk) {

$courseid = substr($code, 1);

if (! record_exists('course', 'id', $courseid)) {
notify('Error finding a course');
} else {
// figure out a sortorder that we can use in the destination category
$sortorder = get_field_sql('SELECT MIN(sortorder)-1 AS min
FROM ' . $CFG->prefix . 'course WHERE category=' . $destcategory->id) || 1000;

$newcourse = new stdClass;
$newcourse->id = $courseid;
$newcourse->category = $destcategory->id;
$newcourse->sortorder = $sortorder;

if (!update_record('course', $newcourse)) {
notify("An error occurred - course not moved!");
}
fix_course_sortorder();
}

$courses = array();
foreach ( $data as $key => $value ) {
if (preg_match('/^c\d+$/', $key)) {
array_push($courses, substr($key, 1));
}
$category = get_record('course_categories', 'id', $category->id); // Refresh it
}
}
move_courses($courses, $data->moveto);
}

/// Hide or show a course
Expand Down Expand Up @@ -430,6 +409,9 @@
echo '<input type="submit" value="'.$strrename.'" />';
echo "</form>";
echo "<br />";

print_course_search();

}
echo "</center>";

Expand Down
56 changes: 55 additions & 1 deletion course/lib.php
Expand Up @@ -1400,7 +1400,7 @@ function print_courses($category, $width="100%") {

function print_course($course, $width="100%") {

global $CFG;
global $CFG, $USER;

static $enrol;

Expand Down Expand Up @@ -1962,4 +1962,58 @@ function course_allowed_module($course,$mod) {
return (record_exists("course_allowed_modules","course",$course->id,"module",$modid));
}

/***
*** Efficiently moves many courses around while maintaining
*** sortorder in order.
***
*** $courseids is an array of course ids
***
**/

function move_courses ($courseids, $categoryid) {

global $CFG;

if (!empty($courseids)) {

$courseids = array_reverse($courseids);

foreach ($courseids as $courseid) {

if (! $course = get_record("course", "id", $courseid)) {
notify("Error finding course $courseid");
} else {
// figure out a sortorder that we can use in the destination category
$sortorder = get_field_sql('SELECT MIN(sortorder)-1 AS min
FROM ' . $CFG->prefix . 'course WHERE category=' . $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()
$sortorder = 200;
} else if ($sortorder < 10) {
fix_course_sortorder($categoryid);
}

$course->category = $categoryid;
$course->sortorder = $sortorder;
$course->fullname = addslashes($course->fullname);
$course->shortname = addslashes($course->shortname);
$course->summary = addslashes($course->summary);
$course->password = addslashes($course->password);
$course->teacher = addslashes($course->teacher);
$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;
}

?>
148 changes: 134 additions & 14 deletions course/search.php
Expand Up @@ -27,6 +27,26 @@
require_login();
}

if (iscreator()) {
if (isset($_GET['edit']) and confirm_sesskey()) {
if ($edit == "on") {
$USER->categoriessearchediting = true;
} else if ($edit == "off") {
$USER->categoriessearchediting = false;
}

print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&perpage=$perpage&");

}

$creatorediting = !empty($USER->categoriessearchediting);
$adminediting = (isadmin() and $creatorediting);
}

if ($adminediting && $perpage != 99999) {
$perpage = 30;
}

$displaylist = array();
$parentlist = array();
make_categories_list($displaylist, $parentlist, "");
Expand All @@ -35,6 +55,10 @@
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
$strcategory = get_string("category");
$strselect = get_string("select");
$strselectall = get_string("selectall");
$strdeselectall = get_string("deselectall");
$stredit = get_string("edit");

if (!$search) {
print_header("$site->fullname : $strsearch", $site->fullname,
Expand All @@ -52,32 +76,128 @@
exit;
}

if (isset($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved

if (! $destcategory = get_record("course_categories", "id", $data->moveto)) {
error("Error finding the category");
}

$courses = array();
foreach ( $data as $key => $value ) {
if (preg_match('/^c\d+$/', $key)) {
array_push($courses, substr($key, 1));
}
}
move_courses($courses, $data->moveto);
}

$courses = get_courses_search($searchterms, "fullname ASC",
$page*$perpage, $perpage, $totalcount);

$searchform = print_course_search($search, true, "navbar");

if (!empty($courses) && iscreator()) {
$searchform .= update_categories_search_button($search,$page,$perpage);
}


print_header("$site->fullname : $strsearchresults", $site->fullname,
"<a href=\"index.php\">$strcourses</a> -> <a href=\"search.php\">$strsearch</a> -> '$search'", "", "", "", $searchform);


$lastcategory = -1;
if ($courses = get_courses_search($searchterms, "fullname ASC",
$page*$perpage, $perpage, $totalcount)) {
if ($courses) {

print_heading("$strsearchresults: $totalcount");

print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&amp;perpage=$perpage&");

foreach ($courses as $course) {
$course->fullname = highlight("$search", $course->fullname);
$course->summary = highlight("$search", $course->summary);
$course->summary .= "<br /><p align=\"right\">";
$course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">";
$course->summary .= $displaylist[$course->category];
$course->summary .= "</a></p>";
print_course($course);
print_spacer(5,5);
if (!$adminediting) {
foreach ($courses as $course) {
$course->fullname = highlight("$search", $course->fullname);
$course->summary = highlight("$search", $course->summary);
$course->summary .= "<br /><p align=\"right\">";
$course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">";
$course->summary .= $displaylist[$course->category];
$course->summary .= "</a></p>";
print_course($course);
print_spacer(5,5);
}
} else { // slightly more sophisticated

$oldperpage = ($adminediting) ? 30 : 10;
print_paging_bar($totalcount, $page, $oldperpage, "search.php?search=$search&perpage=$perpage&",($perpage == 99999));

if ($perpage != 99999 && $totalcount > $perpage) {
echo "<center><p>";
echo "<a href=\"search.php?search=$search&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
echo "</p></center>";
}
echo "<form name=\"movecourses\" action=\"search.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\">";
echo "<input type=\"hidden\" name=\"search\" value=\"$search\">";
echo "<input type=\"hidden\" name=\"page\" value=\"$page\">";
echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\">";
echo "<table align=\"center\" border=0 cellspacing=2 cellpadding=4 class=\"generalbox\"><tr>";
echo "<th>$strcourses</th>";
echo "<th>$strcategory</th>";
echo "<th>$strselect</th>";
echo "<th>$stredit</th>";
foreach ($courses as $course) {
$course->fullname = highlight("$search", $course->fullname);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
echo "<tr>";
echo "<td><a $linkcss href=\"view.php?id=$course->id\">$course->fullname</a></td>";
echo "<td>".$displaylist[$course->category]."</td>";
echo "<td align=\"center\">";
echo "<input type=\"checkbox\" name=\"c$course->id\">";
echo "</td>";
echo "<td>";
if (empty($THEME->custompix)) {
$pixpath = "$CFG->wwwroot/pix";
} else {
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
}
echo "<a title=\"".get_string("settings")."\" href=\"$CFG->wwwroot/course/edit.php?id=$course->id\"><img".
" src=\"$pixpath/t/edit.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
echo "<a title=\"".get_string("assignteachers")."\" href=\"$CFG->wwwroot/course/teacher.php?id=$course->id\"><img".
" src=\"$pixpath/t/user.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
echo "<a title=\"".get_string("delete")."\" href=\"delete.php?id=$course->id\"><img".
" src=\"$pixpath/t/delete.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
if (!empty($course->visible)) {
echo "<a title=\"".get_string("hide")."\" href=\"category.php?id=$course->category&hide=$course->id&amp;sesskey=$USER->sesskey\"><img".
" src=\"$pixpath/t/hide.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
} else {
echo "<a title=\"".get_string("show")."\" href=\"category.php?id=$course->category&show=$course->id&amp;sesskey=$USER->sesskey\"><img".
" src=\"$pixpath/t/show.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
}

echo "<a title=\"".get_string("backup")."\" href=\"../backup/backup.php?id=$course->id\"><img".
" src=\"$pixpath/t/backup.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";

echo "<a title=\"".get_string("restore")."\" href=\"../files/index.php?id=$course->id&wdir=/backupdata\"><img".
" src=\"$pixpath/t/restore.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
echo "</td></tr>";
}
echo "<tr><td colspan=\"4\" align=\"center\">";
echo "<br />";
echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n";
echo "<input type=\"button\" onclick=\"uncheckall()\" value=\"$strdeselectall\" />\n";
choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript:document.movecourses.submit()");
echo "</td></tr>";
echo "</table>";

print_paging_bar($totalcount, $page, $oldperpage, "search.php?search=$search&perpage=30&",($perpage == 99999));


if ($perpage != 99999 && $totalcount > $perpage) {
echo "<center><p>";
echo "<a href=\"search.php?search=$search&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
echo "</p></center>";
}

}

print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&amp;perpage=$perpage&");



} else {
print_heading(get_string("nocoursesfound", "", $search));
Expand Down
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Expand Up @@ -309,6 +309,7 @@
$string['deletingolddata'] = 'Deleting old data';
$string['department'] = 'Department';
$string['description'] = 'Description';
$string['deselectall'] = 'Deselect all';
$string['detailedless'] = 'Less detailed';
$string['detailedmore'] = 'More detailed';
$string['directorypaths'] = 'Directory Paths';
Expand Down Expand Up @@ -985,6 +986,7 @@
$string['sections'] = 'Sections';
$string['seealsostats'] = 'See also: stats';
$string['select'] = 'Select';
$string['selectall'] = 'Select all';
$string['selectacountry'] = 'Select a country';
$string['selectednowmove'] = '$a files selected for moving. Now go to the destination and press \'Move files to here\'';
$string['senddetails'] = 'Send my details via email';
Expand Down
7 changes: 7 additions & 0 deletions lib/javascript.php
Expand Up @@ -33,6 +33,13 @@ function openpopup(url,name,options,fullscreen) {
return false;
}

function uncheckall() {
void(d=document);
void(el=d.getElementsByTagName('INPUT'));
for(i=0;i<el.length;i++)
void(el[i].checked=0)
}

function inserttext(text) {
<?php
if (!empty($SESSION->inserttextform)) {
Expand Down
31 changes: 29 additions & 2 deletions lib/weblib.php
Expand Up @@ -3210,6 +3210,33 @@ function update_categories_button() {
}
}

/**
* Prints the editing button on search results listing
* For bulk move courses to another category
*/

function update_categories_search_button($search,$page,$perpage) {
global $CFG, $USER;

if (isadmin()) {
if (!empty($USER->categoriessearchediting)) {
$string = get_string("turneditingoff");
$edit = "off";
$perpage = 30;
} else {
$string = get_string("turneditingon");
$edit = "on";
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/search.php\">".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />".
"<input type=\"hidden\" name=\"search\" value=\"$search\" />".
"<input type=\"hidden\" name=\"page\" value=\"$page\" />".
"<input type=\"hidden\" name=\"perpage\" value=\"$perpage\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
}

/**
* Prints the editing button on group page
*
Expand Down Expand Up @@ -4022,7 +4049,7 @@ function obfuscate_mailto($email, $label='', $dimmed=false) {
var an equal sign, then the page number.
* @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
*/
function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page') {
function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false) {

$maxdisplay = 18;

Expand All @@ -4044,7 +4071,7 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page
$displaycount = 0;
while ($displaycount < $maxdisplay and $currpage < $lastpage) {
$displaypage = $currpage+1;
if ($page == $currpage) {
if ($page == $currpage && empty($nocurr)) {
echo '&nbsp;&nbsp;'. $displaypage;
} else {
echo '&nbsp;&nbsp;<a href="'. $baseurl . $pagevar .'='. $currpage .'">'. $displaypage .'</a>';
Expand Down

0 comments on commit 861efb1

Please sign in to comment.