3 /// Displays external information about a course
5 require_once("../config.php");
6 require_once("lib.php");
8 $search = optional_param('search', '', PARAM_RAW
); // search words
9 $page = optional_param('page', 0, PARAM_INT
); // which page to show
10 $perpage = optional_param('perpage', 10, PARAM_INT
); // how many per page
11 $moveto = optional_param('moveto', 0, PARAM_INT
); // move to category
12 $edit = optional_param('edit', -1, PARAM_BOOL
);
13 $hide = optional_param('hide', 0, PARAM_INT
);
14 $show = optional_param('show', 0, PARAM_INT
);
15 $blocklist = optional_param('blocklist', 0, PARAM_INT
);
16 $modulelist= optional_param('modulelist', '', PARAM_ALPHAEXT
);
18 $search = trim(strip_tags($search)); // trim & clean raw searched string
21 $searchterms = explode(" ", $search); // Search for words independently
22 foreach ($searchterms as $key => $searchterm) {
23 if (strlen($searchterm) < 2) {
24 unset($searchterms[$key]);
27 $search = trim(implode(" ", $searchterms));
32 if ($CFG->forcelogin
) {
36 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
38 $USER->categoryediting
= $edit;
39 // If the edit mode we are leaving has higher per page than the one we are entering,
40 // with pages, chances are you will get a no courses found error. So when we are switching
41 // modes, set page to 0.
48 if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
50 /// Hide or show a course
52 if ($hide or $show and confirm_sesskey()) {
54 $course = get_record("course", "id", $hide);
57 $course = get_record("course", "id", $show);
61 if (! set_field("course", "visible", $visible, "id", $course->id
)) {
62 notify("Could not update that course!");
69 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
)) && $perpage != 99999) {
73 $displaylist = array();
74 $parentlist = array();
75 make_categories_list($displaylist, $parentlist, "");
77 $strcourses = get_string("courses");
78 $strsearch = get_string("search");
79 $strsearchresults = get_string("searchresults");
80 $strcategory = get_string("category");
81 $strselect = get_string("select");
82 $strselectall = get_string("selectall");
83 $strdeselectall = get_string("deselectall");
84 $stredit = get_string("edit");
85 $strfrontpage = get_string('frontpage', 'admin');
86 $strnovalidcourses = get_string('novalidcourses');
88 if (empty($search) and empty($blocklist) and empty($modulelist)) {
90 $navlinks[] = array('name' => $strcourses, 'link' => "index.php", 'type' => 'misc');
91 $navlinks[] = array('name' => $strsearch, 'link' => null, 'type' => 'misc');
92 $navigation = build_navigation($navlinks);
94 print_header("$site->fullname : $strsearch", $site->fullname
, $navigation, "", "");
95 print_simple_box_start("center");
98 print_course_search("", false, "plain");
100 print_string("searchhelp");
103 print_simple_box_end();
108 if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved
110 if (! $destcategory = get_record("course_categories", "id", $data->moveto
)) {
111 error("Error finding the category");
115 foreach ( $data as $key => $value ) {
116 if (preg_match('/^c\d+$/', $key)) {
117 array_push($courses, substr($key, 1));
120 move_courses($courses, $data->moveto
);
123 // get list of courses containing blocks if required
124 if (!empty($blocklist) and confirm_sesskey()) {
125 $blockid = $blocklist;
126 if (!$blocks = get_records('block_instance', 'blockid', $blockid)) {
127 error( "Could not read data for blockid=$blockid" );
130 // run through blocks and get (unique) courses
132 foreach ($blocks as $block) {
133 $courseid = $block->pageid
;
137 if (!$course = get_record('course', 'id', $courseid)) {
138 error( "Could not read data for courseid=$courseid" );
140 $courses[$courseid] = $course;
142 $totalcount = count( $courses );
144 // get list of courses containing modules if required
145 elseif (!empty($modulelist) and confirm_sesskey()) {
146 $modulename = $modulelist;
147 if (!$modules = get_records($modulename)) {
148 error( "Could not read data for module=$modulename" );
151 // run through modules and get (unique) courses
153 foreach ($modules as $module) {
154 $courseid = $module->course
;
158 if (!$course = get_record('course', 'id', $courseid)) {
159 error( "Could not read data for courseid=$courseid" );
161 $courses[$courseid] = $course;
163 $totalcount = count($courses);
166 $courses = get_courses_search($searchterms, "fullname ASC",
167 $page*$perpage, $perpage, $totalcount);
170 $searchform = print_course_search($search, true, "navbar");
172 if (!empty($courses) && has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
173 $searchform .= update_categories_search_button($search,$page,$perpage);
177 print_header("$site->fullname : $strsearchresults", $site->fullname
,
178 "<a href=\"index.php\">$strcourses</a> -> <a href=\"search.php\">$strsearch</a> -> '".s($search, true)."'", "", "", "", $searchform);
184 print_heading("$strsearchresults: $totalcount");
186 $encodedsearch = urlencode(stripslashes($search));
187 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999));
189 if ($perpage != 99999 && $totalcount > $perpage) {
191 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
192 echo "</p></center>";
195 if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
196 foreach ($courses as $course) {
197 $course->fullname
= highlight("$search", $course->fullname
);
198 $course->summary
= highlight("$search", $course->summary
);
199 $course->summary
.= "<br /><p class=\"category\">";
200 $course->summary
.= "$strcategory: <a href=\"category.php?id=$course->category\">";
201 $course->summary
.= $displaylist[$course->category
];
202 $course->summary
.= "</a></p>";
203 print_course($course);
206 } else { // slightly more sophisticated
208 echo "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n";
209 echo "<div><input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
210 echo "<input type=\"hidden\" name=\"search\" value=\"".s($search, true)."\" />\n";
211 echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
212 echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\" /></div>\n";
213 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\" class=\"generalbox boxaligncenter\">\n<tr>\n";
214 echo "<th scope=\"col\">$strcourses</th>\n";
215 echo "<th scope=\"col\">$strcategory</th>\n";
216 echo "<th scope=\"col\">$strselect</th>\n";
217 echo "<th scope=\"col\">$stredit</th></tr>\n";
218 foreach ($courses as $course) {
220 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
222 $course->fullname
= highlight("$search", $course->fullname
);
223 $linkcss = $course->visible ?
"" : " class=\"dimmed\" ";
225 // are we displaying the front page (courseid=1)?
226 if ($course->id
== 1) {
228 echo "<td><a href=\"$CFG->wwwroot\">$strfrontpage</a></td>\n";
230 // can't do anything else with the front page
231 echo " <td> </td>\n"; // category place
232 echo " <td> </td>\n"; // select place
233 echo " <td> </td>\n"; // edit place
239 echo "<td><a $linkcss href=\"view.php?id=$course->id\">"
240 . format_string($course->fullname
) . "</a></td>\n";
241 echo "<td>".$displaylist[$course->category
]."</td>\n";
244 // this is ok since this will get inherited from course category context
246 if (has_capability('moodle/category:update', $coursecontext)) {
247 echo "<input type=\"checkbox\" name=\"c$course->id\" />\n";
249 echo "<input type=\"checkbox\" name=\"c$course->id\" disabled=\"disabled\" />\n";
254 $pixpath = $CFG->pixpath
;
256 // checks whether user can update course settings
257 if (has_capability('moodle/course:update', $coursecontext)) {
258 echo "<a title=\"".get_string("settings")."\" href=\"$CFG->wwwroot/course/edit.php?id=$course->id\">\n<img".
259 " src=\"$pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"".get_string("settings")."\" /></a>\n ";
262 // checks whether user can do role assignment
263 if (has_capability('moodle/role:assign', $coursecontext)) {
264 echo'<a title="'.get_string('assignroles', 'role').'" href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$coursecontext->id
.'">';
265 echo '<img src="'.$CFG->pixpath
.'/i/roles.gif" class="iconsmall" alt="'.get_string('assignroles', 'role').'" /></a> ' . "\n";
268 // checks whether user can delete course
269 if (has_capability('moodle/course:delete', $coursecontext)) {
270 echo "<a title=\"".get_string("delete")."\" href=\"delete.php?id=$course->id\">\n<img".
271 " src=\"$pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"".get_string("delete")."\" /></a>\n ";
274 // checks whether user can change visibility
275 if (has_capability('moodle/course:visibility', $coursecontext)) {
276 if (!empty($course->visible
)) {
277 echo "<a title=\"".get_string("hide")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&hide=$course->id&sesskey=$USER->sesskey\">\n<img".
278 " src=\"$pixpath/t/hide.gif\" class=\"iconsmall\" alt=\"".get_string("hide")."\" /></a>\n ";
280 echo "<a title=\"".get_string("show")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&show=$course->id&sesskey=$USER->sesskey\">\n<img".
281 " src=\"$pixpath/t/show.gif\" class=\"iconsmall\" alt=\"".get_string("show")."\" /></a>\n ";
285 // checks whether user can do site backup
286 if (has_capability('moodle/site:backup', $coursecontext)) {
287 echo "<a title=\"".get_string("backup")."\" href=\"../backup/backup.php?id=$course->id\">\n<img".
288 " src=\"$pixpath/t/backup.gif\" class=\"iconsmall\" alt=\"".get_string("backup")."\" /></a>\n ";
291 // checks whether user can do restore
292 if (has_capability('moodle/site:restore', $coursecontext)) {
293 echo "<a title=\"".get_string("restore")."\" href=\"../files/index.php?id=$course->id&wdir=/backupdata\">\n<img".
294 " src=\"$pixpath/t/restore.gif\" class=\"iconsmall\" alt=\"".get_string("restore")."\" /></a>\n ";
297 echo "</td>\n</tr>\n";
299 echo "<tr>\n<td colspan=\"4\" style=\"text-align:center\">\n";
301 echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n";
302 echo "<input type=\"button\" onclick=\"uncheckall()\" value=\"$strdeselectall\" />\n";
303 choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript: getElementById('movecourses').submit()");
304 echo "</td>\n</tr>\n";
305 echo "</table>\n</form>";
309 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999));
311 if ($perpage != 99999 && $totalcount > $perpage) {
313 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
314 echo "</p></center>";
318 if (!empty($search)) {
319 print_heading(get_string("nocoursesfound", "", s($search, true)));
322 print_heading( $strnovalidcourses );
328 print_course_search($search);