Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

render_date_range_field()

Description

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_<?php echo htmlspecialchars($name) ?>"
id="editthis_<?php echo $n?>"
type="checkbox"
value="yes"
<?php if($field_save_error){?> checked<?php } ?>
onClick="batch_edit_toggle_edit_multi_checkbox_question(<?php echo (int) $n; ?>);" <?php if(getval("copyfrom","")!="" && $use_copyfrom && $value!=""){echo " checked" ;} ?>>&nbsp;
<label for="editthis<?php echo $n?>"><?php echo htmlspecialchars($field["title"]) ?></label>
<div class="clearerleft"></div>
</div>
<!-- End of edit_multi_checkbox -->
<?php
}

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_<?php echo $n?>" style="<?php if($value=="" && !$field_save_error ){echo "display:none;";} ?>padding-bottom:0;margin-bottom:0;">
<label for="modeselectinput"><?php echo $lang["editmode"]?></label>
<select id="modeselectinput_<?php echo $n?>" name="modeselect_<?php echo $field["ref"]?>" class="stdwidth" onChange="<?php echo $onchangejs;hook ("edit_all_mode_js"); ?>">
<option value="RT"><?php echo $lang["replacealltext"]?></option>
<?php
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"<?php if(getval("modeselect_" . $field["ref"],"")=="FR"){?> selected<?php } ?>><?php echo $lang["findandreplace"]?></option>
<option value="CF"<?php if(getval("modeselect_" . $field["ref"],"")=="CF"){?> selected<?php } ?>><?php echo $lang["edit_copy_from_field"]?></option>
<option value="PP"<?php if(getval("modeselect_" . $field["ref"],"")=="PP"){?> selected<?php } ?>><?php echo $lang["prependtext"]?></option>
<?php
}
if(in_array($field['type'], array_merge($TEXT_FIELD_TYPES, array(FIELD_TYPE_CHECK_BOX_LIST, FIELD_TYPE_CATEGORY_TREE, FIELD_TYPE_DYNAMIC_KEYWORDS_LIST))))
{
# Append applies to text boxes, checkboxes ,category tree and dynamic keyword fields only.
?>
<option value="AP"<?php if(getval("modeselect_" . $field["ref"],"")=="AP"){?> selected<?php } ?>><?php echo $lang["appendtext"]?></option>
<?php
}
if(in_array($field['type'], array_merge($TEXT_FIELD_TYPES, array(FIELD_TYPE_CHECK_BOX_LIST, FIELD_TYPE_DROP_DOWN_LIST, FIELD_TYPE_CATEGORY_TREE, FIELD_TYPE_DYNAMIC_KEYWORDS_LIST))))
{
# Remove applies to text boxes, checkboxes, dropdowns, category trees and dynamic keywords only.
?>
<option value="RM"<?php if(getval("modeselect_" . $field["ref"],"")=="RM"){?> selected<?php } ?>><?php echo $lang["removetext"]?></option>
<?php
}
hook ("edit_all_extra_modes");
?>
</select>
</div><!-- End of modeselect_<?php echo $n?> -->

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

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

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

<?php
# Autosave display
if ($edit_autosave || $ctrls_to_save)
{
?>
<div class="AutoSaveStatus">
<span id="AutoSaveStatus<?php echo $field["ref"] ?>" style="display:none;"></span>
</div>
<?php
}
# 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;
}

if(!hook('replacefield', '', array($field['type'], $field['ref'], $n)))
{
global $auto_order_checkbox, $auto_order_checkbox_case_insensitive, $FIXED_LIST_FIELD_TYPES, $is_search;

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_LIST, FIELD_TYPE_CATEGORY_TREE)))
{
$name = "nodes[{$field['ref']}][]";
}
else if(FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $field['type'])
{
$name = "field_{$field['ref']}";
}

$field_nodes = array();
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;
natsort($field_nodes);
unset($node_data);
}

