Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

render_search_field()

Description

Renders the HTML for the provided $field for inclusion in a search form, for example the
advanced search page. Standard field titles are translated using $lang. Custom field titles are i18n translated.

$field an associative array of field data, i.e. a row from the resource_type_field table.
$name the input name to use in the form (post name)
$value the default value to set for this field, if any
$reset is non-blank if the caller requires the field to be reset

Parameters

ColumnTypeDefaultDescription
$field
$value ""
$autoupdate false
$class "stdwidth"
$forsearchbar false
$limit_keywords array
$searched_nodes array array Array of all the searched nodes previously
$reset ""

Location

include/render_functions.php lines 19 to 708

Definition

 
function render_search_field($field,$value="",$autoupdate=false,$class="stdwidth",$forsearchbar=false,$limit_keywords=array(), $searched_nodes = array(), $reset="")
    {
    
node_field_options_override($field);
    
    global 
$auto_order_checkbox$auto_order_checkbox_case_insensitive$lang$category_tree_open$minyear$daterange_search$searchbyday$is_search$values$n$simple_search_show_dynamic_as_dropdown$clear_function$simple_search_display_condition$autocomplete_search$baseurl$fields$baseurl_short$extrafooterhtml,$FIXED_LIST_FIELD_TYPES$maxyear_extends_current;
    
    
// set this to zero since this does not apply to collections
    
if (!isset($field['field_constraint'])){$field['field_constraint']=0;}
      
    
$name="field_" . ($forsearchbar htmlspecialchars($field["name"]) : $field["ref"]);
    
$id="field_" $field["ref"];

    
$scriptconditions=array();
        
    
#Check if field has a display condition set
    
$displaycondition=true;
    if (
$field["display_condition"]!="" && (!$forsearchbar || ($forsearchbar && !empty($simple_search_display_condition) && in_array($field['ref'],$simple_search_display_condition))))
        {
        
$s=explode(";",$field["display_condition"]);
        
$condref=0;
        foreach (
$s as $condition# Check each condition
            
{
            
$displayconditioncheck=false;
            
$s=explode("=",$condition);
            global 
$fields;
            for (
$cf=0;$cf<count($fields);$cf++) # Check each field to see if needs to be checked
                
{
                if (
$s[0]==$fields[$cf]["name"] && ($fields[$cf]["resource_type"]==|| $fields[$cf]["resource_type"]==$field["resource_type"])) # this field needs to be checked
                    
{
                    
$display_condition_js_prepend=($forsearchbar "#simplesearch_".$fields[$cf]["ref"]." " "");
                    
                    
$scriptconditions[$condref]["field"]               = $fields[$cf]["ref"];  # add new jQuery code to check value
                    
$scriptconditions[$condref]['type']                = $fields[$cf]['type'];
                    
$scriptconditions[$condref]['display_as_dropdown'] = $fields[$cf]['display_as_dropdown'];
                    
$scriptconditionnodes get_nodes($fields[$cf]['ref'], null, (FIELD_TYPE_CATEGORY_TREE == $fields[$cf]['type'] ? true false));
                    
                    
$checkvalues=$s[1];
                    
$validvalues=explode("|",strtoupper($checkvalues));
                    
$scriptconditions[$condref]['valid'] = array();
                    foreach(
$validvalues as $validvalue)
                        {
                        
$found_validvalue get_node_by_name($scriptconditionnodes$validvalue);

                        if(
!= count($found_validvalue))
                            {
                            
$scriptconditions[$condref]['valid'][] = $found_validvalue['ref'];

                            if(
in_array($found_validvalue['ref'],$searched_nodes))
                                {
                                
// Found a valid value
                                
$displayconditioncheck true;
                                }
                            }
                        }
                

                    if (!
$displayconditioncheck)
                        {
                        
$displaycondition=false;
                        }

                    
                    
// Certain fixed list types allow for multiple nodes to be passed at the same time
                    
if(in_array($fields[$cf]['type'], $FIXED_LIST_FIELD_TYPES))
                        {
                        if(
FIELD_TYPE_CATEGORY_TREE == $fields[$cf]['type'])
                            {
                            
?>
                            <script>
                            jQuery(document).ready(function()
                                {
                                jQuery('#CentralSpace').on('categoryTreeChanged', function(e,node)
                                    {
                                    checkSearchDisplayCondition echo $field['ref']; ?>(node);
                                    });
                                });
                            </script>
                            

                            
// Move on to the next field now
                            
continue;
                            }
                        else if(
FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $fields[$cf]['type'])
                            {
                            
?>
                            <script>
                            jQuery(document).ready(function()
                                {
                                jQuery('#CentralSpace').on('dynamicKeywordChanged', function(e,node)
                                    {
                                    checkSearchDisplayCondition echo $field['ref']; ?>(node);
                                    });
                                });
                            </script>
                            

                            
// Move on to the next field now
                            
continue;
                            }
                        else
                            {
                            
$checkname "nodes_searched[{$fields[$cf]['ref']}][]";
                            
$jquery_selector "input[name=\"{$checkname}\"]";
                            if  (
                                
FIELD_TYPE_DROP_DOWN_LIST == $fields[$cf]['type']
                                ||
                                (
in_array($fields[$cf]['type'], array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_RADIO_BUTTONS)) && true == $fields[$cf]['display_as_dropdown'])
                                )
                                {
                                
$checkname       "nodes_searched[{$fields[$cf]['ref']}]";
                                
$jquery_selector "select[name=\"{$checkname}\"]";
                                }
                            
?>
                            <script type="text/javascript">
                            jQuery(document).ready(function()
                                {
                                jQuery(' echo $jquery_selector?>').change(function ()
                                    {
                                    checkSearchDisplayCondition echo $field['ref']; ?>(jQuery(this).val());
                                    });
                                });
                            </script>
                            
                            
}
                        }
                    else
                        {
                        
?>
                        <script type="text/javascript">
                        jQuery(document).ready(function()
                            {
                            jQuery('#field_ echo $fields[$cf]["ref"]; ?>').change(function ()
                                {
                                checkSearchDisplayCondition echo $field['ref']; ?>();
                                });
                            });
                        </script>
                        
                        
}
                    }
                } 
# see if next field needs to be checked

            
$condref++;
            } 
# check next condition

        
?>
        <script type="text/javascript">
        
        function checkSearchDisplayCondition echo $field["ref"];?>(node)
            {
            var idname echo $field['ref']; ?>     = " echo $forsearchbar?"#simplesearch_".$field['ref']:"#question_".$n?>";
            field echo $field['ref']; ?>status    = jQuery(idname echo $field['ref']; ?>).css('display');
            newfield echo $field['ref']; ?>status = 'none';
            newfield echo $field['ref']; ?>show   = false;
            newfield echo $field['ref']; ?>provisional = true;
            
            
foreach($scriptconditions as $scriptcondition)
                {
                
/*
                Example of $scriptcondition:
                Array
                    (
                    [field] => 73
                    [type] => 2
                    [valid] => Array
                        (
                            [0] => 267
                            [1] => 266
                        )
                    )
                */
                
?>
                newfield echo $field['ref']; ?>subcheck = false;
                fieldokvalues echo $scriptcondition['field']; ?> =  echo json_encode($scriptcondition['valid']); ?>;
                
                
############################
                ### Field type specific
                ############################
                
if(in_array($scriptcondition['type'], $FIXED_LIST_FIELD_TYPES))
                    {
                    
$jquery_condition_selector "input[name=\"nodes_searched[{$scriptcondition['field']}][]\"]";
                    
$js_conditional_statement  "fieldokvalues{$scriptcondition['field']}.indexOf(element.value) != -1";

                    if  (
                        
in_array($scriptcondition['type'], array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_RADIO_BUTTONS))
                        &&
                        
false == $scriptcondition['display_as_dropdown']
                        )
                        {
                        
$js_conditional_statement "jQuery(this).prop('checked') && {$js_conditional_statement}";
                        }

                    if((
in_array($scriptcondition['type'], array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_RADIO_BUTTONS)) && true == $scriptcondition['display_as_dropdown'])
                        || 
FIELD_TYPE_DROP_DOWN_LIST == $scriptcondition['type'] )
                        {
                        
$jquery_condition_selector "select[name=\"nodes_searched[{$scriptcondition['field']}]\"] option:selected";
                        }
                        
?>
                    if(!newfield echo $field['ref']; ?>show)
                        {
                        jQuery(' echo $jquery_condition_selector?>').each(function(index, element)
                            {
                             if( echo $js_conditional_statement?>)
                                {
                                newfield echo $field['ref']; ?>subcheck = true;
                                }
                            });
                        }
                    
                    
}?>
                if(!newfield echo $field['ref']; ?>subcheck)
                    {
                    newfield echo $field['ref']; ?>provisional = false;
                    }