COURSE DISPLAY REVAMP
OK, some big changes here to the front end, particularly in course categories and course display. Course categories can now be nested (to any level). Courses and course categories can now be manually sorted any way required. There is a groovy front end for managing these, and a better range of options for formatting the front page. It all still needs some polishing, which I'll be doing over the next couple of days, including better auto-sorting. I would not use this on production systems just yet.
This commit is contained in:
+251
-74
@@ -7,7 +7,7 @@
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only administrators can use this course!");
|
||||
error("Only administrators can use this page!");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
@@ -24,80 +24,146 @@
|
||||
$stredit = get_string("edit");
|
||||
$strdelete = get_string("delete");
|
||||
$straction = get_string("action");
|
||||
$stradd = get_string("add");
|
||||
$straddnewcategory = get_string("addnewcategory");
|
||||
|
||||
print_header("$site->shortname: $strcategories", "$site->fullname",
|
||||
"<A HREF=\"../$CFG->admin/index.php\">$stradministration</A> -> $strcategories");
|
||||
"<A HREF=\"../$CFG->admin/index.php\">$stradministration</A> -> $strcategories",
|
||||
"addform.addcategory");
|
||||
|
||||
print_heading($strcategories);
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($form = data_submitted()) {
|
||||
|
||||
$categories = array();
|
||||
|
||||
// Peel out all the data from variable names.
|
||||
foreach ($form as $key => $val) {
|
||||
if ($key == "new") {
|
||||
if (!empty($val)) {
|
||||
if (get_records("course_categories", "name", $val)) {
|
||||
notify(get_string("categoryduplicate", "", $val));
|
||||
} else {
|
||||
$cat->name = $val;
|
||||
if (!insert_record("course_categories", $cat)) {
|
||||
error("Could not insert the new category '$val'");
|
||||
} else {
|
||||
notify(get_string("categoryadded", "", $val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If data for a new category was submitted, then add it
|
||||
if ($form = data_submitted()) {
|
||||
if (!empty($form->addcategory)) {
|
||||
unset($newcategory);
|
||||
$newcategory->name = $form->addcategory;
|
||||
$newcategory->sortorder = 999;
|
||||
if (!insert_record("course_categories", $newcategory)) {
|
||||
notify("Could not insert the new category '$newcategory->name'");
|
||||
} else {
|
||||
$cat->id = substr($key,1);
|
||||
$cat->name = $val;
|
||||
notify(get_string("categoryadded", "", $newcategory->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($existingcats = get_records("course_categories", "name", $val)) {
|
||||
foreach($existingcats as $existingcat) {
|
||||
if ($existingcat->id != $cat->id) {
|
||||
notify(get_string("categoryduplicate", "", $val));
|
||||
continue 2;
|
||||
}
|
||||
|
||||
/// Delete a category if necessary
|
||||
|
||||
if (isset($delete)) {
|
||||
if ($tempcat = get_record("course_categories", "id", $delete)) {
|
||||
if (delete_records("course_categories", "id", $tempcat->id)) {
|
||||
notify(get_string("categorydeleted", "", $tempcat->name));
|
||||
}
|
||||
if ($children = get_records("course_categories", "parent", $tempcat->id)) {
|
||||
foreach ($children as $childcat) {
|
||||
if (! set_field("course_categories", "parent", $tempcat->parent, "id", $childcat->id)) {
|
||||
notify("Could not update a child category!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!update_record("course_categories", $cat)) {
|
||||
error("Could not update the category '$val'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Get the existing categories
|
||||
if (!$categories = get_categories()) {
|
||||
/// Create a default category if necessary
|
||||
if (!$categories = get_categories()) { /// No category yet!
|
||||
// Try and make one
|
||||
$cat->name = get_string("miscellaneous");
|
||||
if ($cat->id = insert_record("course_categories", $cat)) {
|
||||
$categories[$cat->id] = $cat;
|
||||
} else {
|
||||
unset($tempcat);
|
||||
$tempcat->name = get_string("miscellaneous");
|
||||
if (!$tempcat->id = insert_record("course_categories", $tempcat)) {
|
||||
error("Serious error: Could not create a default category!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete category if the user wants to delete it
|
||||
if (isset($delete)) {
|
||||
if (delete_records("course_categories", "id", $delete)) {
|
||||
notify(get_string("categorydeleted", "", $categories[$delete]->name));
|
||||
unset($categories[$delete]);
|
||||
} else {
|
||||
error("An error occurred while trying to delete a category");
|
||||
|
||||
/// Move a category to a new parent if required
|
||||
|
||||
if (isset($move) and isset($moveto)) {
|
||||
if ($tempcat = get_record("course_categories", "id", $move)) {
|
||||
if ($tempcat->parent != $moveto) {
|
||||
if (! set_field("course_categories", "parent", $moveto, "id", $tempcat->id)) {
|
||||
notify("Could not update that category!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Find lowest ID category - this is the default category
|
||||
|
||||
/// Hide or show a category
|
||||
if (isset($hide) or isset($show)) {
|
||||
if (isset($hide)) {
|
||||
$tempcat = get_record("course_categories", "id", $hide);
|
||||
$visible = 0;
|
||||
} else {
|
||||
$tempcat = get_record("course_categories", "id", $show);
|
||||
$visible = 1;
|
||||
}
|
||||
if ($tempcat) {
|
||||
if (! set_field("course_categories", "visible", $visible, "id", $tempcat->id)) {
|
||||
notify("Could not update that category!");
|
||||
}
|
||||
if (! set_field("course", "visible", $visible, "category", $tempcat->id)) {
|
||||
notify("Could not hide/show any courses in this category !");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Move a category up or down
|
||||
|
||||
if (isset($moveup) or isset($movedown)) {
|
||||
|
||||
$swapcategory = NULL;
|
||||
$movecategory = NULL;
|
||||
|
||||
if (isset($moveup)) {
|
||||
if ($movecategory = get_record("course_categories", "id", $moveup)) {
|
||||
$categories = get_categories("$movecategory->parent");
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if ($category->id == $movecategory->id) {
|
||||
break;
|
||||
}
|
||||
$swapcategory = $category;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($movedown)) {
|
||||
if ($movecategory = get_record("course_categories", "id", $movedown)) {
|
||||
$categories = get_categories("$movecategory->parent");
|
||||
|
||||
$choosenext = false;
|
||||
foreach ($categories as $category) {
|
||||
if ($choosenext) {
|
||||
$swapcategory = $category;
|
||||
break;
|
||||
}
|
||||
if ($category->id == $movecategory->id) {
|
||||
$choosenext = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($swapcategory and $movecategory) { // Renumber everything for robustness
|
||||
$count=0;
|
||||
foreach ($categories as $category) {
|
||||
$count++;
|
||||
if ($category->id == $swapcategory->id) {
|
||||
$category = $movecategory;
|
||||
} else if ($category->id == $movecategory->id) {
|
||||
$category = $swapcategory;
|
||||
}
|
||||
if (! set_field("course_categories", "sortorder", $count, "id", $category->id)) {
|
||||
notify("Could not update that category!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Find the default category (the one with the lowest ID)
|
||||
$categories = get_categories();
|
||||
$default = 99999;
|
||||
foreach ($categories as $category) {
|
||||
fix_category_courses($category->id);
|
||||
if ($category->id < $default) {
|
||||
$default = $category->id;
|
||||
}
|
||||
@@ -112,30 +178,141 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// Print form for creating new categories
|
||||
|
||||
/// Print the table of all categories
|
||||
$table->head = array ($strcategory, $strcourses, $straction);
|
||||
$table->align = array ("LEFT", "CENTER", "CENTER");
|
||||
$table->size = array ("80", "50", "50");
|
||||
$table->width = 100;
|
||||
print_simple_box_start("center");
|
||||
echo "<center>";
|
||||
echo "<form name=\"addform\" action=\"categories.php\" method=\"post\">";
|
||||
echo "<input type=\"text\" size=55 name=\"addcategory\">";
|
||||
echo "<input type=\"submit\" value=\"$straddnewcategory\">";
|
||||
echo "</form>";
|
||||
echo "</center>";
|
||||
print_simple_box_end();
|
||||
|
||||
echo "<br />";
|
||||
|
||||
|
||||
/// Print out the categories with all the knobs
|
||||
|
||||
$strcategories = get_string("categories");
|
||||
$strmovecategoryto = get_string("movecategoryto");
|
||||
$stredit = get_string("edit");
|
||||
|
||||
$displaylist = array();
|
||||
$parentlist = array();
|
||||
|
||||
$displaylist[0] = get_string("top");
|
||||
make_categories_list($displaylist, $parentlist, "");
|
||||
|
||||
echo "<table align=\"center\" border=0 cellspacing=2 cellpadding=5 class=\"generalbox\"><tr>";
|
||||
echo "<th>$strcategories</th>";
|
||||
echo "<th>$stredit</th>";
|
||||
echo "<th>$strmovecategoryto</th>";
|
||||
|
||||
print_category_edit(NULL, $displaylist, $parentlist);
|
||||
|
||||
echo "</table>";
|
||||
|
||||
echo "<FORM ACTION=categories.php METHOD=post>";
|
||||
foreach ($categories as $category) {
|
||||
$count = count_records("course", "category", $category->id);
|
||||
if ($category->id == $default) {
|
||||
$delete = ""; // Can't delete default category
|
||||
} else {
|
||||
$delete = "<A HREF=\"categories.php?delete=$category->id\">$strdelete</A>";
|
||||
}
|
||||
$table->data[] = array ("<INPUT TYPE=text NAME=\"c$category->id\" VALUE=\"$category->name\" SIZE=30>",
|
||||
"<A HREF=\"index.php?category=$category->id\">$count</A>", $delete);
|
||||
}
|
||||
$table->data[] = array ("<INPUT TYPE=text NAME=\"new\" VALUE=\"\" SIZE=30>", "", "$stradd");
|
||||
print_table($table);
|
||||
echo "<CENTER><BR><INPUT TYPE=submit VALUE=\"".get_string("savechanges")."\"> ";
|
||||
echo "</CENTER>";
|
||||
echo "</FORM>";
|
||||
|
||||
print_footer();
|
||||
|
||||
|
||||
|
||||
function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) {
|
||||
/// Recursive function to print all the categories ready for editing
|
||||
|
||||
global $THEME, $CFG;
|
||||
|
||||
static $str = '';
|
||||
static $pixpath = '';
|
||||
|
||||
if (empty($str)) {
|
||||
$str->delete = get_string("delete");
|
||||
$str->moveup = get_string("moveup");
|
||||
$str->movedown = get_string("movedown");
|
||||
$str->edit = get_string("editthiscategory");
|
||||
$str->hide = get_string("hide");
|
||||
$str->show = get_string("show");
|
||||
}
|
||||
|
||||
if (empty($pixpath)) {
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = "$CFG->wwwroot/pix";
|
||||
} else {
|
||||
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
}
|
||||
}
|
||||
|
||||
if ($category) {
|
||||
echo "<tr><td align=\"left\" nowrap=\"nowrap\" bgcolor=\"$THEME->cellcontent\">";
|
||||
echo "<p>";
|
||||
for ($i=0; $i<$depth;$i++) {
|
||||
echo " ";
|
||||
}
|
||||
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
||||
echo "<a $linkcss title=\"$str->edit\" href=\"category.php?id=$category->id\">$category->name</a>";
|
||||
echo "</p>";
|
||||
echo "</td>";
|
||||
|
||||
echo "<td nowrap=\"nowrap\">"; /// Print little icons
|
||||
|
||||
if (!empty($category->visible)) {
|
||||
echo "<a title=\"$str->hide\" href=\"categories.php?hide=$category->id\"><img".
|
||||
" src=\"$pixpath/t/hide.gif\" height=11 width=11 border=0></a> ";
|
||||
} else {
|
||||
echo "<a title=\"$str->show\" href=\"categories.php?show=$category->id\"><img".
|
||||
" src=\"$pixpath/t/show.gif\" height=11 width=11 border=0></a> ";
|
||||
}
|
||||
|
||||
echo "<a title=\"$str->delete\" href=\"categories.php?delete=$category->id\"><img".
|
||||
" src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a> ";
|
||||
|
||||
//echo "<a title=\"$str->update\" href=\"category.php?id=$category->id\"><img".
|
||||
// " src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> ";
|
||||
|
||||
if ($up) {
|
||||
echo "<a title=\"$str->moveup\" href=\"categories.php?moveup=$category->id\"><img".
|
||||
" src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> ";
|
||||
}
|
||||
if ($down) {
|
||||
echo "<a title=\"$str->movedown\" href=\"categories.php?movedown=$category->id\"><img".
|
||||
" src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> ";
|
||||
}
|
||||
echo "</td>";
|
||||
|
||||
echo "<td align=\"left\" width=\"0\">";
|
||||
$tempdisplaylist = $displaylist;
|
||||
unset($tempdisplaylist[$category->id]);
|
||||
foreach ($parentslist as $key => $parents) {
|
||||
if (in_array($category->id, $parents)) {
|
||||
unset($tempdisplaylist[$key]);
|
||||
}
|
||||
}
|
||||
popup_form ("categories.php?move=$category->id&moveto=", $tempdisplaylist, "moveform$category->id", "$category->parent", "", "", "", false);
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
} else {
|
||||
$category->id = "0";
|
||||
}
|
||||
|
||||
if ($categories = get_categories($category->id)) { // Print all the children recursively
|
||||
$countcats = count($categories);
|
||||
$count = 0;
|
||||
$first = true;
|
||||
$last = false;
|
||||
foreach ($categories as $cat) {
|
||||
$count++;
|
||||
if ($count == $countcats) {
|
||||
$last = true;
|
||||
}
|
||||
$up = $first ? false : true;
|
||||
$down = $last ? false : true;
|
||||
$first = false;
|
||||
|
||||
print_category_edit($cat, $displaylist, $parentslist, $depth+1, $up, $down);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
<?PHP // $Id$
|
||||
// Allows the admin to edit a category, and rearrange courses
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
require_variable($id); // Category id
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only administrators can use this page!");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
if (!$category = get_record("course_categories", "id", $id)) {
|
||||
error("Category not known!");
|
||||
}
|
||||
|
||||
|
||||
/// Print headings
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strcategories = get_string("categories");
|
||||
$strcategories = get_string("categories");
|
||||
$strcategory = get_string("category");
|
||||
$strcourses = get_string("courses");
|
||||
|
||||
print_header("$site->shortname: $strcategory", "$site->fullname",
|
||||
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"categories.php\">$strcategories</a> -> $strcategory");
|
||||
|
||||
|
||||
/// Rename the category
|
||||
|
||||
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");
|
||||
} else {
|
||||
notify("The category was renamed");
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 />";
|
||||
|
||||
|
||||
/// Move a specified course to a new category
|
||||
|
||||
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_category_courses($destcategory->id);
|
||||
fix_category_courses($category->id);
|
||||
$category = get_record("course_categories", "id", $category->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Move a course up or down
|
||||
|
||||
if (isset($moveup) or isset($movedown)) {
|
||||
|
||||
|
||||
$movecourse = isset($moveup) ? $moveup : $movedown;
|
||||
|
||||
fix_category_courses($category->id);
|
||||
if (!$category = get_record("course_categories", "id", $category->id)) { // Fresh copy
|
||||
error("Category not known!");
|
||||
}
|
||||
|
||||
$courses = explode(',', $category->courseorder);
|
||||
$key = array_search($movecourse, $courses);
|
||||
if ($key === NULL or $key === false) {
|
||||
notify("Could not find that course in the category list!");
|
||||
|
||||
} else {
|
||||
if (isset($moveup)) {
|
||||
$swapkey = $key-1;
|
||||
} else {
|
||||
$swapkey = $key+1;
|
||||
}
|
||||
$courses[$key] = $courses[$swapkey];
|
||||
$courses[$swapkey] = $movecourse;
|
||||
$category->courseorder = implode(",", $courses);
|
||||
|
||||
if (! set_field("course_categories", "courseorder", $category->courseorder, "id", $category->id)) {
|
||||
notify("Database error while trying to update the category!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Print out the courses with all the knobs
|
||||
|
||||
fix_category_courses($category->id);
|
||||
|
||||
if (!$courses = get_courses($category)) {
|
||||
print_heading(get_string("nocoursesyet"));
|
||||
|
||||
} else {
|
||||
|
||||
$strcourses = get_string("courses");
|
||||
$strmovecourseto = get_string("movecourseto");
|
||||
$stredit = get_string("edit");
|
||||
$strdelete = get_string("delete");
|
||||
$strmoveup = get_string("moveup");
|
||||
$strmovedown = get_string("movedown");
|
||||
$strupdate = get_string("update");
|
||||
$strhide = get_string("hide");
|
||||
$strshow = get_string("show");
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = "$CFG->wwwroot/pix";
|
||||
} else {
|
||||
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
}
|
||||
|
||||
echo "<table align=\"center\" border=0 cellspacing=2 cellpadding=5 class=\"generalbox\"><tr>";
|
||||
echo "<th>$strcourses</th>";
|
||||
echo "<th>$stredit</th>";
|
||||
echo "<th>$strmovecourseto</th></tr>";
|
||||
|
||||
$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>";
|
||||
echo "<td>";
|
||||
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> ";
|
||||
}
|
||||
echo "<a title=\"$strdelete\" href=\"delete.php?id=$course->id\"><img".
|
||||
" src=\"$pixpath/t/delete.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> ";
|
||||
}
|
||||
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
popup_form ("category.php?id=$category->id&move=$course->id&moveto=", $displaylist,
|
||||
"moveform$course->id", "$course->category", "", "", "", false);
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
/// 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=55 name=\"rename\" value=\"$category->name\">";
|
||||
echo "<input type=\"submit\" value=\"$strrename\">";
|
||||
echo "</form>";
|
||||
echo "</center>";
|
||||
print_simple_box_end();
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
+3
-1
@@ -52,7 +52,9 @@
|
||||
<tr valign=top>
|
||||
<td><P><? print_string("category") ?>:</td>
|
||||
<td><?
|
||||
choose_from_menu ($form->categories, "category", "$form->category", "");
|
||||
$displaylist = array();
|
||||
make_categories_list($displaylist);
|
||||
choose_from_menu($displaylist, "category", "$form->category", "");
|
||||
helpbutton("coursecategory", get_string("category"));
|
||||
?>
|
||||
</td>
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
|
||||
$form->timemodified = time();
|
||||
|
||||
fix_category_courses($form->category);
|
||||
|
||||
if (!empty($course)) {
|
||||
if (update_record("course", $form)) {
|
||||
add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
|
||||
|
||||
+25
-34
@@ -4,54 +4,45 @@
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
optional_variable($category, "");
|
||||
optional_variable($category, "0");
|
||||
|
||||
$strcourses = get_string("courses");
|
||||
$strcategories = get_string("categories");
|
||||
$strmycourses = get_string("mycourses");
|
||||
$strfulllistofcourses = get_string("fulllistofcourses");
|
||||
|
||||
if (!$categories = get_categories()) {
|
||||
error("Could not find any course categories!");
|
||||
}
|
||||
if ($category = get_record("course_categories", "id", $category)) {
|
||||
print_header($strcourses, $strcourses, "<a href=\"index.php\">$strcourses</a> -> $category->name",
|
||||
"", "", true, update_category_button($category->id));
|
||||
|
||||
if ($category == "all") {
|
||||
$title = $strfulllistofcourses;
|
||||
$navigation = "<A HREF=\"index.php\">$strcourses</A> -> $title";
|
||||
} else if ($category == "my") {
|
||||
$title = $strmycourses;
|
||||
$navigation = "<A HREF=\"index.php\">$strcourses</A> -> $title";
|
||||
} else if (isset($categories[$category])) {
|
||||
$title = $categories[$category]->name;
|
||||
$navigation = "<A HREF=\"index.php\">$strcourses</A> -> $title";
|
||||
} else {
|
||||
$navigation = $strcourses;
|
||||
print_header($strcourses, $strcourses, $strcourses);
|
||||
$category->id = 0;
|
||||
}
|
||||
|
||||
print_header($strcourses, $strcourses, $navigation);
|
||||
|
||||
$showcategories = (count($categories) > 1);
|
||||
if ($showcategories) {
|
||||
echo "<TABLE WIDTH=\"100%\" CELLPADDING=\"8\" BORDER=\"0\">";
|
||||
echo "<TR><TD WIDTH=\"200\" VALIGN=\"TOP\">";
|
||||
print_course_categories($categories, $category, 200);
|
||||
echo "</TD><TD WIDTH=\"*\" VALIGN=\"TOP\">";
|
||||
/// Print the category selector
|
||||
|
||||
$categories = get_categories();
|
||||
$multicategories = count($categories) > 1;
|
||||
|
||||
if (count($categories) > 1) {
|
||||
$parentlist = array();
|
||||
$displaylist = array();
|
||||
$displaylist["0"] = $strfulllistofcourses;
|
||||
make_categories_list($displaylist, $parentlist, "");
|
||||
|
||||
echo "<table align=center><tr><td>";
|
||||
popup_form("index.php?category=", $displaylist, "switchcategory", "$category->id", "", "", "", false);
|
||||
echo "</td></tr></table><br />";
|
||||
}
|
||||
|
||||
if (empty($category->id)) {
|
||||
print_courses(0, "80%");
|
||||
} else {
|
||||
echo "<TABLE WIDTH=80% ALIGN=CENTER><TR><TD VALIGN=top>";
|
||||
$category="all";
|
||||
unset($title);
|
||||
print_courses($category, "80%");
|
||||
}
|
||||
|
||||
if ($category) {
|
||||
if (isset($title)) {
|
||||
print_heading_block($title);
|
||||
}
|
||||
echo "<BR>";
|
||||
print_all_courses($category);
|
||||
}
|
||||
|
||||
echo "</TD></TR></TABLE>";
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
+308
-180
@@ -14,6 +14,9 @@ define('COURSE_LIVELOG_REFRESH', 60); // Seconds
|
||||
|
||||
define('COURSE_MAX_RECENT_PERIOD', 604800); // A week, in seconds
|
||||
|
||||
define("FRONTPAGENEWS", 0);
|
||||
define("FRONTPAGECOURSELIST", 1);
|
||||
define("FRONTPAGECATEGORYNAMES", 2);
|
||||
|
||||
|
||||
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") {
|
||||
@@ -189,114 +192,16 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
|
||||
}
|
||||
|
||||
|
||||
function print_all_courses($category="all", $style="full", $maxcount=999, $width=180) {
|
||||
global $CFG, $THEME, $USER;
|
||||
|
||||
if ($category == "all") {
|
||||
$courses = get_courses();
|
||||
|
||||
} else if ($category == "my") {
|
||||
if (isset($USER->id)) {
|
||||
if ($courses = get_courses()) {
|
||||
foreach ($courses as $key => $course) {
|
||||
if (!isteacher($course->id) and !isstudent($course->id)) {
|
||||
unset($courses[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
|
||||
global $CFG;
|
||||
if (empty($CFG->gdversion)) {
|
||||
echo "(".get_string("gdneed").")";
|
||||
} else {
|
||||
$courses = get_courses($category);
|
||||
}
|
||||
|
||||
if ($style == "minimal") {
|
||||
$count = 0;
|
||||
if (empty($THEME->custompix)) {
|
||||
$icon = "<img src=\"$CFG->wwwroot/pix/i/course.gif\" height=16 width=16 alt=\"".get_string("course")."\">";
|
||||
} else {
|
||||
$icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\" height=16 width=16 alt=\"".get_string("course")."\">";
|
||||
}
|
||||
if ($courses) {
|
||||
foreach ($courses as $course) {
|
||||
$moddata[]="<a title=\"$course->shortname\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
||||
$modicon[]=$icon;
|
||||
if ($count++ >= $maxcount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fulllist = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</a>...";
|
||||
} else {
|
||||
$moddata = array();
|
||||
$modicon = array();
|
||||
$fulllist = get_string("nocoursesyet");
|
||||
}
|
||||
print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width);
|
||||
|
||||
} else if ($courses) {
|
||||
foreach ($courses as $course) {
|
||||
print_course($course);
|
||||
echo "<br />\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
echo "<p>".get_string("nocoursesyet")."</p>";
|
||||
echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function print_course($course) {
|
||||
|
||||
global $CFG, $THEME;
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Could not find a site!");
|
||||
}
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = "$CFG->wwwroot/pix";
|
||||
} else {
|
||||
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
}
|
||||
|
||||
print_simple_box_start("CENTER", "100%");
|
||||
|
||||
echo "<TABLE WIDTH=100%>";
|
||||
echo "<TR VALIGN=top>";
|
||||
echo "<TD VALIGN=top WIDTH=50%>";
|
||||
echo "<P><FONT SIZE=3><B><A TITLE=\"".get_string("entercourse")."\"
|
||||
HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A></B></FONT></P>";
|
||||
if ($teachers = get_course_teachers($course->id)) {
|
||||
echo "<P><FONT SIZE=1>\n";
|
||||
foreach ($teachers as $teacher) {
|
||||
if ($teacher->authority > 0) {
|
||||
if (!$teacher->role) {
|
||||
$teacher->role = $course->teacher;
|
||||
}
|
||||
echo "$teacher->role: <A HREF=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</A><BR>";
|
||||
}
|
||||
}
|
||||
echo "</FONT></P>";
|
||||
}
|
||||
if ($course->guest) {
|
||||
$strallowguests = get_string("allowguests");
|
||||
echo "<A TITLE=\"$strallowguests\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<IMG VSPACE=4 ALT=\"$strallowguests\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$pixpath/i/user.gif\"></A> ";
|
||||
}
|
||||
if ($course->password) {
|
||||
$strrequireskey = get_string("requireskey");
|
||||
echo "<A TITLE=\"$strrequireskey\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<IMG VSPACE=4 ALT=\"$strrequireskey\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$pixpath/i/key.gif\"></A>";
|
||||
}
|
||||
|
||||
|
||||
echo "</TD><TD VALIGN=top WIDTH=50%>";
|
||||
echo "<P><FONT SIZE=2>".text_to_html($course->summary)."</FONT></P>";
|
||||
echo "</TD></TR>";
|
||||
echo "</TABLE>";
|
||||
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
function print_recent_activity($course) {
|
||||
// $course is an object
|
||||
@@ -593,7 +498,7 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod
|
||||
}
|
||||
if ($mod->visible or $isteacher) {
|
||||
$instancename = urldecode($modinfo[$modnumber]->name);
|
||||
$link_css = $mod->visible ? "" : " class=\"dimmed\" ";
|
||||
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
|
||||
if (!empty($modinfo[$modnumber]->extra)) {
|
||||
$extra = urldecode($modinfo[$modnumber]->extra);
|
||||
} else {
|
||||
@@ -602,7 +507,7 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod
|
||||
|
||||
$modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"".
|
||||
" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
|
||||
$moddata[] = "<a title=\"$mod->modfullname\" $link_css $extra".
|
||||
$moddata[] = "<a title=\"$mod->modfullname\" $linkcss $extra".
|
||||
"href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a>".
|
||||
"<br />$editbuttons";
|
||||
}
|
||||
@@ -670,10 +575,10 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
|
||||
} else {
|
||||
$extra = "";
|
||||
}
|
||||
$link_css = $mod->visible ? "" : " class=\"dimmed\" ";
|
||||
$linkcss = $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 $extra".
|
||||
" <font size=2><a title=\"$mod->modfullname\" $linkcss $extra".
|
||||
" href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>";
|
||||
}
|
||||
if (isediting($course->id)) {
|
||||
@@ -893,9 +798,127 @@ function print_course_admin_links($course, $width=180) {
|
||||
print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width);
|
||||
}
|
||||
|
||||
function print_course_categories($categories, $selected="none", $width=180) {
|
||||
global $CFG, $THEME, $USER;
|
||||
|
||||
|
||||
function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
|
||||
/// Given an empty array, this function recursively travels the
|
||||
/// categories, building up a nice list for display. It also makes
|
||||
/// an array that list all the parents for each category.
|
||||
|
||||
if ($category) {
|
||||
if ($path) {
|
||||
$path = "$path / $category->name";
|
||||
} else {
|
||||
$path = "$category->name";
|
||||
}
|
||||
$list[$category->id] = $path;
|
||||
} else {
|
||||
$category->id = 0;
|
||||
}
|
||||
|
||||
if ($categories = get_categories("$category->id")) { // Print all the children recursively
|
||||
foreach ($categories as $cat) {
|
||||
if (!empty($category->id)) {
|
||||
$parents[$cat->id] = $parents[$category->id];
|
||||
$parents[$cat->id][] = $category->id;
|
||||
}
|
||||
make_categories_list($list, &$parents, $cat, $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fix_category_courses($categoryid) {
|
||||
/// Given a category, this function makes sure the courseorder
|
||||
/// variable reflects the real world.
|
||||
|
||||
if (!$category = get_record("course_categories", "id", $categoryid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$catcourseschanged = false;
|
||||
|
||||
if (trim($category->courseorder)) {
|
||||
$catcourses = explode(',', $category->courseorder);
|
||||
} else {
|
||||
$catcourses = array();
|
||||
}
|
||||
$courses = get_records("course", "category", $category->id);
|
||||
|
||||
if ($catcourses) {
|
||||
foreach ($catcourses as $key => $catcourse) { // Look for missing courses
|
||||
if (!isset($courses[$catcourse])) {
|
||||
$catcourseschanged = true;
|
||||
unset($catcourses[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($courses) {
|
||||
foreach ($courses as $course) {
|
||||
if (!in_array($course->id, $catcourses)) {
|
||||
$catcourseschanged = true;
|
||||
$catcourses[] = $course->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($catcourseschanged) {
|
||||
$category->courseorder = implode(',', $catcourses);
|
||||
return set_field("course_categories", "courseorder", $category->courseorder, "id", $category->id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) {
|
||||
/// Recursive function to print out all the categories in a nice format
|
||||
/// with or without courses included
|
||||
|
||||
if (!$displaylist) {
|
||||
make_categories_list(&$displaylist, &$parentslist);
|
||||
}
|
||||
|
||||
if ($category) {
|
||||
if ($category->visible or isadmin()) {
|
||||
print_category_box($category, $depth);
|
||||
} else {
|
||||
return; // Don't bother printing children of invisible categories
|
||||
}
|
||||
|
||||
} else {
|
||||
print_simple_box_start("center", "100%");
|
||||
$category->id = "0";
|
||||
}
|
||||
|
||||
if ($categories = get_categories($category->id)) { // Print all the children recursively
|
||||
$countcats = count($categories);
|
||||
$count = 0;
|
||||
$first = true;
|
||||
$last = false;
|
||||
foreach ($categories as $cat) {
|
||||
$count++;
|
||||
if ($count == $countcats) {
|
||||
$last = true;
|
||||
}
|
||||
$up = $first ? false : true;
|
||||
$down = $last ? false : true;
|
||||
$first = false;
|
||||
|
||||
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($category->id == "0") {
|
||||
print_simple_box_end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function print_category_box($category, $depth) {
|
||||
/// Prints the category box in indented fashion
|
||||
|
||||
global $CFG;
|
||||
|
||||
$strallowguests = get_string("allowguests");
|
||||
$strrequireskey = get_string("requireskey");
|
||||
|
||||
@@ -905,84 +928,189 @@ function print_course_categories($categories, $selected="none", $width=180) {
|
||||
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
}
|
||||
|
||||
if ($selected == "index") { // Print comprehensive index of categories with courses
|
||||
if ($courses = get_courses()) {
|
||||
if (isset($USER->id) and !isadmin()) {
|
||||
print_simple_box_start("CENTER", "100%", $THEME->cellheading);
|
||||
print_heading("<a href=\"course/index.php?category=my\">".get_string("mycourses")."</a>", "left");
|
||||
$some = false;
|
||||
echo "<ul>";
|
||||
foreach ($courses as $key => $course) {
|
||||
if (isteacher($course->id) or isstudent($course->id)) {
|
||||
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
||||
echo "<br />";
|
||||
$some = true;
|
||||
}
|
||||
}
|
||||
if (!$some) {
|
||||
print_string("nocoursesyet");
|
||||
}
|
||||
echo "</ul>";
|
||||
print_simple_box_end();
|
||||
print_spacer(8,1);
|
||||
}
|
||||
foreach ($categories as $category) {
|
||||
print_simple_box_start("CENTER", "100%");
|
||||
print_heading("<a href=\"course/index.php?category=$category->id\">$category->name</a>", "left");
|
||||
$some = false;
|
||||
echo "<ul>";
|
||||
foreach ($courses as $key => $course) {
|
||||
if ($course->category == $category->id) {
|
||||
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
||||
echo " ";
|
||||
unset($courses[$key]);
|
||||
if ($course->guest ) {
|
||||
echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>";
|
||||
}
|
||||
if ($course->password) {
|
||||
echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>";
|
||||
}
|
||||
echo "<br />";
|
||||
$some = true;
|
||||
}
|
||||
}
|
||||
if (!$some) {
|
||||
print_string("nocoursesyet");
|
||||
}
|
||||
echo "</ul>";
|
||||
print_simple_box_end();
|
||||
print_spacer(8,1);
|
||||
}
|
||||
}
|
||||
$size = $depth * 40;
|
||||
|
||||
} else { // Print short list of categories only
|
||||
foreach ($categories as $cat) {
|
||||
$caticon[]="<img src=\"$pixpath/i/course.gif\" height=16 width=16>";
|
||||
if ($cat->id == $selected) {
|
||||
$catdata[]="$cat->name";
|
||||
} else {
|
||||
$catdata[]="<a href=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</a>";
|
||||
$catlinkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
||||
|
||||
echo "<table class=\"categorybox\">";
|
||||
echo "<tr>";
|
||||
echo "<td width=\"$size\">";
|
||||
echo print_spacer(1, $size);
|
||||
echo "<td width=\"100%\">";
|
||||
echo "<font size=+1><a $catlinkcss href=\"$CFG->wwwroot/course/index.php?category=$category->id\">$category->name</a></font>";
|
||||
//echo "<font size=+1>$category->name</font>";
|
||||
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
|
||||
if ($courses = get_courses($category)) {
|
||||
echo "<ul>";
|
||||
foreach ($courses as $course) {
|
||||
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
|
||||
echo "<li><a $linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
||||
echo " ";
|
||||
unset($courses[$key]);
|
||||
if ($course->guest ) {
|
||||
echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>";
|
||||
}
|
||||
if ($course->password) {
|
||||
echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>";
|
||||
}
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
$catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</a>";
|
||||
$caticon[] = "";
|
||||
if (isset($USER->id)) {
|
||||
$catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</a>";
|
||||
$caticon[] = "";
|
||||
}
|
||||
print_side_block(get_string("categories"), "", $catdata, $caticon, "", $width);
|
||||
}
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
echo "</table>";
|
||||
|
||||
}
|
||||
|
||||
function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
|
||||
global $CFG;
|
||||
if (empty($CFG->gdversion)) {
|
||||
echo "(".get_string("gdneed").")";
|
||||
function print_courses_sideblock($category=0, $width="100%") {
|
||||
global $CFG, $THEME;
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$icon = "<img src=\"$CFG->wwwroot/pix/i/course.gif\"".
|
||||
" height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
|
||||
} else {
|
||||
echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
|
||||
$icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\"".
|
||||
" height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
|
||||
}
|
||||
|
||||
$categories = get_categories(0); // Parent = 0 ie top-level categories only
|
||||
if (count($categories) > 1) { // Just print top level category links
|
||||
foreach ($categories as $category) {
|
||||
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
||||
$moddata[]="<a $linkcss href=\"$CFG->wwwroot/course/index.php?category=$category->id\">$category->name</a>";
|
||||
$modicon[]=$icon;
|
||||
}
|
||||
} else { // Just print course names of single category
|
||||
$courses = get_courses($category);
|
||||
if ($courses) {
|
||||
foreach ($courses as $course) {
|
||||
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
|
||||
$moddata[]="<a $linkcss title=\"$course->shortname\" ".
|
||||
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
||||
$modicon[]=$icon;
|
||||
}
|
||||
$fulllist = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</a>...";
|
||||
} else {
|
||||
$moddata = array();
|
||||
$modicon = array();
|
||||
$fulllist = get_string("nocoursesyet");
|
||||
}
|
||||
}
|
||||
|
||||
print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width);
|
||||
}
|
||||
|
||||
|
||||
function print_courses($category, $width="100%") {
|
||||
/// Category is 0 (for all courses) or an object
|
||||
|
||||
global $CFG, $THEME;
|
||||
|
||||
if (empty($category)) {
|
||||
$categories = NULL;
|
||||
$courses = get_courses(0);
|
||||
} else {
|
||||
$categories = get_categories($category->id); // sub categories
|
||||
$courses = get_courses($category);
|
||||
}
|
||||
|
||||
if ($categories) {
|
||||
print_simple_box_start("center");
|
||||
print_heading(get_string("subcategories"));
|
||||
foreach ($categories as $category) {
|
||||
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
||||
echo "<p align=\"center\"><a $linkcss".
|
||||
" href=\"$CFG->wwwroot/course/index.php?category=$category->id\">$category->name</a></p>";
|
||||
}
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
if ($courses) {
|
||||
foreach ($courses as $course) {
|
||||
print_course($course, $width);
|
||||
echo "<br />\n";
|
||||
}
|
||||
} else {
|
||||
print_heading(get_string("nocoursesyet"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function print_course($course, $width="100%") {
|
||||
|
||||
global $CFG, $THEME;
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Could not find a site!");
|
||||
}
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = "$CFG->wwwroot/pix";
|
||||
} else {
|
||||
$pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
}
|
||||
|
||||
print_simple_box_start("center", "$width");
|
||||
|
||||
echo "<table width=\"100%\">";
|
||||
echo "<tr valign=top>";
|
||||
echo "<td valign=top width=50%>";
|
||||
echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\"
|
||||
href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a></b></font></p>";
|
||||
if ($teachers = get_course_teachers($course->id)) {
|
||||
echo "<p><font size=\"1\">\n";
|
||||
foreach ($teachers as $teacher) {
|
||||
if ($teacher->authority > 0) {
|
||||
if (!$teacher->role) {
|
||||
$teacher->role = $course->teacher;
|
||||
}
|
||||
echo "$teacher->role: <a href=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</a><br />";
|
||||
}
|
||||
}
|
||||
echo "</font></p>";
|
||||
}
|
||||
if ($course->guest) {
|
||||
$strallowguests = get_string("allowguests");
|
||||
echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img vspace=4 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a> ";
|
||||
}
|
||||
if ($course->password) {
|
||||
$strrequireskey = get_string("requireskey");
|
||||
echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
echo "<img vspace=4 alt=\"$strrequireskey\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>";
|
||||
}
|
||||
|
||||
|
||||
echo "</td><td valign=top width=50%>";
|
||||
echo "<p><font size=2>".text_to_html($course->summary)."</font></p>";
|
||||
echo "</td></tr>";
|
||||
echo "</table>";
|
||||
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
|
||||
function print_my_moodle() {
|
||||
/// Prints custom user information on the home page.
|
||||
/// Over time this can include all sorts of information
|
||||
|
||||
global $USER, $CFG;
|
||||
|
||||
if (!isset($USER->id)) {
|
||||
error("It shouldn't be possible to see My Moodle without being logged in.");
|
||||
}
|
||||
|
||||
if ($courses = get_my_courses($USER->id)) {
|
||||
foreach ($courses as $course) {
|
||||
print_course($course, "100%");
|
||||
echo "<br />\n";
|
||||
}
|
||||
}
|
||||
echo "<p align=\"right\"><a href=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</a>...</p>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
|
||||
if ($user->id == $USER->id) {
|
||||
unset($USER->student["$id"]);
|
||||
redirect("$CFG->wwwroot");
|
||||
redirect("$CFG->wwwroot/");
|
||||
}
|
||||
|
||||
redirect("$CFG->wwwroot/user/index.php?id=$course->id");
|
||||
|
||||
@@ -61,14 +61,23 @@
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
if ($site->newsitems > 0 ) {
|
||||
$categories = get_categories();
|
||||
if (count($categories) > 1) {
|
||||
print_course_categories($categories, "none", $side);
|
||||
} else {
|
||||
$category = array_shift($categories);
|
||||
print_all_courses($category->id, "minimal", 10, $side);
|
||||
}
|
||||
switch ($CFG->frontpage) {
|
||||
case FRONTPAGENEWS: // print news links on the side
|
||||
print_courses_sideblock(0, "$side");
|
||||
break;
|
||||
|
||||
case FRONTPAGECOURSELIST:
|
||||
case FRONTPAGECATEGORYNAMES:
|
||||
if ($site->newsitems) {
|
||||
if ($news = forum_get_course_forum($site->id, "news")) {
|
||||
print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews");
|
||||
echo "<font size=\"-2\">";
|
||||
forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false);
|
||||
echo "</font>";
|
||||
print_side_block_end();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
print_spacer(1,$side);
|
||||
}
|
||||
@@ -86,38 +95,49 @@
|
||||
}
|
||||
echo "<td width=\"70%\" valign=\"top\">";
|
||||
|
||||
if ($site->newsitems == 0 ) {
|
||||
print_heading_block(get_string("availablecourses"));
|
||||
print_spacer(8,1);
|
||||
$categories = get_categories();
|
||||
if (count($categories) > 1) {
|
||||
print_course_categories($categories, "index");
|
||||
} else {
|
||||
print_all_courses("all");
|
||||
}
|
||||
|
||||
} else {
|
||||
if (! $newsforum = forum_get_course_forum($site->id, "news")) {
|
||||
error("Could not find or create a main news forum for the site");
|
||||
}
|
||||
|
||||
if (isset($USER->id)) {
|
||||
$SESSION->fromdiscussion = "$CFG->wwwroot";
|
||||
if (forum_is_subscribed($USER->id, $newsforum->id)) {
|
||||
$subtext = get_string("unsubscribe", "forum");
|
||||
} else {
|
||||
$subtext = get_string("subscribe", "forum");
|
||||
switch ($CFG->frontpage) { /// Display the main part of the front page.
|
||||
case FRONTPAGENEWS:
|
||||
if (! $newsforum = forum_get_course_forum($site->id, "news")) {
|
||||
error("Could not find or create a main news forum for the site");
|
||||
}
|
||||
$headertext = "<table border=0 align=right cellpadding=0 cellspacing=0><tr>
|
||||
<td align=right><font size=1>
|
||||
<a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
|
||||
</td></tr></table>$newsforum->name";
|
||||
} else {
|
||||
$headertext = $newsforum->name;
|
||||
}
|
||||
print_heading_block($headertext);
|
||||
print_spacer(8,1);
|
||||
forum_print_latest_discussions($newsforum->id, $site->newsitems);
|
||||
|
||||
if (isset($USER->id)) {
|
||||
$SESSION->fromdiscussion = "$CFG->wwwroot";
|
||||
if (forum_is_subscribed($USER->id, $newsforum->id)) {
|
||||
$subtext = get_string("unsubscribe", "forum");
|
||||
} else {
|
||||
$subtext = get_string("subscribe", "forum");
|
||||
}
|
||||
$headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0><tr>
|
||||
<td>$newsforum->name</td>
|
||||
<td align=right><font size=1>
|
||||
<a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
|
||||
</td></tr></table>";
|
||||
} else {
|
||||
$headertext = $newsforum->name;
|
||||
}
|
||||
print_heading_block($headertext);
|
||||
print_spacer(8,1);
|
||||
forum_print_latest_discussions($newsforum->id, $site->newsitems);
|
||||
break;
|
||||
|
||||
case FRONTPAGECOURSELIST:
|
||||
case FRONTPAGECATEGORYNAMES:
|
||||
if (isset($USER->id) and !isset($USER->admin)) {
|
||||
print_heading_block(get_string("mycourses"));
|
||||
print_spacer(8,1);
|
||||
print_my_moodle();
|
||||
} else {
|
||||
print_heading_block(get_string("availablecourses"));
|
||||
print_spacer(8,1);
|
||||
if (count_records("course_categories") > 1) {
|
||||
print_whole_category_list();
|
||||
} else {
|
||||
print_courses(0, "100%");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
echo "</td>";
|
||||
|
||||
+11
-2
@@ -16,6 +16,7 @@ $string['add'] = "Add";
|
||||
$string['added'] = "Added \$a";
|
||||
$string['addinganew'] = "Adding a new \$a";
|
||||
$string['addinganewto'] = "Adding a new \$a->what to \$a->to";
|
||||
$string['addnewcategory'] = "Add new category";
|
||||
$string['addnewcourse'] = "Add a new course";
|
||||
$string['addnewuser'] = "Add a new user";
|
||||
$string['address'] = "Address";
|
||||
@@ -186,6 +187,7 @@ $string['editinga'] = "Editing a \$a";
|
||||
$string['editmyprofile'] = "Edit profile";
|
||||
$string['editsummary'] = "Edit summary";
|
||||
$string['editthisactivity'] = "Edit this activity";
|
||||
$string['editthiscategory'] = "Edit this category";
|
||||
$string['edituser'] = "Edit user accounts";
|
||||
$string['email'] = "Email address";
|
||||
$string['emailformat'] = "Email format";
|
||||
@@ -276,8 +278,11 @@ $string['formattopics'] = "Topics format";
|
||||
$string['formatweeks'] = "Weekly format";
|
||||
$string['formatwiki'] = "Wiki format";
|
||||
$string['from'] = "From";
|
||||
$string['frontpagecategorynames'] = "Show a list of categories";
|
||||
$string['frontpagecourselist'] = "Show a list of courses";
|
||||
$string['frontpagedescription'] = "Front page description";
|
||||
$string['frontpageformat'] = "Front page format";
|
||||
$string['frontpagenews'] = "Show news items";
|
||||
$string['fulllistofcourses'] = "All courses";
|
||||
$string['fullprofile'] = "Full profile";
|
||||
$string['fullname'] = "Full name";
|
||||
@@ -441,6 +446,8 @@ $string['modulesuccess'] = "\$a tables have been set up correctly";
|
||||
$string['moodleversion'] = "Moodle Version";
|
||||
$string['mostrecently'] = "most recently";
|
||||
$string['move'] = "Move";
|
||||
$string['movecategoryto'] = "Move category to:";
|
||||
$string['movecourseto'] = "Move course to:";
|
||||
$string['movedown'] = "Move down";
|
||||
$string['movefull'] = "Move \$a to this location";
|
||||
$string['movehere'] = "Move to here";
|
||||
@@ -609,7 +616,6 @@ $string['showonlytopic'] = "Show only topic \$a";
|
||||
$string['showonlyweek'] = "Show only week \$a";
|
||||
$string['showrecent'] = "Show recent activity";
|
||||
$string['showtheselogs'] = "Show these logs";
|
||||
$string['socialheadline'] = "Social forum - latest topics";
|
||||
$string['showallcourses'] = "Show all courses";
|
||||
$string['site'] = "Site";
|
||||
$string['sites'] = "Sites";
|
||||
@@ -617,6 +623,7 @@ $string['sitelogs'] = "Site logs";
|
||||
$string['sitenews'] = "Site news";
|
||||
$string['sitesettings'] = "Site settings";
|
||||
$string['size'] = "Size";
|
||||
$string['socialheadline'] = "Social forum - latest topics";
|
||||
$string['someallowguest'] = "Some courses may allow guest access";
|
||||
$string['someerrorswerefound'] = "Some information was missing or incorrect. Look below for details.";
|
||||
$string['startdate'] = "Course start date";
|
||||
@@ -635,6 +642,7 @@ $string['strftimerecentfull'] = "%%a, %%d %%b %%Y, %%I:%%M %%p";
|
||||
$string['strftimetime'] = "%%I:%%M %%p";
|
||||
$string['stringsnotset'] = "The following strings are not defined in \$a";
|
||||
$string['studentnotallowed'] = "Sorry, but you can not enter this course as '\$a'";
|
||||
$string['subcategories'] = "Sub-categories";
|
||||
$string['success'] = "Success";
|
||||
$string['summary'] = "Summary";
|
||||
$string['summaryof'] = "Summary of \$a";
|
||||
@@ -652,13 +660,14 @@ $string['to'] = "To";
|
||||
$string['today'] = "Today";
|
||||
$string['todaylogs'] = "Today's logs";
|
||||
$string['toomanytoshow'] = "There are too many users to show";
|
||||
$string['top'] = "Top";
|
||||
$string['topic'] = "Topic";
|
||||
$string['topichide'] = "Hide this topic from \$a";
|
||||
$string['topicoutline'] = "Topic outline";
|
||||
$string['topicshow'] = "Show this topic to \$a";
|
||||
$string['total'] = "Total";
|
||||
$string['turneditingoff'] = "Turn editing off";
|
||||
$string['turneditingon'] = "Turn editing on";
|
||||
$string['total'] = "Total";
|
||||
$string['undecided'] = "Undecided";
|
||||
$string['unenrol'] = "Unenrol";
|
||||
$string['unenrolme'] = "Unenrol me from \$a";
|
||||
|
||||
+48
-8
@@ -83,6 +83,9 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
|
||||
case "mysqlt":
|
||||
|
||||
switch (strtolower($type)) {
|
||||
case "text":
|
||||
$type = "TEXT";
|
||||
break;
|
||||
case "integer":
|
||||
$type = "INTEGER($size)";
|
||||
break;
|
||||
@@ -821,16 +824,24 @@ function get_site () {
|
||||
|
||||
|
||||
function get_courses($category=0, $sort="fullname ASC") {
|
||||
/// Returns list of courses
|
||||
/// Returns list of courses, for whole site, or category
|
||||
|
||||
if ($category > 0) { // Return all courses in one category
|
||||
$courses = get_records("course", "category", $category, $sort);
|
||||
if ($category === 0) { // Return all courses, except site
|
||||
$courses = get_records_select("course", "category > 0", $sort);
|
||||
|
||||
} else if ($category < 0) { // Return all courses, even the site
|
||||
} else if ($category === -1) { // Return all courses, even the site
|
||||
$courses = get_records("course", "", "", $sort);
|
||||
|
||||
} else { // Return all courses, except site
|
||||
$courses = get_records_select("course", "category > 0", $sort);
|
||||
} else { // $category is an object
|
||||
$courses = get_records("course", "category", $category->id);
|
||||
if ($courses) { // Reorder them
|
||||
$courselist = explode(',', $category->courseorder);
|
||||
$outcourses = array();
|
||||
foreach ($courselist as $courseid) {
|
||||
$outcourses[] = $courses[$courseid];
|
||||
}
|
||||
$courses = $outcourses;
|
||||
}
|
||||
}
|
||||
|
||||
if ($courses) { /// Remove unavailable courses from the list
|
||||
@@ -845,8 +856,37 @@ function get_courses($category=0, $sort="fullname ASC") {
|
||||
return $courses;
|
||||
}
|
||||
|
||||
function get_categories() {
|
||||
return get_records("course_categories", "", "", "name");
|
||||
function get_my_courses($userid, $sort="c.fullname ASC") {
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT c.*
|
||||
FROM {$CFG->prefix}course c,
|
||||
{$CFG->prefix}user_students s,
|
||||
{$CFG->prefix}user_teachers t
|
||||
WHERE (s.userid = '$userid' AND s.course = c.id)
|
||||
OR (t.userid = '$userid' AND t.course = c.id)
|
||||
GROUP BY c.id
|
||||
ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
||||
function get_categories($parent="none", $sort="sortorder ASC") {
|
||||
if ($parent == "none") {
|
||||
$categories = get_records("course_categories", "", "", $sort);
|
||||
} else {
|
||||
$categories = get_records("course_categories", "parent", $parent, $sort);
|
||||
}
|
||||
if ($categories) { /// Remove unavailable categories from the list
|
||||
$admin = isadmin();
|
||||
foreach ($categories as $key => $category) {
|
||||
if (!$category->visible) {
|
||||
if (!$admin) {
|
||||
unset($categories[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -413,6 +413,15 @@ function main_upgrade($oldversion=0) {
|
||||
execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003072803) {
|
||||
table_column("course_categories", "", "description", "text", "", "", "");
|
||||
table_column("course_categories", "", "parent", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "courseorder", "text", "", "", "");
|
||||
table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
|
||||
table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ CREATE TABLE `prefix_course` (
|
||||
CREATE TABLE `prefix_course_categories` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255) NOT NULL default '',
|
||||
`description` text NOT NULL,
|
||||
`parent` int(10) unsigned NOT NULL default '0',
|
||||
`sortorder` int(10) unsigned NOT NULL default '0',
|
||||
`courseorder` text NOT NULL,
|
||||
`visible` tinyint(1) NOT NULL default '1',
|
||||
`timemodified` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`)
|
||||
) TYPE=MyISAM COMMENT='Course categories';
|
||||
|
||||
@@ -184,6 +184,15 @@ function main_upgrade($oldversion=0) {
|
||||
execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003072802) {
|
||||
table_column("course_categories", "", "description", "text", "", "", "");
|
||||
table_column("course_categories", "", "parent", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "courseorder", "text", "", "", "");
|
||||
table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
|
||||
table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -31,6 +31,12 @@ CREATE TABLE prefix_course (
|
||||
CREATE TABLE prefix_course_categories (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name varchar(255) NOT NULL default ''
|
||||
description text NOT NULL default '',
|
||||
parent integer NOT NULL default '0',
|
||||
sortorder integer NOT NULL default '0',
|
||||
courseorder text NOT NULL default '',
|
||||
visible integer NOT NULL default '1',
|
||||
timemodified` integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
CREATE TABLE prefix_course_display (
|
||||
|
||||
+14
-3
@@ -725,7 +725,7 @@ function print_footer ($course=NULL) {
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||
}
|
||||
} else {
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot\">".get_string("home")."</a>";
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">".get_string("home")."</a>";
|
||||
$course = get_site();
|
||||
}
|
||||
|
||||
@@ -1079,6 +1079,17 @@ function update_module_button($moduleid, $courseid, $string) {
|
||||
}
|
||||
}
|
||||
|
||||
function update_category_button($categoryid) {
|
||||
// Prints the editing button on a module "view" page
|
||||
global $CFG;
|
||||
|
||||
if (isadmin()) {
|
||||
$string = get_string("editthiscategory");
|
||||
return "<form target=_parent method=get action=\"$CFG->wwwroot/course/category.php\">".
|
||||
"<input type=hidden name=id value=\"$categoryid\">".
|
||||
"<input type=submit value=\"$string\"></form>";
|
||||
}
|
||||
}
|
||||
|
||||
function navmenu($course, $cm=NULL) {
|
||||
// Given a course and a (current) coursemodule
|
||||
@@ -1184,7 +1195,7 @@ function error ($message, $link="") {
|
||||
$link = "$SESSION->fromurl";
|
||||
unset($SESSION->fromurl);
|
||||
} else {
|
||||
$link = "$CFG->wwwroot";
|
||||
$link = "$CFG->wwwroot/";
|
||||
}
|
||||
}
|
||||
print_continue($link);
|
||||
@@ -1245,7 +1256,7 @@ function notice ($message, $link="") {
|
||||
if (!empty($_SERVER["HTTP_REFERER"])) {
|
||||
$link = $_SERVER["HTTP_REFERER"];
|
||||
} else {
|
||||
$link = $CFG->wwwroot;
|
||||
$link = "$CFG->wwwroot/";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
// database to determine whether upgrades should
|
||||
// be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2003072800; // The current version is a date (YYYYMMDDXX)
|
||||
$version = 2003072803; // The current version is a date (YYYYMMDDXX)
|
||||
|
||||
$release = "1.1 development"; // User-friendly version number
|
||||
|
||||
|
||||
Reference in New Issue
Block a user