if(!$multiple && !$blank_edit_template && getval("copyfrom","") == "" && getval('metadatatemplate', '') == "" && $check_edit_checksums)
{
echo "<input id='field_" . $field['ref'] . "_checksum' name='" . "field_" . $field['ref'] . "_checksum' type='hidden' value='" . md5(implode(",",$field_nodes)) . "'>";
echo "<input name='" . "field_" . $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'], NULL, FALSE);
$field_nodes = array();
foreach($selected_nodes as $selected_node)
{
if(in_array($selected_node,array_column($field['nodes'],"ref")))
{
$field_nodes[] = $selected_node;
}
}
natsort($field_nodes);

echo "<input id='field_" . $field['ref'] . "_checksum' name='" . "field_" . $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_" . $field['ref'] . "_checksum' name='" . "field_" . $field['ref'] . "_checksum' type='hidden' value='" . md5(trim(preg_replace('/\s\s+/', ' ', $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">!! <?php echo $errors[$field["ref"]]?> !!</div>
<?php
}

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;<?php if ( in_array($field["type"],array(2,3,4,6,7,10,12,14)) ) { ?> clear:left;<?php } else { ?> display:none;<?php } ?>" id="help_<?php echo $field["ref"]?>"><div class="FormHelpInner"><?php echo nl2br(trim(i18n_get_translated($field["help_text"])))?></div></div>
<?php
}

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


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


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


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

</tr>
</tbody>
</table>
<?php
}
?>
<div class="clearerleft"> </div>
</div><!-- end of question_<?php echo $n?> div -->
<?php

hook('afterfielddisplay', '', array($n, $field));
}

Parameters

ColumnTypeDefaultDescription
$name
$value
$forsearch true
$autoupdate false
$field array
$reset ""

Location

include/render_functions.php lines 1958 to 2272

