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 escape_quoted_data($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" ;} ?>>
<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 htmlspecialchars($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 htmlspecialchars($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 htmlspecialchars($lang["findandreplace"])?></option>
<option value="CF"<?php if(getval("modeselect_" . $field["ref"],"")=="CF"){?> selected<?php } ?>><?php echo htmlspecialchars($lang["edit_copy_from_field"])?></option>
<?php
if(!$multilingual_text_fields)
{
// Prepending text doesn't work wih multilingual fields
?>
<option value="PP"<?php if(getval("modeselect_" . $field["ref"],"")=="PP"){?> selected<?php } ?>><?php echo htmlspecialchars($lang["prependtext"])?></option>
<?php
}
}
if((in_array($field['type'], $TEXT_FIELD_TYPES) && !$multilingual_text_fields) || in_array($field['type'], [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 onl.
?>
<option value="AP"<?php if(getval("modeselect_" . $field["ref"],"")=="AP"){?> selected<?php } ?>><?php echo htmlspecialchars($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.
if ($field['required'] == 0)
{
# And it only applies if the field is optional
?>
<option value="RM"<?php if(getval("modeselect_" . $field["ref"],"")=="RM"){?> selected<?php } ?>><?php echo htmlspecialchars($lang["removetext"])?></option>
<?php
}
}
hook ("edit_all_extra_modes","",[$field]);
?>
</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> </label>
<?php echo htmlspecialchars($lang["find"])?> <input type="text" name="find_<?php echo $field["ref"]?>" class="shrtwidth">
<?php echo htmlspecialchars($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 escape_quoted_data($labelname)?>" <?php if($field['type']==FIELD_TYPE_DATE_RANGE) {echo " class='daterangelabel'";} ?> >
<?php
if (!$multiple)
{
echo htmlspecialchars($field["title"]);
if (!$is_template && $field["required"]==1)
{
echo "<sup></sup>";
}
}
if ($upload_review_mode)
{
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;
}
// 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;
// Establish the full set of selected nodes to be rendered for this field
// Do this only if the field's selected nodes haven't previously been adjusted to take account of omit_when_copying
if(!$omit_when_copying_enacted)
{
$selected_nodes = array_unique(array_merge($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_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;
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'], 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;
}
}
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']))) . "'>";
}
elseif ($field['type'] === FIELD_TYPE_DATE && $GLOBALS['use_native_input_for_date_field'])
{
if ($GLOBALS['blank_date_upload_template'] && $value !== '' && $ref <= 0)
{
$value = '';
}
}
$is_search = false;
include "edit_fields/{$type}.php";
$lastglobal = $field['global']==1;
}
# ----------------------------------------------------------------------------
# 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 " " . $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 htmlspecialchars($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 htmlspecialchars($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 htmlspecialchars($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 htmlspecialchars($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
Column | Type | Default | Description |
---|---|---|---|
$name | |||
$value | |||
$forsearch | true | ||
$autoupdate | false | ||
$field | array | ||
$reset | "" |
Location
include/render_functions.php lines 2304 to 2677
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, $edit_autosave,$forsearchbar, $maxyear_extends_current;
if($forsearch)
{
// Get the start/end date from the string
$startpos = strpos($value,"start");
$endpos = strpos($value,"end");
$startvalue = $startpos !== false ? substr($value,$startpos+5,($endpos ? ($endpos - ($startpos + 5)) : NULL)) : "";
$endvalue = $endpos !== 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 = "";
}
}
$startvalue = trim($startvalue);
$endvalue = trim($endvalue);
$ss=explode("-",$startvalue);
if (count($ss)>=1)
{
$found_start_year = $ss[0] ?? "";
$found_start_month = $ss[1] ?? "";
$found_start_day = $ss[2] ?? "";
}
$se=explode("-",$endvalue);
if (count($se)>=1)
{
$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 htmlspecialchars($lang["fromdate"])?></label>
if($date_d_m_y)
{
?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_start_day"> echo htmlspecialchars($lang["day"]); ?></label>
<select name=" echo $name?>_start_day"
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 escape_quoted_data($name) ?>_start_month"> echo htmlspecialchars($lang["month"]); ?></label>
<select name=" echo $name?>_start_month"
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 htmlspecialchars($lang["months"][$d-1])?></option>
}?>
</select>
}
else
{
?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_start_month"> echo htmlspecialchars($lang["month"]); ?></label>
<select name=" echo $name?>_start_month"
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 htmlspecialchars($lang["months"][$d-1]) ?></option>
}?>
</select>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_start_day"> echo htmlspecialchars($lang["day"]); ?></label>
<select name=" echo $name?>_start_day"
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>
}
if($forsearch)
{?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_year"> echo htmlspecialchars($lang["year"]); ?></label>
<select name=" echo escape_quoted_data($name) ?>_start_year"
if ($forsearch && $autoupdate)
{ ?>onChange="UpdateResultCount();" }
else if (!$forsearch && $edit_autosave)
{?>onChange="AutoSave(' echo $field["ref"]?>');" } ?>
>
<option value=""> echo $forsearch?$lang["anyyear"]:$lang["year"]; ?></option>
$y=date("Y");
$y += $maxyear_extends_current;
for ($d=$y;$d>=$minyear;$d--)
{
?><option if ($d==$found_start_year) { ?>selected } ?>> echo $d?></option>
}?>
</select>
}
else
{?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_year"> echo htmlspecialchars($lang["year"]); ?></label>
<input size="5" name=" echo escape_quoted_data($name) ?>_start_year" id=" echo escape_quoted_data($name) ?>_start_year" type="text" value=" echo $found_start_year ?>"
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"]?>');" } ?>>
}?>
</div>
<div class="clearerleft"> </div>
<!--- to date -->
<label class='daterangelabel'></label>
<div class="stdwidth indent echo $name?>_range" id=" echo $name?>_to" >
<label class="InnerLabel"> echo htmlspecialchars($lang["todate"])?></label>
if($date_d_m_y)
{
?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_day"> echo htmlspecialchars($lang["day"]); ?></label>
<select name=" echo $name?>_end_day"
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_end_day) { ?>selected } ?> value=" echo $m?>"> echo $m?></option>
}?>
</select>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_month"> echo htmlspecialchars($lang["month"]); ?></label>
<select name=" echo $name?>_end_month"
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_end_month) { ?>selected } ?> value=" echo $m?>"> echo htmlspecialchars($lang["months"][$d-1])?></option>
}?>
</select>
}
else
{
?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_month"> echo htmlspecialchars($lang["month"]); ?></label>
<select name=" echo $name?>_end_month"
if (!$forsearch && $edit_autosave)
{?>onChange="AutoSave(' echo $field["ref"]?>');" }
else
{?>onChange="UpdateResultCount();" } ?>
>
<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_end_month) { ?>selected } ?> value=" echo $m?>"> echo htmlspecialchars($lang["months"][$d-1]) ?></option>
}?>
</select>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_day"> echo htmlspecialchars($lang["day"]); ?></label>
<select name=" echo $name?>_end_day"
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_end_day) { ?>selected } ?> value=" echo $m?>"> echo $m?></option>
}
?>
</select>
}
if($forsearch)
{?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_year"> echo htmlspecialchars($lang["year"]); ?></label>
<select name=" echo $name?>_end_year"
if ($forsearch && $autoupdate) { ?>onChange="UpdateResultCount();" }
else if (!$forsearch && $edit_autosave)
{?>onChange="AutoSave(' echo $field["ref"]?>');" } ?>
>
<option value=""> echo $forsearch?$lang["anyyear"]:$lang["year"]?></option>
$y=date("Y");
$y += $maxyear_extends_current;
for ($d=$y;$d>=$minyear;$d--)
{
?><option if ($d==$found_end_year ) { ?>selected } ?>> echo $d?></option>
}
?>
</select>
}
else
{?>
<label class="accessibility-hidden" for=" echo escape_quoted_data($name) ?>_end_year"> echo htmlspecialchars($lang["year"]); ?></label>
<input size="5" name=" echo escape_quoted_data($name) ?>_end_year" id=" echo escape_quoted_data($name) ?>_end_year" type="text" value=" echo $found_end_year ?>"
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"]?>');" } ?>>
}
if($forsearch !== true)
{
?>
<script>
//Get value of the date element before the change
jQuery('[name^= echo $name;?>]').on('focus', function(){
jQuery.data(this, 'current', jQuery(this).val());
});
//Check the value of the date after the change
jQuery('[name^= echo $name;?>_start]').on('change', function(){
let day = jQuery('[name= echo escape_quoted_data($name); ?>_start_day]').val().trim();
let month = jQuery('[name= echo escape_quoted_data($name); ?>_start_month]').val().trim();
let year = jQuery('[name= echo escape_quoted_data($name); ?>_start_year]').val().trim();
if (year != "" && !jQuery.isNumeric(year))
{
styledalert( echo "'" . $lang["error"] . "','" . $lang["invalid_date_generic"] . "'" ?>);
jQuery(this).val(jQuery.data(this, 'current'));
}
if(jQuery.isNumeric(year) && jQuery.isNumeric(day) && jQuery.isNumeric(month)){
//format date string into yyyy-mm-dd
let date_string = year + '-' + month + '-' + day;
//get a timestamp from the date string and then convert that back to yyyy-mm-dd
let date = new Date(date_string).toISOString().split('T')[0];
//check if the before and after are the same, if a date like 2021-02-30 is selected date would be 2021-03-02
if(date_string !== date){
styledalert( echo "'" . $lang["error"] . "','" . $lang["invalid_date_generic"] . "'" ?>);
jQuery(this).val(jQuery.data(this, 'current'))
}
}
})
//Same again but for the end of the date range
jQuery('[name^= echo $name;?>_end]').on('change', function(){
let day = jQuery('[name= echo escape_quoted_data($name); ?>_end_day]').val().trim();
let month = jQuery('[name= echo escape_quoted_data($name); ?>_end_month]').val().trim();
let year = jQuery('[name= echo escape_quoted_data($name); ?>_end_year]').val().trim();
if (year != "" && !jQuery.isNumeric(year))
{
styledalert( echo "'" . $lang["error"] . "','" . $lang["invalid_date_generic"] . "'" ?>);
jQuery(this).val(jQuery.data(this, 'current'));
}
if(jQuery.isNumeric(year) && jQuery.isNumeric(day) && jQuery.isNumeric(month)){
//format date string into yyyy-mm-dd
let date_string = year + '-' + month + '-' + day;
//get a timestamp from the date string and then convert that back to yyyy-mm-dd
let date = new Date(date_string).toISOString().split('T')[0];
//check if the before and after are the same, if a date like 2021-02-30 is selected date would be 2021-03-02
if(date_string !== date){
styledalert( echo "'" . $lang["error"] . "','" . $lang["invalid_date_generic"] . "'" ?>);
jQuery(this).val(jQuery.data(this, 'current'))
}
}
})
</script>
} ?>
<!-- date range search end date-->
</div>
<div class="clearerleft"></div>
if($daterange_edtf_support)
{?>
<a href="#" onclick="if(jQuery('# echo $name ?>_edtf').prop('disabled')){jQuery('# echo $name ?>_edtf').prop('disabled',false);jQuery('# echo $name ?>_edtf').show();jQuery('. echo $name ?>_range').hide();}else{jQuery('# echo $name ?>_edtf').prop('disabled',true);jQuery('# echo $name ?>_edtf').hide();jQuery('. echo $name ?>_range').show();}return false;">
<i aria-hidden="true" class="fa fa-caret-right"></i>
echo "EDTF"; ?>
</a>
}
}
This article was last updated 6th December 2023 10:35 Europe/London time based on the source file dated 29th November 2023 14:55 Europe/London time.