Collections functions
General functions
Render functions
Theme permission functions
Resource functions

display_field()

Parameters

ColumnTypeDefaultDescription
$n
$field
$newtab false
$modal false

Location

include/render_functions.php lines 1761 to 2217

Definition

 
function display_field($n$field$newtab=false,$modal=false)
  {
  global 
$use$ref$original_fields$multilingual_text_fields$multiple$lastrt,$is_template$language$lang,
  
$blank_edit_template$edit_autosave$errors$tabs_on_edit$collapsible_sections$ctrls_to_save,
  
$embedded_data_user_select$embedded_data_user_select_fields$show_error$save_errors$baseurl$is_search,
  
$all_selected_nodes,$original_nodes$FIXED_LIST_FIELD_TYPES$TEXT_FIELD_TYPES$upload_review_mode$check_edit_checksums,
  
$upload_review_lock_metadata$locked_fields$lastedited$copyfrom$fields;

  
// debug_function_call() not used here because $field with numerous node options is unsuitable for debug log
  
debug("display_field()" "n = " $n ", field ref=" $field["ref"] . ", modal=" . ($modal "TRUE" "FALSE"));

  
// Set $is_search to false in case page request is not an ajax load and $is_search hs been set from the searchbar
  
$is_search=false;
  
  if(!isset(
$locked_fields))
    {
    
$locked_fields explode(",",getval("lockedfields",""));
    }

    if(!isset(
$copyfrom))
        {
        
$copyfrom getval('copyfrom''');
        }

  
$name="field_" $field["ref"];
  
$value=$field["value"];
  
$value=trim((string) $value);
  
$use_copyfrom=true;
    if (
$use != $ref && ($field["omit_when_copying"]))
        {
        
debug("display_field: reverting copied value for field " $field["ref"] . " as omit_when_copying is enabled");
        
# Return this field value back to the original value, instead of using the value from the copied resource/metadata template
        # This is triggered if field has the 'omit_when_copying' flag set
        
reset($original_fields);
        
$use_copyfrom=false;
        foreach (
$original_fields as $original_field)
            {
            if (
$original_field["ref"]==$field["ref"])
                {
                
$value=$original_field["value"];
                }
            }
        
$selected_nodes $original_nodes;
        }
    elseif((
$ref<|| $upload_review_mode) && isset($locked_fields) && in_array($field["ref"], $locked_fields) && $lastedited 0)
        {
        
// Get value from last edited resource 
        
debug("display_field: locked field " $field['ref'] . ". Using nodes from last resource edited - " $lastedited);
        
$selected_nodes get_resource_nodes($lastedited,$field["ref"]);
        }
    else
        {
        
$selected_nodes $all_selected_nodes;
        
$submitted_val getval("field_" $field['ref'],"");
        if(!empty(
$save_errors) && $submitted_val != "")
            {
            
// Set to the value that was submitted 
            
$value $submitted_val;
            }
        }
    
  
$displaycondition=true;
  if (
$field["display_condition"]!="")
    {
    
#Check if field has a display condition set and render the client side check display condition functions
    
$displaycondition check_display_condition($n$field$fieldstrue);
    }

  if (
$multilingual_text_fields)
    {
    
# Multilingual text fields - find all translations and display the translation for the current language.
    
$translations=i18n_get_translations($value);
    if (
array_key_exists($language,$translations)) {$value=$translations[$language];} else {$value="";}
    }

  if (
$multiple && ((getval("copyfrom","") == "" && getval('metadatatemplate''') == "") || str_replace(array(" ",","),"",$value)=="")) {$value="";} # Blank the value for multi-edits  unless copying data from resource.

  
if ($field["resource_type"]!=$lastrt && $lastrt!=-&& $collapsible_sections)
      {
      
?></div><h2 class="CollapsibleSectionHead" id="resource_type_properties"> echo htmlspecialchars(get_resource_type_name($field["resource_type"]))?>  echo $lang["properties"]?></h2><div class="CollapsibleSection" id="ResourceProperties if ($ref==-1) echo "Upload"?> echo $field["resource_type"]; ?>Section">
      
}
    
$lastrt=$field["resource_type"];

    
# Blank form if 'reset form' has been clicked
    
if('' != getval('resetform'''))
        {
        
$value '';

        if(
in_array($field['type'], $FIXED_LIST_FIELD_TYPES))
            {
            
$selected_nodes = array();
            }
        
$user_set_values = array();
        }
    
// Copy from resource should only show values from the resource we are copying from
    
else if($ref != $use && $copyfrom != '')
        {
        
$user_set_values = array();
        }
    else
        {
        
debug("display_field: getting all user selected values from form data for field " $field['ref']);
        
$user_set_values getval('nodes', array());
        }

    
/****************************** Errors on saving ***************************************/
    
$field_save_error FALSE;
    if (isset(
$show_error) && isset($save_errors))
      {
      if(
array_key_exists($field['ref'], $save_errors))
        {
        
$field_save_error TRUE;
        }
      }
     
    if (
$multiple && !hook("replace_edit_all_checkbox","",array($field["ref"])))
      {
      
# Multiple items, a toggle checkbox appears which activates the question
      
?>
      <div class="Question edit_multi_checkbox">
        <input name="editthis_ echo htmlspecialchars($name?>"
               id="editthis_ echo $n?>"
               type="checkbox"
               value="yes"
                if($field_save_error){?> checked ?>
               onClick="batch_edit_toggle_edit_multi_checkbox_question( echo (int) $n?>);"  if(getval("copyfrom","")!="" && $use_copyfrom && $value!=""){echo " checked" ;} ?>>&nbsp;
            <label for="editthis echo $n?>"> echo htmlspecialchars($field["title"]) ?></label>
            <div class="clearerleft"></div>
        </div>
        <!-- End of edit_multi_checkbox -->
      
      
}

  if (
$multiple && !hook("replace_edit_all_mode_select","",array($field["ref"])))
      {
      
# When editing multiple, give option to select Replace All Text or Find and Replace
      
$onchangejs "var fr=document.getElementById('findreplace_" $n "');\n";
      
$onchangejs .= "var q=document.getElementById('question_" $n "');\n";
      if (
$field["type"] == FIELD_TYPE_CATEGORY_TREE)
        {
        
$onchangejs .= "if (this.value=='RM'){branch_limit_field['field_" $field["ref"] . "']=1;}else{branch_limit_field['field_" $field["ref"] . "']=0;}";
        }
      elseif (
in_array($field["type"], $TEXT_FIELD_TYPES ))
        {
        
$onchangejs .= "
        var cf=document.getElementById('copy_from_field_" 
$field["ref"] . "');
            if (this.value=='CF')
                {
                cf.style.display='block';q.style.display='none';fr.style.display='none';
                }
            else if (this.value=='FR')
                {
                fr.style.display='block';q.style.display='none';cf.style.display='none';
                }
            else
                {
                fr.style.display='none';cf.style.display='none';q.style.display='block';
                }"
;
        }
      
?>
      <div class="Question" id="modeselect_ echo $n?>" style=" if($value=="" && !$field_save_error ){echo "display:none;";} ?>padding-bottom:0;margin-bottom:0;">
      <label for="modeselectinput"> echo $lang["editmode"]?></label>
      <select id="modeselectinput_ echo $n?>" name="modeselect_ echo $field["ref"]?>" class="stdwidth" onChange=" echo $onchangejs;hook ("edit_all_mode_js"); ?>">
      <option value="RT"> echo $lang["replacealltext"]?></option>
      
      
if (in_array($field["type"], $TEXT_FIELD_TYPES ))
        {
        
# 'Find and replace', prepend and 'copy from field' options apply to text boxes only.
        
?>
        <option value="FR" if(getval("modeselect_" $field["ref"],"")=="FR"){?> selected ?>> echo $lang["findandreplace"]?></option>
        <option value="CF" if(getval("modeselect_" $field["ref"],"")=="CF"){?> selected ?>> echo $lang["edit_copy_from_field"]?></option>
        
        
if(!$multilingual_text_fields)
            {
            
// Prepending text doesn't work wih multilingual fields
            
?>
            <option value="PP" if(getval("modeselect_" $field["ref"],"")=="PP"){?> selected ?>> echo $lang["prependtext"]?></option>
            
            
}
        }
      if((
in_array($field['type'], $TEXT_FIELD_TYPES) && !$multilingual_text_fields) || in_array($field['type'], [FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_CATEGORY_TREEFIELD_TYPE_DYNAMIC_KEYWORDS_LIST]))
        {
        
# Append applies to text boxes, checkboxes ,category tree and dynamic keyword fields onl.
        
?>
        <option value="AP" if(getval("modeselect_" $field["ref"],"")=="AP"){?> selected ?>> echo $lang["appendtext"]?></option>
        
        
}
      if(
in_array($field['type'], array_merge($TEXT_FIELD_TYPES, array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_DROP_DOWN_LISTFIELD_TYPE_CATEGORY_TREEFIELD_TYPE_DYNAMIC_KEYWORDS_LIST))))
        {
        
# Remove applies to text boxes, checkboxes, dropdowns, category trees and dynamic keywords only. 
        
if ($field['required'] == 0
            {
            
# And it only applies if the field is optional
            
?> 
        <option value="RM" if(getval("modeselect_" $field["ref"],"")=="RM"){?> selected ?>> echo $lang["removetext"]?></option>
        
            
}
        }
        
hook ("edit_all_extra_modes","",[$field]);
        
?>
        </select>
      </div><!-- End of modeselect_ echo $n?> -->

      
      
if (in_array($field["type"], $TEXT_FIELD_TYPES))
        {
        
render_field_selector_question("","copy_from_field_" $field["ref"], array(), "stdwidth"true);
        }
        
?>

      <div class="Question" id="findreplace_ echo $n?>" style="display:none;border-top:none;">
        <label>&nbsp;</label>
         echo $lang["find"]?> <input type="text" name="find_ echo $field["ref"]?>" class="shrtwidth">
         echo $lang["andreplacewith"]?> <input type="text" name="replace_ echo $field["ref"]?>" class="shrtwidth">
      </div><!-- End of findreplace_ echo $n?> -->

       hook ("edit_all_after_findreplace","",array($field,$n)); 
      }
      
?>

      <div class="Question  if($upload_review_mode && in_array($field["ref"],$locked_fields)){echo " lockedQuestion ";} if($field_save_error) { echo 'FieldSaveError'; } ?>" id="question_ echo $n?>
      
if (($multiple && !$field_save_error) || !$displaycondition || $newtab)
        {
?>style="border-top:none; 
        
if (($multiple && $value=="") || !$displaycondition# Hide this
        
{
        
?>
        display:none;
        
        
}
        
?>"
        
}
     
?>>
      
     $labelname 
$name;

     
// For batch editing, CKEditor renders as a text box, as it does not work at all well when appending / prepending (it expects to work with HTML only)
     
if ($field['type'] == && $multiple)
        {
        
$field['type']=1;
        }
      
     
// Add _selector to label so it will keep working:
     
if($field['type'] == 9)
      {
      
$labelname .= '_selector';
      }

      
// Add -d to label so it will keep working
     
if($field['type'] == 4)
        {
        
$labelname .= '-d';
        }
        
?>
     <label for=" echo htmlspecialchars($labelname)?> if($field['type']==FIELD_TYPE_DATE_RANGE) {echo " class='daterangelabel'";} ?> >
      
     
if (!$multiple
        {
        echo 
htmlspecialchars($field["title"]);
        if (!
$is_template && $field["required"]==1)
            {
            echo 
"<sup>*</sup>";
            }
        } 
     if (
$upload_review_mode && $upload_review_lock_metadata)
        {
        
renderLockButton($field["ref"], $locked_fields);
        }
        
?>
     </label>

     
    
# Autosave display
     
if ($edit_autosave || $ctrls_to_save)
      {
      
?>
      <div class="AutoSaveStatus">
      <span id="AutoSaveStatus echo $field["ref"?>" style="display:none;"></span>
      </div>
      
      

    
# Define some Javascript for help actions (applies to all fields)
    # Help actions for CKEditor fields are set in pages/edit_fields/8.php
     
if (trim($field["help_text"]=="")) 
       {
        
# No helptext; so no javascript for toggling
        
$help_js="";
       }
     else
       {
       if ( 
in_array($field["type"],array(2,3,4,6,7,10,12,14)) )
         {
         
# For the selected field types the helptext is always shown; so no javascript toggling 
         
$help_js="";
         }
       else
         {
         
# For all other field types setup javascript to toggle helptext depending on loss or gain of focus
         
$help_js="onBlur=\"HideHelp(" $field["ref"] . ");return false;\" onFocus=\"ShowHelp(" $field["ref"] . ");return false;\"";
         }
       }

    
#hook to modify field type in special case. Returning zero (to get a standard text box) doesn't work, so return 1 for type 0, 2 for type 1, etc.
     
$modified_field_type="";
     
$modified_field_type=(hook("modifyfieldtype"));
     if (
$modified_field_type){$field["type"]=$modified_field_type-1;}

     
hook("addfieldextras");
    
# ----------------------------  Show field -----------------------------------
    
$type $field['type'];

    
// Default to text type.
    
if('' == $type)
        {
        
$type 0;
        }

    
// The visibility status (block/none) will be sent to the server for validation purposes
    
echo "<input id='field_" . (int) $field['ref']  . "_displayed' name='" "field_" . (int) $field['ref']  . "_displayed' type='hidden' value='block'>";

    if(!
hook('replacefield''', array($field['type'], $field['ref'], $n)))
        {
        global 
$auto_order_checkbox$auto_order_checkbox_case_insensitive$FIXED_LIST_FIELD_TYPES$is_search;
        
$selected_nodes get_resource_nodes($use$field['ref']);
        if(
in_array($field['type'], $FIXED_LIST_FIELD_TYPES))
            {
            
$name "nodes[{$field['ref']}]";

            
// Sometimes we need to pass multiple options
            
if(in_array($field['type'], array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_CATEGORY_TREE)))
                {
                
$name "nodes[{$field['ref']}][]";
                }
            else if(
FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $field['type'])
                {
                
$name "field_{$field['ref']}";
                }

            
$field_nodes array_column($selected_nodes,"ref");
            foreach(
$selected_nodes as $selected_node)
                {
                
$node_data = array();
                if(
get_node($selected_node$node_data) && $node_data["resource_type_field"] != $field["ref"])
                    {
                    continue;
                    }

                
$field_nodes[] = $selected_node;
                unset(
$node_data);
                }
            
sort($field_nodes);
            if(!
$multiple && !$blank_edit_template && getval("copyfrom","") == "" && getval('metadatatemplate''') == "" && $check_edit_checksums)
                {
                echo 
"<input id='field_" . (int) $field['ref']  . "_checksum' name='" "field_" . (int) $field['ref']  . "_checksum' type='hidden' value='" md5(implode(",",$field_nodes)) . "'>";
                echo 
"<input id='field_" . (int) $field['ref']  . "_currentval' name='" "field_" . (int) $field['ref']  . "_currentval' type='hidden' value='" implode(",",$field_nodes) . "'>";
                }
            }
        elseif(
$field['type']==FIELD_TYPE_DATE_RANGE && !$blank_edit_template && getval("copyfrom","") == "" && getval('metadatatemplate''') == "" && $check_edit_checksums)
            {
            
$field['nodes'] = get_nodes($field['ref'], NULLFALSE);
            
$field_nodes = array();
            foreach(
$selected_nodes as $selected_node)
                {
                if(
in_array($selected_node,array_column($field['nodes'],"ref")))
                    {
                    
$field_nodes[] = $selected_node;
                    }
                }
            
sort($field_nodes);            
            echo 
"<input id='field_" . (int) $field['ref']  . "_checksum' name='" "field_" . (int) $field['ref']  . "_checksum' type='hidden' value='" md5(implode(",",$field_nodes)) . "'>";
            }
        elseif(!
$multiple && !$blank_edit_template && getval("copyfrom","")=="" && getval('metadatatemplate''') == "" && $check_edit_checksums)
            {
            echo 
"<input id='field_" . (int) $field['ref']  . "_checksum' name='" "field_" . (int) $field['ref']  . "_checksum' type='hidden' value='" md5(trim(preg_replace('/\s\s+/'' ', (string) $field['value']))) . "'>";
            }

        
$is_search false;

        include 
"edit_fields/{$type}.php";
        }
        
    
# ----------------------------------------------------------------------------

    # Display any error messages from previous save
    
if (array_key_exists($field["ref"],$errors))
      {
       
?>
       <div class="FormError">!!  echo $errors[$field["ref"]]?> !!</div>
       
      
}

    if (
trim($field["help_text"]!=""))
     {
        
# Show inline help for this field.
        # For certain field types that have no obvious focus, the help always appears
       
?>
       <div class="FormHelp" style="padding:0; if ( in_array($field["type"],array(2,3,4,6,7,10,12,14)) ) { ?> clear:left; } else { ?> display:none; ?>" id="help_ echo $field["ref"]?>"><div class="FormHelpInner"> echo nl2br(trim(i18n_get_translated($field["help_text"])))?></div></div>
       
     
}

    
# If enabled, include code to produce extra fields to allow multilingual free text to be entered.
    
if ($multilingual_text_fields && ($field["type"]==|| $field["type"]==|| $field["type"]==5))
      {
       
display_multilingual_text_field($n$field$translations);
      }
    
    if((
$embedded_data_user_select || (isset($embedded_data_user_select_fields) && in_array($field["ref"],$embedded_data_user_select_fields))) && ($ref<&& !$multiple))
    {
      
?>
      <table id="exif_ echo $field["ref"?>" class="ExifOptions" cellpadding="3" cellspacing="3"  if ($embedded_data_user_select){?> style="display: none;"  ?>>                    
         <tbody>
           <tr>        
             <td>
                 echo "&nbsp;&nbsp;" $lang["embeddedvalue"] . ": " ?>
             </td>
             <td width="10" valign="middle">
               <input type="radio" id="exif_extract_ echo $field["ref"?>" name="exif_option_ echo $field["ref"?>" value="yes" checked>
            </td>
            <td align="left" valign="middle">
               <label class="customFieldLabel" for="exif_extract_ echo $field["ref"?>"> echo $lang["embedded_metadata_extract_option"?></label>
            </td>


            <td width="10" valign="middle">
               <input type="radio" id="no_exif_ echo $field["ref"?>" name="exif_option_ echo $field["ref"?>" value="no">
            </td>
            <td align="left" valign="middle">
               <label class="customFieldLabel" for="no_exif_ echo $field["ref"?>"> echo $lang["embedded_metadata_donot_extract_option"?></label>
            </td>


            <td width="10" valign="middle">
               <input type="radio" id="exif_append_ echo $field["ref"?>" name="exif_option_ echo $field["ref"?>" value="append">
            </td>
            <td align="left" valign="middle">
               <label class="customFieldLabel" for="exif_append_ echo $field["ref"?>"> echo $lang["embedded_metadata_append_option"?></label>
            </td>


            <td width="10" valign="middle">
               <input type="radio" id="exif_prepend_ echo $field["ref"?>" name="exif_option_ echo $field["ref"?>" value="prepend">
            </td>
            <td align="left" valign="middle">
               <label class="customFieldLabel" for="exif_prepend_ echo $field["ref"?>"> echo $lang["embedded_metadata_prepend_option"?></label>
            </td>

         </tr>
      </tbody>
   </table>        
   
  
}
  
?>
  <div class="clearerleft"> </div>
  </div><!-- end of question_ echo $n?> div -->
       
  
  hook
('afterfielddisplay''', array($n$field));
  }

This article was last updated 3rd February 2023 16:05 Europe/London time based on the source file dated 2nd February 2023 15:55 Europe/London time.