Definition

 
function render_date_range_field($name,$value,$forsearch=true,$autoupdate=false,$field=array(),$reset="")
    {
    
$found_year='';$found_month='';$found_day='';$found_start_year='';$found_start_month='';$found_start_day='';$found_end_year='';$found_end_month='';$found_end_day=''
    global 
$daterange_edtf_support,$lang$minyear,$date_d_m_y$chosen_dropdowns$edit_autosave,$forsearchbar$maxyear_extends_current;
    if(
$forsearch)
        {
        
// Get the start/end date from the string
        
$startvalue=strpos($value,"start")!==false?substr($value,strpos($value,"start")+5,10):"";
        
$endvalue=strpos($value,"end")!==false?substr($value,strpos($value,"end")+3,10):"";
        }
    else
        {
        if(
$value!="" && strpos($value,",")!==false)
            {
            
// Extract the start date from the value obtained from get_resource_field_data
            
$rangevalues explode(",",$value);
            
$startvalue $rangevalues[0];
            
$endvalue $rangevalues[1];
            }
        elseif(
strlen($value)==10 && strpos($value,"-") !==  false)
            {
            
$startvalue $value;
            
$endvalue "";
            }
        else
            {
            
$startvalue "";
            
$endvalue "";
            }
        }
                
    
$ss=explode("-",$startvalue);
    if (
count($ss)>=3)
        {
        
$found_start_year=$ss[0];
        
$found_start_month=$ss[1];
        
$found_start_day=$ss[2];
        }
    
$se=explode("-",$endvalue);
    if (
count($se)>=3)
        {
        
$found_end_year=$se[0];
        
$found_end_month=$se[1];
        
$found_end_day=$se[2];
        }
        
    
// If the form has been submitted (but not reset) but data was not saved get the submitted values   
    
if($reset == ""
        {
        foreach(array(
"start_year""start_month","start_day","end_year","end_month","end_day") as $subpart)
            {
            if(
getval($name "_" $subpart,"") != "")
                {
                ${
"found_" $subpart} = getval($name "_" $subpart,"");
                }
            }
        }
    
    if(
$daterange_edtf_support)
        {
        
// Use EDTF format for date input
        
?>        
        <input class=" echo $forsearch?"SearchWidth":"stdwidth"?>"  name=" echo $name?>_edtf" id=" echo $name?>_edtf" type="text" value=" echo ($startvalue!=""|$endvalue!="")?$startvalue "/" $endvalue:""?>" style="display:none;" disabled  if ($forsearch && $autoupdate) { ?>onChange="UpdateResultCount();" } if($forsearch && !$forsearchbar){ ?> onKeyPress="if (!(updating)) {setTimeout('UpdateResultCount()',2000);updating=true;}" } else if (!$forsearch  && $edit_autosave){?>onChange="AutoSave(' echo $field["ref"]?>');" ?>>
        
        
}?>
    <!--  date range search start -->           
    <!--- start date -->    
    <div class="stdwidth indent  echo $name?>_range" id=" echo $name?>_from">
    <label class="InnerLabel"> echo $lang["fromdate"]?></label>
    
                 
        
if($date_d_m_y)
            {  
            
?>
            <label class="accessibility-hidden" for=" echo htmlspecialchars($name?>_start_day"> echo $lang["day"]; ?></label>
            <select name=" echo $name?>_start_day"
              if ($chosen_dropdowns) {?>class="ChosenDateRangeDay" }
            if (
$forsearch && $autoupdate
                    { 
?>onChange="UpdateResultCount();" }
            else if (!
$forsearch  && $edit_autosave)
            {
?>onChange="AutoSave(' echo $field["ref"]?>');" ?>
              >
              <option value=""> echo $forsearch?$lang["anyday"]:$lang["day"]; ?></option>
              
              
for ($d=1;$d<=31;$d++)
                {
                
$m=str_pad($d,2,"0",STR_PAD_LEFT);
                
?><option  if ($d==$found_start_day) { ?>selected ?> value=" echo $m?>"> echo $m?></option>
                
}
              
?>
            </select>
            <label class="accessibility-hidden" for=" echo htmlspecialchars($name?>_start_month"> echo $lang["month"]; ?></label>
            <select name=" echo $name?>_start_month"
                 if ($chosen_dropdowns) {?>class="ChosenDateRangeMonth" }
                if (
$forsearch && $autoupdate
                    { 
?>onChange="UpdateResultCount();" }
                else if (!
$forsearch  && $edit_autosave)
                    {
?>onChange="AutoSave(' echo $field["ref"]?>');" ?>
                    >
                <option value=""> echo $forsearch?$lang["anymonth"]:$lang["month"]; ?></option>
                
                
for ($d=1;$d<=12;$d++)
                    {
                    
$m=str_pad($d,2,"0",STR_PAD_LEFT);
                    
?><option  if ($d==$found_start_month) { ?>selected ?> value=" echo $m?>"> echo $lang["months"][$d-1]?></option>
                    
}?>
            </select>
            
            
}
        else
            { 
            
?>        
            <label class="accessibility-hidden" for=" echo htmlspecialchars($name?>_start_month"> echo $lang["month"]; ?></label>
            <select name=" echo $name?>_start_month"
                 if ($chosen_dropdowns) {?>class="ChosenDateRangeMonth" }
                if (
$forsearch && $autoupdate
                    { 
?>onChange="UpdateResultCount();" }
                else if (!
$forsearch  && $edit_autosave)
                    {
?>onChange="AutoSave(' echo $field["ref"]?>');" ?>
                    >                    
                <option value=""> echo $forsearch?$lang["anymonth"]:$lang["month"]; ?></option>
                
                
for ($d=1;$d<=12;$d++)
                    {
                    
$m=str_pad($d,2,"0",STR_PAD_LEFT);
                    
?><option  if ($d==$found_start_month) { ?>selected ?> value=" echo $m?>"> echo $lang["months"][$d-1]?></option>
                    
}?>
            </select>
            <label class="accessibility-hidden" for=" echo htmlspecialchars($name?>_start_day"> echo $lang["day"]; ?></label>
            <select name=" echo $name?>_start_day"
               if ($chosen_dropdowns) {?>class="ChosenDateRangeDay" }
                if (
$forsearch && $autoupdate