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
);
16 $search = trim(strip_tags($search)); // trim & clean raw searched string
19 $searchterms = explode(" ", $search); // Search for words independently
20 foreach ($searchterms as $key => $searchterm) {
21 if (strlen($searchterm) < 2) {
22 unset($searchterms[$key]);
25 $search = trim(implode(" ", $searchterms));
30 if ($CFG->forcelogin
) {
34 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
36 $USER->categoryediting
= $edit;
37 // If the edit mode we are leaving has higher per page than the one we are entering,
38 // with pages, chances are you will get a no courses found error. So when we are switching
39 // modes, set page to 0.
46 if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
48 /// Hide or show a course
50 if ($hide or $show and confirm_sesskey()) {
52 $course = get_record("course", "id", $hide);
55 $course = get_record("course", "id", $show);
59 if (! set_field("course", "visible", $visible, "id", $course->id
)) {
60 notify("Could not update that course!");
67 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
)) && $perpage != 99999) {
71 $displaylist = array();
72 $parentlist = array();
73 make_categories_list($displaylist, $parentlist, "");
75 $strcourses = get_string("courses");
76 $strsearch = get_string("search");
77 $strsearchresults = get_string("searchresults");
78 $strcategory = get_string("category");
79 $strselect = get_string("select");
80 $strselectall = get_string("selectall");
81 $strdeselectall = get_string("deselectall");
82 $stredit = get_string("edit");
85 print_header("$site->fullname : $strsearch", $site->fullname
,
86 "<a href=\"index.php\">$strcourses</a> -> $strsearch", "", "");
87 print_simple_box_start("center");
90 print_course_search("", false, "plain");
92 print_string("searchhelp");
95 print_simple_box_end();
100 if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved
102 if (! $destcategory = get_record("course_categories", "id", $data->moveto
)) {
103 error("Error finding the category");
107 foreach ( $data as $key => $value ) {
108 if (preg_match('/^c\d+$/', $key)) {
109 array_push($courses, substr($key, 1));
112 move_courses($courses, $data->moveto
);
115 $courses = get_courses_search($searchterms, "fullname ASC",
116 $page*$perpage, $perpage, $totalcount);
118 $searchform = print_course_search($search, true, "navbar");
120 if (!empty($courses) && has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
121 $searchform .= update_categories_search_button($search,$page,$perpage);
125 print_header("$site->fullname : $strsearchresults", $site->fullname
,
126 "<a href=\"index.php\">$strcourses</a> -> <a href=\"search.php\">$strsearch</a> -> '".s($search, true)."'", "", "", "", $searchform);
132 print_heading("$strsearchresults: $totalcount");
134 $encodedsearch = urlencode(stripslashes($search));
135 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999));
137 if ($perpage != 99999 && $totalcount > $perpage) {
139 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
140 echo "</p></center>";
143 if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
144 foreach ($courses as $course) {
145 $course->fullname
= highlight("$search", $course->fullname
);
146 $course->summary
= highlight("$search", $course->summary
);
147 $course->summary
.= "<br /><p align=\"right\">";
148 $course->summary
.= "$strcategory: <a href=\"category.php?id=$course->category\">";
149 $course->summary
.= $displaylist[$course->category
];
150 $course->summary
.= "</a></p>";
151 print_course($course);
154 } else { // slightly more sophisticated
156 echo "<form name=\"movecourses\" action=\"search.php\" method=\"post\">";
157 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\">";
158 echo "<input type=\"hidden\" name=\"search\" value=\"".s($search, true)."\">";
159 echo "<input type=\"hidden\" name=\"page\" value=\"$page\">";
160 echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\">";
161 echo "<table align=\"center\" border=0 cellspacing=2 cellpadding=4 class=\"generalbox\"><tr>";
162 echo "<th>$strcourses</th>";
163 echo "<th>$strcategory</th>";
164 echo "<th>$strselect</th>";
165 echo "<th>$stredit</th>";
166 foreach ($courses as $course) {
168 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
170 $course->fullname
= highlight("$search", $course->fullname
);
171 $linkcss = $course->visible ?
"" : " class=\"dimmed\" ";
173 echo "<td><a $linkcss href=\"view.php?id=$course->id\">$course->fullname</a></td>";
174 echo "<td>".$displaylist[$course->category
]."</td>";
175 echo "<td align=\"center\">";
177 // this is ok since this will get inherited from course category context
179 if (has_capability('moodle/category:update', $coursecontext)) {
180 echo "<input type=\"checkbox\" name=\"c$course->id\">";
182 echo "<input type=\"checkbox\" name=\"c$course->id\" disabled=\"disabled\">";
187 if (empty($THEME->custompix
)) {
188 $pixpath = "$CFG->wwwroot/pix";
190 $pixpath = "$CFG->themedir/$CFG->theme/pix";
193 // checks whether user can update course settings
194 if (has_capability('moodle/course:update', $coursecontext)) {
195 echo "<a title=\"".get_string("settings")."\" href=\"$CFG->wwwroot/course/edit.php?id=$course->id\"><img".
196 " src=\"$pixpath/t/edit.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
199 // checks whether user can do role assignment
200 if (has_capability('moodle/role:assign', $coursecontext)) {
201 echo'<a title="'.get_string('assignroles', 'role').'" href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$coursecontext->id
.'">';
202 echo '<img src="'.$CFG->pixpath
.'/i/roles.gif" height="11" width="11" alt="'.get_string('assignroles', 'role').'" /></a>';
205 // checks whether user can delete course
206 if (has_capability('moodle/course:delete', $coursecontext)) {
207 echo "<a title=\"".get_string("delete")."\" href=\"delete.php?id=$course->id\"><img".
208 " src=\"$pixpath/t/delete.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
211 // checks whether user can change visibility
212 if (has_capability('moodle/course:visibility', $coursecontext)) {
213 if (!empty($course->visible
)) {
214 echo "<a title=\"".get_string("hide")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&hide=$course->id&sesskey=$USER->sesskey\"><img".
215 " src=\"$pixpath/t/hide.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
217 echo "<a title=\"".get_string("show")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&show=$course->id&sesskey=$USER->sesskey\"><img".
218 " src=\"$pixpath/t/show.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
222 // checks whether user can do site backup
223 if (has_capability('moodle/site:backup', $coursecontext)) {
224 echo "<a title=\"".get_string("backup")."\" href=\"../backup/backup.php?id=$course->id\"><img".
225 " src=\"$pixpath/t/backup.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
228 // checks whether user can do restore
229 if (has_capability('moodle/site:restore', $coursecontext)) {
230 echo "<a title=\"".get_string("restore")."\" href=\"../files/index.php?id=$course->id&wdir=/backupdata\"><img".
231 " src=\"$pixpath/t/restore.gif\" height=\"11\" width=\"11\" border=\"0\"></a> ";
236 echo "<tr><td colspan=\"4\" align=\"center\">";
238 echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n";
239 echo "<input type=\"button\" onclick=\"uncheckall()\" value=\"$strdeselectall\" />\n";
240 choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript:document.movecourses.submit()");
246 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999));
248 if ($perpage != 99999 && $totalcount > $perpage) {
250 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
251 echo "</p></center>";
255 print_heading(get_string("nocoursesfound", "", s($search, true)));
260 print_course_search($search);