$searchterm) { if (strlen($searchterm) < 2) { unset($searchterms[$key]); } } $search = trim(implode(" ", $searchterms)); } $site = get_site(); if ($CFG->forcelogin) { require_login(); } if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) { if ($edit !== -1) { $USER->categoryediting = $edit; // If the edit mode we are leaving has higher per page than the one we are entering, // with pages, chances are you will get a no courses found error. So when we are switching // modes, set page to 0. $page = 0; } } /// 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 = $DB->get_record("course", array("id"=>$hide)); $visible = 0; } else { $course = $DB->get_record("course", array("id"=>$show)); $visible = 1; } if ($course) { if (! $DB->set_field("course", "visible", $visible, array("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(false) and confirm_sesskey()) { // Some courses are being moved if (! $destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) { print_error('cannotfindcategory', '', '', $data->moveto); } $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 = $DB->get_records('block_instance', array('blockid'=>$blockid))) { print_error('blockcannotread', '', '', $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 = $DB->get_record('course', array('id'=>$courseid))) { print_error('invalidcourseid', '', '', $courseid); } $courses[$courseid] = $course; } $totalcount = count( $courses ); } // get list of courses containing modules if required elseif (!empty($modulelist) and confirm_sesskey()) { $modulename = $modulelist; if (!$modules = $DB->get_records($modulename)) { print_error('invalidmodulename', '', '', $modulename); } // run through modules and get (unique) courses $courses = array(); foreach ($modules as $module) { $courseid = $module->course; if ($courseid==0) { continue; } if (!$course = $DB->get_record('course', array('id'=>$courseid))) { print_error('invalidcourseid', '', '', $courseid); } $courses[$courseid] = $course; } $totalcount = count($courses); } 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)."'", '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($search); print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); if ($perpage != 99999 && $totalcount > $perpage) { echo "

"; echo "".get_string("showall", "", $totalcount).""; echo "

"; } if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { foreach ($courses as $course) { $course->fullname = highlight(trim($search, '+'), $course->fullname); $course->summary = highlight(trim($search, '+'), $course->summary); $course->summary .= "

"; $course->summary .= "$strcategory: category\">"; $course->summary .= $displaylist[$course->category]; $course->summary .= "

"; print_course($course); print_spacer(5,5); } } else { // slightly more sophisticated echo "
\n"; echo "
sesskey\" />\n"; echo "\n"; echo "\n"; echo "
\n"; echo "\n\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; foreach ($courses as $course) { if (isset($course->context)) { $coursecontext = $course->context; } else { $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); } $course->fullname = highlight(trim($search, '+'), $course->fullname); $linkcss = $course->visible ? "" : " class=\"dimmed\" "; // are we displaying the front page (courseid=1)? if ($course->id == 1) { echo "\n"; echo "\n"; // can't do anything else with the front page echo " \n"; // category place echo " \n"; // select place echo " \n"; // edit place echo "\n"; continue; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n\n"; } echo "\n\n\n"; echo "
$strcourses$strcategory$strselect$stredit
wwwroot\">$strfrontpage   
id\">" . format_string($course->fullname) . "".$displaylist[$course->category]."\n"; // this is ok since this will get inherited from course category context // if it is set if (has_capability('moodle/category:update', $coursecontext)) { echo "id\" />\n"; } else { echo "id\" disabled=\"disabled\" />\n"; } echo "\n"; $pixpath = $CFG->pixpath; // checks whether user can update course settings if (has_capability('moodle/course:update', $coursecontext)) { echo "wwwroot/course/edit.php?id=$course->id\">\n\n "; } // checks whether user can do role assignment if (has_capability('moodle/role:assign', $coursecontext)) { echo''; echo ''.get_string('assignroles', 'role').' ' . "\n"; } // checks whether user can delete course if (has_capability('moodle/course:delete', $coursecontext)) { echo "id\">\n\n "; } // checks whether user can change visibility if (has_capability('moodle/course:visibility', $coursecontext)) { if (!empty($course->visible)) { echo "id&sesskey=$USER->sesskey\">\n\n "; } else { echo "id&sesskey=$USER->sesskey\">\n\n "; } } // checks whether user can do site backup if (has_capability('moodle/site:backup', $coursecontext)) { echo "id\">\n\n "; } // checks whether user can do restore if (has_capability('moodle/site:restore', $coursecontext)) { echo "id&wdir=/backupdata\">\n\n "; } echo "
\n"; echo "
"; echo "\n"; echo "\n"; choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript: getElementById('movecourses').submit()"); echo "
\n
"; } print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); if ($perpage != 99999 && $totalcount > $perpage) { echo "

"; echo "".get_string("showall", "", $totalcount).""; echo "

"; } } else { if (!empty($search)) { print_heading(get_string("nocoursesfound", "", s($search))); } else { print_heading( $strnovalidcourses ); } } echo "

"; print_course_search($search); print_footer(); ?>