$searchterm) {
if (strlen($searchterm) < 2) {
unset($searchterms[$key]);
}
}
$search = trim(implode(" ", $searchterms));
}
$site = get_site();
if ($CFG->forcelogin) {
require_login();
}
if (update_category_button()) {
if ($edit !== -1) {
$USER->categoryediting = $edit;
}
$adminediting = !empty($USER->categoryediting);
} else {
$adminediting = false;
}
/// Editing functions
if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM))) {
/// Hide or show a course
if ($hide or $show and confirm_sesskey()) {
if ($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!");
}
}
}
}
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM)) && $perpage != 99999) {
$perpage = 30;
}
$displaylist = array();
$parentlist = array();
make_categories_list($displaylist, $parentlist);
$strcourses = get_string("courses");
$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");
$strfrontpage = get_string('frontpage', 'admin');
$strnovalidcourses = get_string('novalidcourses');
if (empty($search) and empty($blocklist) and empty($modulelist)) {
$navlinks = array();
$navlinks[] = array('name' => $strcourses, 'link' => "index.php", 'type' => 'misc');
$navlinks[] = array('name' => $strsearch, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->fullname : $strsearch", $site->fullname, $navigation, "", "");
print_simple_box_start("center");
echo "
";
echo "
";
print_course_search("", false, "plain");
echo "
";
print_string("searchhelp");
echo "
";
echo "";
print_simple_box_end();
print_footer();
exit;
}
if (!empty($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);
}
// get list of courses containing blocks if required
if (!empty($blocklist) and confirm_sesskey()) {
$blockid = $blocklist;
if (!$blocks = get_records('block_instance', 'blockid', $blockid)) {
error( "Could not read data for blockid=$blockid" );
}
// run through blocks and get (unique) courses
$courses = array();
foreach ($blocks as $block) {
$courseid = $block->pageid;
// MDL-11167, blocks can be placed on mymoodle, or the blogs page
// and it should not show up on course search page
if ($courseid==0 || $block->pagetype != 'course-view') {
continue;
}
if (!$course = get_record('course', 'id', $courseid)) {
error( "Could not read data for courseid=$courseid" );
}
$courses[$courseid] = $course;
}
$totalcount = count( $courses );
}
// get list of courses containing modules if required
elseif (!empty($modulelist) and confirm_sesskey()) {
$modulename = $modulelist;
$sql = "SELECT DISTINCT c.id FROM {$CFG->prefix}".$modulelist." module, {$CFG->prefix}course c"
." WHERE module.course=c.id";
$courseids = get_records_sql($sql);
$courses = array();
if (!empty($courseids)) {
$firstcourse = $page*$perpage;
$lastcourse = $page*$perpage + $perpage -1;
$i = 0;
foreach ($courseids as $courseid) {
if ($i>= $firstcourse && $i<=$lastcourse) {
$courses[$courseid->id] = get_record('course', 'id', $courseid->id);
}
$i++;
}
$totalcount = count($courseids);
}
else {
$totalcount = 0;
}
}
else {
$courses = get_courses_search($searchterms, "fullname ASC",
$page, $perpage, $totalcount);
}
$searchform = print_course_search($search, true, "navbar");
if (!empty($courses) && has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
$searchform .= update_categories_search_button($search,$page,$perpage);
}
$navlinks = array();
$navlinks[] = array('name' => $strcourses, 'link' => 'index.php', 'type' => 'misc');
$navlinks[] = array('name' => $strsearch, 'link' => 'search.php', 'type' => 'misc');
$navlinks[] = array('name' => "'".s($search, true)."'", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->fullname : $strsearchresults", $site->fullname, $navigation, "", "", "", $searchform);
$lastcategory = -1;
if ($courses) {
print_heading("$strsearchresults: $totalcount");
$encodedsearch = urlencode(stripslashes($search));
///add the module parameter to the paging bar if they exists
$modulelink = "";
if (!empty($modulelist) and confirm_sesskey()) {
$modulelink = "&modulelist=".$modulelist."&sesskey=".$USER->sesskey;
}
print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $modulelink);
if (!$adminediting) {
/// Show browse view.
foreach ($courses as $course) {
$course->summary .= "
";
$course->summary .= "$strcategory: category\">";
$course->summary .= $displaylist[$course->category];
$course->summary .= "
";
print_course($course, $search);
print_spacer(5,5);
}
} else {
/// Show editing UI.
echo "";
}
print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink);
} else {
if (!empty($search)) {
print_heading(get_string("nocoursesfound", "", s($search, true)));
}
else {
print_heading( $strnovalidcourses );
}
}
echo "
";
print_course_search($search);
print_footer();
/**
* Print a list navigation bar
* Display page numbers, and a link for displaying all entries
* @param integer $totalcount - number of entry to display
* @param integer $page - page number
* @param integer $perpage - number of entry per page
* @param string $encodedsearch
* @param string $modulelink - module name
*/
function print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink) {
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch".$modulelink."&perpage=$perpage&",'page',($perpage == 99999));
//display
if ($perpage != 99999 && $totalcount > $perpage) {
echo "";
echo "".get_string("showall", "", $totalcount)."";
echo "
";
}
}
?>