Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

display_field()

Parameters

ColumnTypeDefaultDescription
$n
$field
$newtab false
$modal false

Location

include/render_functions.php lines 1517 to 1955

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("display_field"func_get_args());

  
// 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($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;
        }
    
  
$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>
        <option value="PP" if(getval("modeselect_" $field["ref"],"")=="PP"){?> selected ?>> echo $lang["prependtext"]?></option>
        
        
}
      if(
in_array($field['type'], array_merge($TEXT_FIELD_TYPES, array(FIELD_TYPE_CHECK_BOX_LISTFIELD_TYPE_CATEGORY_TREEFIELD_TYPE_DYNAMIC_KEYWORDS_LIST))))
        {
        
# Append applies to text boxes, checkboxes ,category tree and dynamic keyword fields only.
        
?>
        <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. 
        
?> 
        <option value="RM" if(getval("modeselect_" $field["ref"],"")=="RM"){?> selected ?>> echo $lang["removetext"]?></option>
        
        
}
        
hook ("edit_all_extra_modes");
        
?>
        </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 (!$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)) )
         {