2003-07-30 13:02:45 +00:00
|
|
|
<?PHP // $Id$
|
2003-08-07 16:01:31 +00:00
|
|
|
// Displays the top level category or all courses
|
|
|
|
// In editing mode, allows the admin to edit a category,
|
|
|
|
// and rearrange courses
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
require_once("../config.php");
|
|
|
|
require_once("lib.php");
|
|
|
|
|
|
|
|
require_variable($id); // Category id
|
|
|
|
|
|
|
|
|
|
|
|
if (!$site = get_site()) {
|
|
|
|
error("Site isn't defined!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$category = get_record("course_categories", "id", $id)) {
|
|
|
|
error("Category not known!");
|
|
|
|
}
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (iscreator()) {
|
|
|
|
if (isset($_GET['edit'])) {
|
|
|
|
if ($edit == "on") {
|
|
|
|
$USER->editing = true;
|
|
|
|
} else if ($edit == "off") {
|
|
|
|
$USER->editing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$updatebutton = update_category_button($category->id);
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
$creatorediting = !empty($USER->editing);
|
|
|
|
$adminediting = (isadmin() and $creatorediting);
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
} else {
|
|
|
|
$updatebutton = "";
|
|
|
|
$adminediting = false;
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Rename the category if requested
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
if (!empty($rename)) {
|
|
|
|
$category->name = $rename;
|
|
|
|
if (! set_field("course_categories", "name", $category->name, "id", $category->id)) {
|
|
|
|
notify("An error occurred while renaming the category");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
|
|
|
|
/// Print headings
|
|
|
|
|
|
|
|
$numcategories = count_records("course_categories");
|
|
|
|
|
|
|
|
$stradministration = get_string("administration");
|
|
|
|
$strcategories = get_string("categories");
|
|
|
|
$strcategory = get_string("category");
|
|
|
|
$strcourses = get_string("courses");
|
|
|
|
$strcoursemanagement = get_string("coursemanagement");
|
|
|
|
|
|
|
|
if ($creatorediting) {
|
|
|
|
if ($adminediting) {
|
|
|
|
print_header("$site->shortname: $category->name", "$site->fullname",
|
|
|
|
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
|
|
|
|
"<a href=\"index.php\">$strcoursemanagement</a> -> $category->name",
|
|
|
|
"", "", true, $updatebutton);
|
|
|
|
} else {
|
|
|
|
print_header("$site->shortname: $category->name", "$site->fullname",
|
|
|
|
"<a href=\"index.php\">$strcourses</a> -> $category->name", "", "", true, $updatebutton);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_header("$site->shortname: $category->name", "$site->fullname",
|
|
|
|
"<a href=\"index.php\">$strcourses</a> -> $category->name", "", "", true, $updatebutton);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
/// Print the category selector
|
|
|
|
|
|
|
|
$displaylist = array();
|
|
|
|
$parentlist = array();
|
|
|
|
|
|
|
|
make_categories_list($displaylist, $parentlist, "");
|
|
|
|
|
|
|
|
echo "<table align=center><tr><td>";
|
|
|
|
popup_form("category.php?id=", $displaylist, "switchcategory", "$category->id", "", "", "", false);
|
|
|
|
echo "</td></tr></table><br />";
|
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Editing functions
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if ($adminediting) {
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Move a specified course to a new category
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (isset($move) and isset($moveto)) {
|
|
|
|
if (! $course = get_record("course", "id", $move)) {
|
|
|
|
notify("Error finding the course");
|
|
|
|
} else if (! $destcategory = get_record("course_categories", "id", $moveto)) {
|
|
|
|
notify("Error finding the category");
|
|
|
|
} else {
|
|
|
|
if (!set_field("course", "category", $destcategory->id, "id", $course->id)) {
|
|
|
|
notify("An error occurred - course not moved!");
|
|
|
|
}
|
|
|
|
fix_course_sortorder($destcategory->id);
|
|
|
|
fix_course_sortorder($category->id);
|
|
|
|
$category = get_record("course_categories", "id", $category->id);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Hide or show a course
|
|
|
|
|
|
|
|
if (isset($hide) or isset($show)) {
|
|
|
|
if (isset($hide)) {
|
|
|
|
$course = get_record("course", "id", $hide);
|
|
|
|
$visible = 0;
|
|
|
|
} else {
|
|
|
|
$course = get_record("course", "id", $show);
|
|
|
|
$visible = 1;
|
|
|
|
}
|
|
|
|
if ($course) {
|
|
|
|
if (! set_field("course", "visible", $visible, "id", $course->id)) {
|
|
|
|
notify("Could not update that course!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Move a course up or down
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (isset($moveup) or isset($movedown)) {
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
$movecourse = NULL;
|
|
|
|
$swapcourse = NULL;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
$courses = get_courses($category->id);
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
if (isset($moveup)) {
|
2003-08-07 16:01:31 +00:00
|
|
|
if ($movecourse = get_record("course", "id", $moveup)) {
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
if ($course->id == $movecourse->id) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$swapcourse = $course;
|
|
|
|
}
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2003-08-07 16:01:31 +00:00
|
|
|
if (isset($movedown)) {
|
|
|
|
if ($movecourse = get_record("course", "id", $movedown)) {
|
|
|
|
$choosenext = false;
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
if ($choosenext) {
|
|
|
|
$swapcourse = $course;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($course->id == $movecourse->id) {
|
|
|
|
$choosenext = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($swapcourse and $movecourse) { // Renumber everything for robustness
|
|
|
|
$count=0;
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
$count++;
|
|
|
|
if ($course->id == $swapcourse->id) {
|
|
|
|
$course = $movecourse;
|
|
|
|
} else if ($course->id == $movecourse->id) {
|
|
|
|
$course = $swapcourse;
|
|
|
|
}
|
|
|
|
if (! set_field("course", "sortorder", $count, "id", $course->id)) {
|
|
|
|
notify("Could not update that course!");
|
|
|
|
}
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-07 16:01:31 +00:00
|
|
|
|
|
|
|
fix_course_sortorder($category->id);
|
|
|
|
|
|
|
|
} // End of editing stuff
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Print out all the courses
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (!$courses = get_courses($category->id)) {
|
2003-07-30 13:02:45 +00:00
|
|
|
print_heading(get_string("nocoursesyet"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
$strcourses = get_string("courses");
|
2003-07-30 13:02:45 +00:00
|
|
|
$strmovecourseto = get_string("movecourseto");
|
2003-08-07 16:01:31 +00:00
|
|
|
$stredit = get_string("edit");
|
2003-07-30 13:02:45 +00:00
|
|
|
$strdelete = get_string("delete");
|
2003-08-07 16:01:31 +00:00
|
|
|
$strbackup = get_string("backup");
|
2003-07-30 13:02:45 +00:00
|
|
|
$strmoveup = get_string("moveup");
|
|
|
|
$strmovedown = get_string("movedown");
|
|
|
|
$strupdate = get_string("update");
|
|
|
|
$strhide = get_string("hide");
|
|
|
|
$strshow = get_string("show");
|
2003-08-07 16:01:31 +00:00
|
|
|
$strassignteachers = get_string("assignteachers");
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
if (empty($THEME->custompix)) {
|
|
|
|
$pixpath = "$CFG->wwwroot/pix";
|
|
|
|
} else {
|
|
|
|
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
|
|
|
}
|
2003-08-07 16:01:31 +00:00
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
echo "<table align=\"center\" border=0 cellspacing=2 cellpadding=4 class=\"generalbox\"><tr>";
|
2003-07-30 13:02:45 +00:00
|
|
|
echo "<th>$strcourses</th>";
|
2003-08-07 16:01:31 +00:00
|
|
|
if ($creatorediting) {
|
|
|
|
echo "<th>$stredit</th>";
|
|
|
|
if ($adminediting) {
|
|
|
|
echo "<th>$strmovecourseto</th>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</tr>";
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
$numcourses = count($courses);
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
$count++;
|
|
|
|
$up = ($count == 1) ? false : true;
|
|
|
|
$down = ($count == $numcourses) ? false : true;
|
|
|
|
|
|
|
|
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td><a $linkcss href=\"view.php?id=$course->id\">$course->fullname</a></td>";
|
2003-08-07 16:01:31 +00:00
|
|
|
if ($creatorediting) {
|
|
|
|
echo "<td>";
|
|
|
|
if ($adminediting) {
|
2003-08-09 02:24:27 +00:00
|
|
|
echo "<a title=\"$strassignteachers\" href=\"$CFG->wwwroot/$CFG->admin/teacher.php?id=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/user.gif\" height=11 width=11 border=0></a> ";
|
2003-08-07 16:01:31 +00:00
|
|
|
echo "<a title=\"$strdelete\" 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=\"$strhide\" href=\"category.php?id=$category->id&hide=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/hide.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
} else {
|
|
|
|
echo "<a title=\"$strshow\" href=\"category.php?id=$category->id&show=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/show.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
echo "<a title=\"$strbackup\" href=\"../backup/backup.php?id=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/backup.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
|
|
|
|
|
|
|
|
if ($up) {
|
|
|
|
echo "<a title=\"$strmoveup\" href=\"category.php?id=$category->id&moveup=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($down) {
|
|
|
|
echo "<a title=\"$strmovedown\" href=\"category.php?id=$category->id&movedown=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
}
|
|
|
|
|
2003-08-09 02:24:27 +00:00
|
|
|
echo "</td>";
|
|
|
|
echo "<td>";
|
|
|
|
popup_form ("category.php?id=$category->id&move=$course->id&moveto=", $displaylist,
|
|
|
|
"moveform$course->id", "$course->category", "", "", "", false);
|
|
|
|
} else if (isteacher($course->id)) {
|
|
|
|
echo "<a title=\"$strassignteachers\" href=\"$CFG->wwwroot/$CFG->admin/teacher.php?id=$course->id\"><img".
|
|
|
|
" src=\"$pixpath/t/user.gif\" height=11 width=11 border=0></a> ";
|
|
|
|
}
|
2003-08-07 16:01:31 +00:00
|
|
|
echo "</td>";
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
echo "</tr>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
echo "<br />";
|
|
|
|
}
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if ($adminediting) {
|
|
|
|
/// First print form to rename the category
|
|
|
|
$strrename= get_string("rename");
|
|
|
|
print_simple_box_start("center");
|
|
|
|
echo "<center>";
|
|
|
|
echo "<form name=\"renameform\" action=\"category.php\" method=\"post\">";
|
|
|
|
echo "<input type=\"hidden\" name=\"id\" value=\"$category->id\">";
|
|
|
|
echo "<input type=\"text\" size=30 name=\"rename\" value=\"$category->name\">";
|
|
|
|
echo "<input type=\"submit\" value=\"$strrename\">";
|
|
|
|
echo "</form>";
|
|
|
|
echo "</center>";
|
|
|
|
print_simple_box_end();
|
|
|
|
echo "<br />";
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
print_footer();
|
|
|
|
|
|
|
|
?>
|