selfsearch.php 2.51 KB
Newer Older
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage core
6
 * @author     Catalyst IT Ltd
7 8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
9 10 11 12 13 14 15 16 17 18 19 20
 *
 */

define('INTERNAL', 1);
require('init.php');
define('TITLE', get_string('selfsearch'));

$query         = param_variable('query','');
$artefacttype  = param_variable('artefacttype','all');

$enc_jsonscript = json_encode(get_config('wwwroot') . 'json/selfsearch.php');
$enc_noresults  = json_encode(get_string('noresultsfound'));
21
$enc_pages = json_encode(get_string('listedinpages', 'view'));
22 23 24

$javascript = <<<EOF
var results = new TableRenderer(
25
    'searchresults',
26 27 28 29 30 31
    $enc_jsonscript,
    []
);
results.statevars.push('query');
results.statevars.push('type');
results.emptycontent = {$enc_noresults};
32
results.rowfunction = function (r, rownumber, d) {
33

Nigel McNie's avatar
Nigel McNie committed
34
    var titleElement;
35
    if (r.links && r.links._default) {
36
        titleElement = [jQuery('<h3>',{'class': 'title'}), jQuery('<a>', {'href': r.links._default, 'text': r.title})];
37 38 39
        delete r.links._default;
    }
    else {
40
        titleElement = [jQuery('<h3>', {'class': 'title', 'text': r.title})];
41 42 43
    }

    for ( var k in r.links ) {
44
        var link = jQuery('<a>', {'href': r.links[k], 'text': k});
45 46 47 48
        titleElement.push(link);
    }

    if (r.views) {
49 50
        var viewsList = jQuery('<ul>');
        var viewsElement = jQuery('<div>').append(jQuery('<label>').append($enc_pages), viewsList);
51
        for ( var k in r.views ) {
52 53
            var link = jQuery('<a>',{'href': r.views[k]}).append(k);
            viewsList.append(jQuery('<li>').append(link));
54
        }
55 56
    }

57 58
    var descriptionElement = jQuery('<p>');
    descriptionElement.html(r.summary);
59

60 61 62 63
    return jQuery('<tr>', {'class': 'r' + (rownumber % 2)}).append(
      jQuery('<td>').append(
        titleElement, descriptionElement, viewsElement
      ))[0];
64
};
65 66

function dosearch(e) {
67
    results.query = jQuery('#search_query').val();
68 69 70 71
    results.offset = 0;

    results.doupdate();
}
72 73
EOF;

74
if ($query != '') {
75 76 77
    $javascript .= 'results.query = ' . json_encode($query) . ";\n";
    $javascript .= "results.updateOnLoad();\n";
}
78 79 80
else {
    $javascript .= 'results.query = \'\';';
}
81

82
$smarty = smarty(array('tablerenderer'), array(), array(), array('sidebars' => true));
83 84 85 86
$smarty->assign('query', $query);
$smarty->assign('artefacttype', $artefacttype);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('selfsearch.tpl');