function search(&$fromform, &$result) { global $CFG, $USER; $terms = array('keyword', 'title', 'description'); // Initialize with the target URL $search = trim($fromform->search); $lang = strtolower(preg_replace('/\\_\\w+$/', '', $USER->lang)); foreach ($terms as $term) { $search = preg_replace('/' . $term . ':\\s*/', $term . '_' . $lang . ':', $search); } $url = 'http://localhost:7574/solr/select?q=' . $search . '&wt=php'; // is this a complete browse request? if ($fromform->search == '*') { $url = 'http://localhost:7574/solr/select?q=' . urlencode('keyword_' . $lang . ':[0 TO zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]') . '&wt=php'; } $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, TAORESOURCE_PLUGIN_CURL_TIMEOUT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Moodle'); $code = curl_exec($ch); if ($code === false) { $this->error[] = curl_errno($ch) . ':' . curl_error($ch); return false; } curl_close($ch); $qr = false; if ($code) { $code = "\$qr = " . $code . ";"; eval($code); } if ($qr && isset($qr['response']) && $qr['response']['numFound'] > 0) { $docs = $qr['response']['docs']; foreach ($docs as $doc) { if ($taoresource_entry = taoresource_entry::get_by_id((int) $doc['entry'])) { $result[] = $taoresource_entry; } } } return false; }
$type = optional_param('type', '', PARAM_ALPHANUM); $section = optional_param('section', 0, PARAM_INT); $mode = required_param('mode', PARAM_ALPHA); $course = required_param('course', PARAM_INT); $pagestep = optional_param('pagestep', 1, PARAM_INT); if (!($course = get_record("course", "id", $course))) { error("This course doesn't exist"); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); $pagetitle = strip_tags($course->shortname); // sort out how we should look depending on add or update if ($mode == 'update') { $entry_id = required_param('entry_id', PARAM_INT); $taoresource_entry = taoresource_entry::get_by_id($entry_id); $strpreview = get_string('preview', 'taoresource'); $taoresource_entry->url_display = "<a href=\"{$CFG->wwwroot}/mod/taoresource/view.php?identifier={$taoresource_entry->identifier}&inpopup=true\" " . "onclick=\"this.target='resource{$taoresource_entry->id}'; return openpopup('/mod/taoresource/view.php?inpopup=true&identifier={$taoresource_entry->identifier}', " . "'resource{$taoresource_entry->id}','resizable=1,scrollbars=1,directories=1,location=0,menubar=0,toolbar=0,status=1,width=800,height=600');\">(" . $strpreview . ")</a>"; $taoresource_entry->taoresourcefile = $taoresource_entry->file; } else { $mode = 'add'; $taoresource_entry = new taoresource_entry(); } // which form phase are we in - step 1 or step 2 $mform = false; if ($pagestep == 1) { $mform = new mod_taoresource_taoresource_entry_form($mode); $mform->set_data($taoresource_entry); } else { $mform = new mod_taoresource_taoresource_entry_extra_form($mode); $mform->set_data($taoresource_entry);
$fromform->{$parts}[0] = $parts[1]; } } } } $mform->set_data($fromform); $mform->display(); $fromform->search = isset($fromform->search) ? clean_param($fromform->search, PARAM_CLEAN) : clean_param(optional_param('search', '', PARAM_RAW), PARAM_CLEAN); $fromform->section = $section; $resources = array(); // if we have an id then we must have come here from the add page if (!empty($fromform->id)) { $resources[] = taoresource_entry::get_by_id($fromform->id); } else { if ($id) { $resources[] = taoresource_entry::get_by_id($id); } else { $resources = taoresource_entry::search($fromform); } } //output results in same format as ims finder.php if ($resources) { $totalcount = count($resources); $baseurl = $CFG->wwwroot . "/mod/taoresource/search.php?course={$course->id}§ion={$section}&type={$type}&add=taoresource&return={$return}&"; // serialise the search query and append to the paging URI $search_parameters = ''; foreach ($fromform as $fld => $val) { if (!in_array($fld, $exclude_inputs)) { if ($val === true) { $val = 'true'; } else {