| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: search.php,v 1.49.2.2 2008/04/24 08:35:47 dongsheng Exp $ 2 3 /// Displays external information about a course 4 5 require_once("../config.php"); 6 require_once ("lib.php"); 7 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); 17 18 $search = trim(strip_tags($search)); // trim & clean raw searched string 19 20 if ($search) { 21 $searchterms = explode(" ", $search); // Search for words independently 22 foreach ($searchterms as $key => $searchterm) { 23 if (strlen($searchterm) < 2) { 24 unset($searchterms[$key]); 25 } 26 } 27 $search = trim(implode(" ", $searchterms)); 28 } 29 30 $site = get_site(); 31 32 if ($CFG->forcelogin) { 33 require_login(); 34 } 35 36 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) { 37 if ($edit !== -1) { 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. 42 $page = 0; 43 } 44 } 45 46 /// Editing functions 47 48 if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM))) { 49 50 /// Hide or show a course 51 52 if ($hide or $show and confirm_sesskey()) { 53 if ($hide) { 54 $course = get_record("course", "id", $hide); 55 $visible = 0; 56 } else { 57 $course = get_record("course", "id", $show); 58 $visible = 1; 59 } 60 if ($course) { 61 if (! set_field("course", "visible", $visible, "id", $course->id)) { 62 notify("Could not update that course!"); 63 } 64 } 65 } 66 67 } 68 69 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM)) && $perpage != 99999) { 70 $perpage = 30; 71 } 72 73 $displaylist = array(); 74 $parentlist = array(); 75 make_categories_list($displaylist, $parentlist, ""); 76 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'); 87 88 if (empty($search) and empty($blocklist) and empty($modulelist)) { 89 $navlinks = array(); 90 $navlinks[] = array('name' => $strcourses, 'link' => "index.php", 'type' => 'misc'); 91 $navlinks[] = array('name' => $strsearch, 'link' => null, 'type' => 'misc'); 92 $navigation = build_navigation($navlinks); 93 94 print_header("$site->fullname : $strsearch", $site->fullname, $navigation, "", ""); 95 print_simple_box_start("center"); 96 echo "<center>"; 97 echo "<br />"; 98 print_course_search("", false, "plain"); 99 echo "<br /><p>"; 100 print_string("searchhelp"); 101 echo "</p>"; 102 echo "</center>"; 103 print_simple_box_end(); 104 print_footer(); 105 exit; 106 } 107 108 if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved 109 110 if (! $destcategory = get_record("course_categories", "id", $data->moveto)) { 111 error("Error finding the category"); 112 } 113 114 $courses = array(); 115 foreach ( $data as $key => $value ) { 116 if (preg_match('/^c\d+$/', $key)) { 117 array_push($courses, substr($key, 1)); 118 } 119 } 120 move_courses($courses, $data->moveto); 121 } 122 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" ); 128 } 129 130 // run through blocks and get (unique) courses 131 $courses = array(); 132 foreach ($blocks as $block) { 133 $courseid = $block->pageid; 134 // MDL-11167, blocks can be placed on mymoodle, or the blogs page 135 // and it should not show up on course search page 136 if ($courseid==0 || $block->pagetype != 'course-view') { 137 continue; 138 } 139 if (!$course = get_record('course', 'id', $courseid)) { 140 error( "Could not read data for courseid=$courseid" ); 141 } 142 $courses[$courseid] = $course; 143 } 144 $totalcount = count( $courses ); 145 } 146 // get list of courses containing modules if required 147 elseif (!empty($modulelist) and confirm_sesskey()) { 148 $modulename = $modulelist; 149 if (!$modules = get_records($modulename)) { 150 error( "Could not read data for module=$modulename" ); 151 } 152 153 // run through modules and get (unique) courses 154 $courses = array(); 155 foreach ($modules as $module) { 156 $courseid = $module->course; 157 if ($courseid==0) { 158 continue; 159 } 160 if (!$course = get_record('course', 'id', $courseid)) { 161 error( "Could not read data for courseid=$courseid" ); 162 } 163 $courses[$courseid] = $course; 164 } 165 $totalcount = count($courses); 166 } 167 else { 168 $courses = get_courses_search($searchterms, "fullname ASC", 169 $page, $perpage, $totalcount); 170 } 171 172 $searchform = print_course_search($search, true, "navbar"); 173 174 if (!empty($courses) && has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) { 175 $searchform .= update_categories_search_button($search,$page,$perpage); 176 } 177 178 $navlinks = array(); 179 $navlinks[] = array('name' => $strcourses, 'link' => 'index.php', 'type' => 'misc'); 180 $navlinks[] = array('name' => $strsearch, 'link' => 'search.php', 'type' => 'misc'); 181 $navlinks[] = array('name' => "'".s($search, true)."'", 'link' => null, 'type' => 'misc'); 182 $navigation = build_navigation($navlinks); 183 184 print_header("$site->fullname : $strsearchresults", $site->fullname, $navigation, "", "", "", $searchform); 185 186 187 $lastcategory = -1; 188 if ($courses) { 189 190 print_heading("$strsearchresults: $totalcount"); 191 192 $encodedsearch = urlencode(stripslashes($search)); 193 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); 194 195 if ($perpage != 99999 && $totalcount > $perpage) { 196 echo "<center><p>"; 197 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>"; 198 echo "</p></center>"; 199 } 200 201 if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { 202 foreach ($courses as $course) { 203 $course->fullname = highlight("$search", $course->fullname); 204 $course->summary = highlight("$search", $course->summary); 205 $course->summary .= "<br /><p class=\"category\">"; 206 $course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">"; 207 $course->summary .= $displaylist[$course->category]; 208 $course->summary .= "</a></p>"; 209 print_course($course); 210 print_spacer(5,5); 211 } 212 } else { // slightly more sophisticated 213 214 echo "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n"; 215 echo "<div><input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n"; 216 echo "<input type=\"hidden\" name=\"search\" value=\"".s($search, true)."\" />\n"; 217 echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />\n"; 218 echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\" /></div>\n"; 219 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\" class=\"generalbox boxaligncenter\">\n<tr>\n"; 220 echo "<th scope=\"col\">$strcourses</th>\n"; 221 echo "<th scope=\"col\">$strcategory</th>\n"; 222 echo "<th scope=\"col\">$strselect</th>\n"; 223 echo "<th scope=\"col\">$stredit</th></tr>\n"; 224 225 foreach ($courses as $course) { 226 227 if (isset($course->context)) { 228 $coursecontext = $course->context; 229 } else { 230 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 231 } 232 233 $course->fullname = highlight("$search", $course->fullname); 234 $linkcss = $course->visible ? "" : " class=\"dimmed\" "; 235 236 // are we displaying the front page (courseid=1)? 237 if ($course->id == 1) { 238 echo "<tr>\n"; 239 echo "<td><a href=\"$CFG->wwwroot\">$strfrontpage</a></td>\n"; 240 241 // can't do anything else with the front page 242 echo " <td> </td>\n"; // category place 243 echo " <td> </td>\n"; // select place 244 echo " <td> </td>\n"; // edit place 245 echo "</tr>\n"; 246 continue; 247 } 248 249 echo "<tr>\n"; 250 echo "<td><a $linkcss href=\"view.php?id=$course->id\">" 251 . format_string($course->fullname) . "</a></td>\n"; 252 echo "<td>".$displaylist[$course->category]."</td>\n"; 253 echo "<td>\n"; 254 255 // this is ok since this will get inherited from course category context 256 // if it is set 257 if (has_capability('moodle/category:update', $coursecontext)) { 258 echo "<input type=\"checkbox\" name=\"c$course->id\" />\n"; 259 } else { 260 echo "<input type=\"checkbox\" name=\"c$course->id\" disabled=\"disabled\" />\n"; 261 } 262 263 echo "</td>\n"; 264 echo "<td>\n"; 265 $pixpath = $CFG->pixpath; 266 267 // checks whether user can update course settings 268 if (has_capability('moodle/course:update', $coursecontext)) { 269 echo "<a title=\"".get_string("settings")."\" href=\"$CFG->wwwroot/course/edit.php?id=$course->id\">\n<img". 270 " src=\"$pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"".get_string("settings")."\" /></a>\n "; 271 } 272 273 // checks whether user can do role assignment 274 if (has_capability('moodle/role:assign', $coursecontext)) { 275 echo'<a title="'.get_string('assignroles', 'role').'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$coursecontext->id.'">'; 276 echo '<img src="'.$CFG->pixpath.'/i/roles.gif" class="iconsmall" alt="'.get_string('assignroles', 'role').'" /></a> ' . "\n"; 277 } 278 279 // checks whether user can delete course 280 if (has_capability('moodle/course:delete', $coursecontext)) { 281 echo "<a title=\"".get_string("delete")."\" href=\"delete.php?id=$course->id\">\n<img". 282 " src=\"$pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"".get_string("delete")."\" /></a>\n "; 283 } 284 285 // checks whether user can change visibility 286 if (has_capability('moodle/course:visibility', $coursecontext)) { 287 if (!empty($course->visible)) { 288 echo "<a title=\"".get_string("hide")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&hide=$course->id&sesskey=$USER->sesskey\">\n<img". 289 " src=\"$pixpath/t/hide.gif\" class=\"iconsmall\" alt=\"".get_string("hide")."\" /></a>\n "; 290 } else { 291 echo "<a title=\"".get_string("show")."\" href=\"search.php?search=$encodedsearch&perpage=$perpage&page=$page&show=$course->id&sesskey=$USER->sesskey\">\n<img". 292 " src=\"$pixpath/t/show.gif\" class=\"iconsmall\" alt=\"".get_string("show")."\" /></a>\n "; 293 } 294 } 295 296 // checks whether user can do site backup 297 if (has_capability('moodle/site:backup', $coursecontext)) { 298 echo "<a title=\"".get_string("backup")."\" href=\"../backup/backup.php?id=$course->id\">\n<img". 299 " src=\"$pixpath/t/backup.gif\" class=\"iconsmall\" alt=\"".get_string("backup")."\" /></a>\n "; 300 } 301 302 // checks whether user can do restore 303 if (has_capability('moodle/site:restore', $coursecontext)) { 304 echo "<a title=\"".get_string("restore")."\" href=\"../files/index.php?id=$course->id&wdir=/backupdata\">\n<img". 305 " src=\"$pixpath/t/restore.gif\" class=\"iconsmall\" alt=\"".get_string("restore")."\" /></a>\n "; 306 } 307 308 echo "</td>\n</tr>\n"; 309 } 310 echo "<tr>\n<td colspan=\"4\" style=\"text-align:center\">\n"; 311 echo "<br />"; 312 echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n"; 313 echo "<input type=\"button\" onclick=\"uncheckall()\" value=\"$strdeselectall\" />\n"; 314 choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript: getElementById('movecourses').submit()"); 315 echo "</td>\n</tr>\n"; 316 echo "</table>\n</form>"; 317 318 } 319 320 print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); 321 322 if ($perpage != 99999 && $totalcount > $perpage) { 323 echo "<center><p>"; 324 echo "<a href=\"search.php?search=$encodedsearch&perpage=99999\">".get_string("showall", "", $totalcount)."</a>"; 325 echo "</p></center>"; 326 } 327 328 } else { 329 if (!empty($search)) { 330 print_heading(get_string("nocoursesfound", "", s($search, true))); 331 } 332 else { 333 print_heading( $strnovalidcourses ); 334 } 335 } 336 337 echo "<br /><br />"; 338 339 print_course_search($search); 340 341 print_footer(); 342 343 344 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |