. /** * @package mod_forum * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../../config.php'); require_once('lib.php'); $id = required_param('id', PARAM_INT); // course id $search = trim(optional_param('search', '', PARAM_NOTAGS)); // search string $page = optional_param('page', 0, PARAM_INT); // which page to show $perpage = optional_param('perpage', 10, PARAM_INT); // how many per page $showform = optional_param('showform', 0, PARAM_INT); // Just show the form $user = trim(optional_param('user', '', PARAM_NOTAGS)); // Names to search for $userid = trim(optional_param('userid', 0, PARAM_INT)); // UserID to search for $forumid = trim(optional_param('forumid', 0, PARAM_INT)); // ForumID to search for $subject = trim(optional_param('subject', '', PARAM_NOTAGS)); // Subject $phrase = trim(optional_param('phrase', '', PARAM_NOTAGS)); // Phrase $words = trim(optional_param('words', '', PARAM_NOTAGS)); // Words $fullwords = trim(optional_param('fullwords', '', PARAM_NOTAGS)); // Whole words $notwords = trim(optional_param('notwords', '', PARAM_NOTAGS)); // Words we don't want $tags = optional_param_array('tags', [], PARAM_TEXT); $timefromrestrict = optional_param('timefromrestrict', 0, PARAM_INT); // Use starting date $fromday = optional_param('fromday', 0, PARAM_INT); // Starting date $frommonth = optional_param('frommonth', 0, PARAM_INT); // Starting date $fromyear = optional_param('fromyear', 0, PARAM_INT); // Starting date $fromhour = optional_param('fromhour', 0, PARAM_INT); // Starting date $fromminute = optional_param('fromminute', 0, PARAM_INT); // Starting date if ($timefromrestrict) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregorianfrom = $calendartype->convert_to_gregorian($fromyear, $frommonth, $fromday); $datefrom = make_timestamp($gregorianfrom['year'], $gregorianfrom['month'], $gregorianfrom['day'], $fromhour, $fromminute); } else { $datefrom = optional_param('datefrom', 0, PARAM_INT); // Starting date } $timetorestrict = optional_param('timetorestrict', 0, PARAM_INT); // Use ending date $today = optional_param('today', 0, PARAM_INT); // Ending date $tomonth = optional_param('tomonth', 0, PARAM_INT); // Ending date $toyear = optional_param('toyear', 0, PARAM_INT); // Ending date $tohour = optional_param('tohour', 0, PARAM_INT); // Ending date $tominute = optional_param('tominute', 0, PARAM_INT); // Ending date if ($timetorestrict) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregorianto = $calendartype->convert_to_gregorian($toyear, $tomonth, $today); $dateto = make_timestamp($gregorianto['year'], $gregorianto['month'], $gregorianto['day'], $tohour, $tominute); } else { $dateto = optional_param('dateto', 0, PARAM_INT); // Ending date } $PAGE->set_pagelayout('standard'); $PAGE->set_url($FULLME); //TODO: this is very sloppy --skodak if (empty($search)) { // Check the other parameters instead if (!empty($words)) { $search .= ' '.$words; } if (!empty($userid)) { $search .= ' userid:'.$userid; } if (!empty($forumid)) { $search .= ' forumid:'.$forumid; } if (!empty($user)) { $search .= ' '.forum_clean_search_terms($user, 'user:'); } if (!empty($subject)) { $search .= ' '.forum_clean_search_terms($subject, 'subject:'); } if (!empty($fullwords)) { $search .= ' '.forum_clean_search_terms($fullwords, '+'); } if (!empty($notwords)) { $search .= ' '.forum_clean_search_terms($notwords, '-'); } if (!empty($phrase)) { $search .= ' "'.$phrase.'"'; } if (!empty($datefrom)) { $search .= ' datefrom:'.$datefrom; } if (!empty($dateto)) { $search .= ' dateto:'.$dateto; } if (!empty($tags)) { $search .= ' tags:' . implode(',', $tags); } $individualparams = true; } else { $individualparams = false; } if ($search) { $search = forum_clean_search_terms($search); } if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } require_course_login($course); $params = array( 'context' => $PAGE->context, 'other' => array('searchterm' => $search) ); $event = \mod_forum\event\course_searched::create($params); $event->trigger(); $strforums = get_string("modulenameplural", "forum"); $strsearch = get_string("search", "forum"); $strsearchresults = get_string("searchresults", "forum"); $strpage = get_string("page"); if (!$search || $showform) { $PAGE->navbar->add($strforums, new moodle_url('/mod/forum/index.php', array('id'=>$course->id))); $PAGE->navbar->add(get_string('advancedsearch', 'forum')); $PAGE->set_title($strsearch); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); forum_print_big_search_form($course); echo $OUTPUT->footer(); exit; } /// We need to do a search now and print results $searchterms = str_replace('forumid:', 'instance:', $search); $searchterms = explode(' ', $searchterms); $searchform = forum_search_form($course, $search); $PAGE->navbar->add($strsearch, new moodle_url('/mod/forum/search.php', array('id'=>$course->id))); $PAGE->navbar->add($strsearchresults); if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) { $PAGE->set_title($strsearchresults); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($strforums, 2); echo $OUTPUT->heading($strsearchresults, 3); echo $OUTPUT->heading(get_string("noposts", "forum"), 4); if (!$individualparams) { $words = $search; } forum_print_big_search_form($course); echo $OUTPUT->footer(); exit; } //including this here to prevent it being included if there are no search results require_once($CFG->dirroot.'/rating/lib.php'); //set up the ratings information that will be the same for all posts $ratingoptions = new stdClass(); $ratingoptions->component = 'mod_forum'; $ratingoptions->ratingarea = 'post'; $ratingoptions->userid = $USER->id; $ratingoptions->returnurl = $PAGE->url->out(false); $rm = new rating_manager(); $PAGE->set_title($strsearchresults); $PAGE->set_heading($course->fullname); $PAGE->set_button($searchform); echo $OUTPUT->header(); echo '