function displaySearchForm($searchRequest)
{
    registerShortcut("Ctrl+Alt+W", "addReturningObjectRow(document.getElementById('numReturningObjects').value++);" . "toggleFieldDisabled();");
    print "<script>\n";
    print "var searchable_objects = new Array();\n";
    foreach (describeGlobal("searchable") as $obj) {
        print "searchable_objects[\"{$obj}\"]=\"{$obj}\";\n";
    }
    print "</script>\n";
    print "<script src='" . getPathToStaticResource('/script/search.js') . "' type='text/javascript'></script>\n";
    print "<form method='POST' name='search_form' action='search.php'>\n";
    print getCsrfFormTag();
    print "<input type='hidden' id='numReturningObjects' name='numReturningObjects' value='" . count($searchRequest->getReturningObjects()) . "' />";
    print "<p class='instructions'>Enter a search string and optionally select the objects and fields to return to build a SOSL search below:</p>\n";
    print "<table id='search_form_table' border='0' width='1'>\n<tr>\n";
    print "<td NOWRAP>Search for </td><td NOWRAP colspan='2'><input type='text' id='SB_searchString' name='SB_searchString' value=\"" . htmlspecialchars($searchRequest->getSearchString(), ENT_QUOTES) . "\" size='37' onKeyUp='buildSearch();' /> in ";
    $fieldTypeSelectOptions = array('ALL FIELDS' => 'All Fields', 'NAME FIELDS' => 'Name Fields', 'PHONE FIELDS' => 'Phone Fields', 'EMAIL FIELDS' => 'Email Fields');
    print "<select id='SB_fieldTypeSelect' name='SB_fieldTypeSelect' onChange='buildSearch();' onkeyup='buildSearch();'>\n";
    foreach ($fieldTypeSelectOptions as $opKey => $op) {
        print "<option value='{$opKey}'";
        if ($opKey == $searchRequest->getFieldType()) {
            print " selected='selected' ";
        }
        print ">{$op}</option>";
    }
    print "</select>";
    print " limited to <input id='SB_limit' name='SB_limit' type='text'  value='" . htmlspecialchars($searchRequest->getLimit(), ENT_QUOTES) . "' size='5' onKeyUp='buildSearch();' /> maximum records</td></tr>\n";
    print "<tr id='sosl_search_textarea_row'><td valign='top' colspan='3'><br/>Enter or modify a SOSL search below:" . "<br/><textarea id='sosl_search_textarea' type='text' name='sosl_search' cols='100' rows='" . WorkbenchConfig::get()->value("textareaRows") . "' style='overflow: auto; font-family: monospace, courier;'>" . htmlspecialchars($searchRequest->getSoslSearch(), ENT_QUOTES) . "</textarea>" . "</td></tr>";
    print "<tr><td><input type='submit' name='searchSubmit' value='Search' />";
    print "<td colspan=4 align='right'>";
    print "&nbsp;&nbsp;" . "<img onmouseover=\"Tip('Where did saved searches go? They have been replaced with bookmarkable and shareable searched! Just run a search and bookmark the URL to save or copy and paste to share.')\" align='absmiddle' src='" . getPathToStaticResource('/images/help16.png') . "'/>";
    print "</td></tr></table><p/>\n";
    print "</form>\n";
    $rowNum = 0;
    foreach ($searchRequest->getReturningObjects() as $ro) {
        print "<script>addReturningObjectRow(" . $rowNum++ . ", " . "\"" . htmlspecialchars($ro->getObject(), ENT_QUOTES) . "\", " . "\"" . htmlspecialchars($ro->getFields(), ENT_QUOTES) . "\"" . ");</script>";
    }
    print "<script>toggleFieldDisabled();</script>";
}
function printObjectSelection($defaultObject = false, $nameId = 'default_object', $width = 20, $extras = null, $filter1 = null, $filter2 = null)
{
    // todo: do we really want to set this here? seems like it should be in a request handler or something...
    WorkbenchContext::get()->setDefaultObject($defaultObject);
    $describeGlobalResults = describeGlobal($filter1, $filter2);
    print "<select id='{$nameId}' name='{$nameId}' style='width: " . $width . "em;' {$extras}>\n";
    print "<option value=''></option>";
    //Print the global object types in a dropdown select box, using the filter set and the API version supports it
    foreach ($describeGlobalResults as $type) {
        print "    <option value='{$type}'";
        if ($defaultObject == $type) {
            print " selected='true'";
        }
        print ">{$type}</option> \n";
    }
    print "</select>\n";
}
Beispiel #3
0
function displaySearchForm($searchRequest)
{
    registerShortcut("Ctrl+Alt+W", "addReturningObjectRow(document.getElementById('numReturningObjects').value++);" . "toggleFieldDisabled();");
    print "<script>\n";
    print "var searchable_objects = new Array();\n";
    foreach (describeGlobal("searchable") as $obj) {
        print "searchable_objects[\"{$obj}\"]=\"{$obj}\";\n";
    }
    print <<<SEARCH_BUILDER_SCRIPT

function doesSearchHaveName() {
    var saveSr = document.getElementById('saveSr');
    if (saveSr.value == null || saveSr.value.length == 0) {
        alert('Search must have a name to save.');
        return false;
    }    
    
    return true;
}

function toggleFieldDisabled() {

    if (document.getElementById('SB_searchString').value) {
        document.getElementById('SB_limit').disabled = false;
        document.getElementById('SB_fieldTypeSelect').disabled = false;
        document.getElementById('SB_objSelect_0').disabled = false;
        if (document.getElementById('SB_objSelect_0').value) {
            document.getElementById('SB_objDetail_0').disabled = false;
        } else {
            document.getElementById('SB_objDetail_0').disabled = true;
        }
    } else {
        document.getElementById('SB_limit').disabled = true;
        document.getElementById('SB_fieldTypeSelect').disabled = true;
        document.getElementById('SB_objSelect_0').disabled = true;
        document.getElementById('SB_objDetail_0').disabled = true;
    }

    var allPreviousRowsUsed = true;
    for (var ro = 1; ro < document.getElementById('numReturningObjects').value; ro++) {
        var this_SB_objSelect = document.getElementById('SB_objSelect_' + ro);
        var this_SB_objDetail = document.getElementById('SB_objDetail_' + ro);
        
        var last_SB_objSelect = document.getElementById('SB_objSelect_' + (ro - 1));
        var last_SB_objDetail = document.getElementById('SB_objDetail_' + (ro - 1));
        
        if (allPreviousRowsUsed && last_SB_objSelect.value && last_SB_objDetail.value) {
            this_SB_objSelect.disabled = false;
            this_SB_objDetail.disabled = false;
            if (this_SB_objSelect.value) {
                this_SB_objDetail.disabled = false;
            } else {
                this_SB_objDetail.disabled = true;
            }
        } else {
            this_SB_objSelect.disabled = true;
            this_SB_objDetail.disabled = true;
            allPreviousRowsUsed = false;
        }
    }
}

function buildSearch() {
    toggleFieldDisabled();
    
    var searchString = 'FIND {' + document.getElementById('SB_searchString').value + '}';
    
    var fieldTypeSelect = '';
    if (document.getElementById('SB_fieldTypeSelect').value && !document.getElementById('SB_fieldTypeSelect').disabled) {
        fieldTypeSelect = ' IN ' + document.getElementById('SB_fieldTypeSelect').value;
    }
    
    var roString = '';
    for (var ro = 0; ro < document.getElementById('numReturningObjects').value; ro++) {
        var SB_objSelect = document.getElementById('SB_objSelect_' + ro);
        var SB_objDetail = document.getElementById('SB_objDetail_' + ro);
        
        if (SB_objSelect.value && !SB_objSelect.disabled) {
            roString += ro == 0 ? ' RETURNING ' : ', ';
            
            roString += SB_objSelect.value;

            if (SB_objDetail.value && !SB_objDetail.disabled) {
                roString += '(' + SB_objDetail.value + ')';
            }
        }
    }
    
    var limit = '';
    if (document.getElementById('SB_limit').value && !document.getElementById('SB_limit').disabled) {
        limit = ' LIMIT ' + document.getElementById('SB_limit').value;
    }


    if (searchString) {
        document.getElementById('sosl_search_textarea').value = searchString + fieldTypeSelect + roString + limit;
    }
}

function addReturningObjectRow(rowNum, defaultObject, defaultFields) {
    //build the row inner html
    var row = "";
    
    row +=     "<select id='SB_objSelect_" + rowNum + "' name='SB_objSelect_" + rowNum + "' style='width: 20em;' onChange='buildSearch();' onkeyup='buildSearch();'>" +
            "<option value=''></option>";
    
    for (var obj in searchable_objects) {
        row += "<option value='" + obj + "'";
        if (defaultObject == obj) row += " selected='selected' ";
        row += "'>" + obj + "</option>";
    }     
    
    defaultFields = defaultFields != null ? defaultFields : "";
    row +=  "</select>&nbsp;" +
            "<input type='text' id='SB_objDetail_" + rowNum + "' size='51' name='SB_objDetail_" + rowNum + "' value='" + defaultFields + "' onkeyup='buildSearch();' />";
            

    //add to the DOM
    var leadingTxtCell = document.createElement('td');
    leadingTxtCell.setAttribute('nowrap','true');
    leadingTxtCell.innerHTML = rowNum == 0 ? "returning object:" : "and object:" ;
    
    var bodyCell = document.createElement('td');
    bodyCell.setAttribute('nowrap','true');
    bodyCell.innerHTML = row;

    var newPlusCell = document.createElement('td');
    newPlusCell.setAttribute('id','add_row_plus_cell_' + rowNum);
    newPlusCell.setAttribute('vAlign','bottom');
    newPlusCell.innerHTML = "<img id='row_plus_button' src='" + getPathToStaticResource('/images/plus_icon.jpg') + "' onclick='addReturningObjectRow(document.getElementById(\\"numReturningObjects\\").value++);toggleFieldDisabled();' onmouseover='this.style.cursor=\\"pointer\\";'  style='padding-top: 4px;'/>";
    
    var newRow = document.createElement('tr');
    newRow.setAttribute('id','returning_objects_row_' + rowNum);
    newRow.appendChild(leadingTxtCell);
    newRow.appendChild(bodyCell);
    newRow.appendChild(newPlusCell);
    
    var lastRow = document.getElementById('sosl_search_textarea_row');    
    lastRow.parentNode.insertBefore(newRow, lastRow);
    
    if (rowNum > 0) {
        var row_plus_button = document.getElementById('row_plus_button');
        row_plus_button.parentNode.removeChild(row_plus_button);
    }
}

</script>
SEARCH_BUILDER_SCRIPT;
    if (WorkbenchConfig::get()->value("autoJumpToResults")) {
        print "<form method='POST' name='search_form' action='#sr'>\n";
    } else {
        print "<form method='POST' name='search_form' action='#sr'>\n";
    }
    print "<input type='hidden' id='numReturningObjects' name='numReturningObjects' value='" . count($searchRequest->getReturningObjects()) . "' />";
    print "<p class='instructions'>Enter a search string and optionally select the objects and fields to return to build a SOSL search below:</p>\n";
    print "<table id='search_form_table' border='0' width='1'>\n<tr>\n";
    print "<td NOWRAP>Search for </td><td NOWRAP colspan='2'><input type='text' id='SB_searchString' name='SB_searchString' value=\"" . htmlspecialchars($searchRequest->getSearchString(), ENT_QUOTES) . "\" size='37' onKeyUp='buildSearch();' /> in ";
    $fieldTypeSelectOptions = array('ALL FIELDS' => 'All Fields', 'NAME FIELDS' => 'Name Fields', 'PHONE FIELDS' => 'Phone Fields', 'EMAIL FIELDS' => 'Email Fields');
    print "<select id='SB_fieldTypeSelect' name='SB_fieldTypeSelect' onChange='buildSearch();' onkeyup='buildSearch();'>\n";
    foreach ($fieldTypeSelectOptions as $opKey => $op) {
        print "<option value='{$opKey}'";
        if ($opKey == $searchRequest->getFieldType()) {
            print " selected='selected' ";
        }
        print ">{$op}</option>";
    }
    print "</select>";
    print " limited to <input id='SB_limit' name='SB_limit' type='text'  value='" . htmlspecialchars($searchRequest->getLimit(), ENT_QUOTES) . "' size='5' onKeyUp='buildSearch();' /> maximum records</td></tr>\n";
    print "<tr id='sosl_search_textarea_row'><td valign='top' colspan='3'><br/>Enter or modify a SOSL search below:" . "<br/><textarea id='sosl_search_textarea' type='text' name='sosl_search' cols='100' rows='" . WorkbenchConfig::get()->value("textareaRows") . "' style='overflow: auto; font-family: monospace, courier;'>" . htmlspecialchars($searchRequest->getSoslSearch(), ENT_QUOTES) . "</textarea>" . "</td></tr>";
    print "<tr><td><input type='submit' name='searchSubmit' value='Search' />";
    //print "<input type='reset' value='Reset' />";
    //save and retrieve named searches
    print "<td align='right' colspan='2'>";
    print "&nbsp;Run: " . "<select name='getSr' style='width: 10em;' onChange='document.search_form.submit();'>" . "<option value='' selected='selected'></option>";
    if (isset($_SESSION['savedSearchRequests'])) {
        foreach ($_SESSION['savedSearchRequests'] as $srName => $sr) {
            if ($srName != null) {
                print "<option value='{$srName}'>{$srName}</option>";
            }
        }
    }
    print "</select>";
    print "&nbsp;&nbsp;Save as: <input type='text' id='saveSr' name='saveSr' value='" . htmlspecialchars($searchRequest->getName(), ENT_QUOTES) . "' style='width: 10em;'/>\n";
    print "<input type='submit' name='doSaveSr' value='Save' onclick='return doesSearchHaveName();' />\n";
    print "<input type='submit' name='clearAllSr' value='Clear All'/>\n";
    print "&nbsp;&nbsp;" . "<img onmouseover=\"Tip('Save a search with a name and run it at a later time during your session. Note, if a search is already saved with the same name, the previous one will be overwritten.')\" align='absmiddle' src='" . getPathToStaticResource('/images/help16.png') . "'/>";
    print "</td></tr></table><p/></form>\n";
    $rowNum = 0;
    foreach ($searchRequest->getReturningObjects() as $ro) {
        print "<script>addReturningObjectRow(" . $rowNum++ . ", " . "\"" . $ro->getObject() . "\", " . "\"" . $ro->getFields() . "\"" . ");</script>";
    }
    print "<script>toggleFieldDisabled();</script>";
}