Id());
$SafeGroupName = defaulthtmlentities($Item->Name());
$Fields = $Item->GetFields();
# go to the next item if there are no fields in the group
if (!count($Fields)) continue; ?>
RequireUIFile("ckeditor.js");
$AF->RequireUIFile("ckeditor_setup.js");
# error codes (NOTE: Must match codes in SPT--EditResourceComplete.php!!!)
if (!defined("ERR_FILEUPLOADERROR"))
{
define("ERR_FILEUPLOADERROR", 1);
define("ERR_ZEROLENGTH", 2);
define("ERR_IMAGEUPLOADERROR", 3);
define("ERR_UNSUPPORTEDIMAGEFORMAT", 4);
define("ERR_UNKNOWNIMAGETYPE", 5);
define("ERR_REQUIREDFIELDEMPTY", 6);
define("ERR_POSTEMPTY", 7);
define("ERR_IMAGESTORE", 8);
define("ERR_TEMPSTORE", 9);
define("ERR_FILESTORE", 10);
}
# error messages
$ErrorMessages = array(
ERR_FILEUPLOADERROR => "A problem was encountered uploading the file %s for the %s field. (%s)",
ERR_ZEROLENGTH => "The file %s uploaded to the %s field was empty (zero length).",
ERR_IMAGEUPLOADERROR => "A problem was encountered uploading the image file %s for the %s field. (%s)",
ERR_UNSUPPORTEDIMAGEFORMAT => "The image file %s uploaded for the %s field was in an unsupported image format.",
ERR_UNKNOWNIMAGETYPE => "The image file %s uploaded for the %s field was of an unknown type.",
ERR_REQUIREDFIELDEMPTY => "%s%s is a required field.",
ERR_POSTEMPTY => "File or image upload was too large (No POST data received)",
ERR_IMAGESTORE => "There were problems with the image store:%s Contact the site administrator with this information to resolve them.",
ERR_TEMPSTORE => "tmp does not exist or is not writeable, contact the site administrator with this error.",
ERR_FILESTORE => File::GetStorageDirectory()." does not exist or is not writeable, contact the site administrator with this error."
);
?>
GetDisplayName(), $ErrorInfoTwo);
?>
UserCanViewField($User, $Field))
{
$Edit = $EditingAllowed
? $Resource->UserCanModifyField($User, $Field) : FALSE;
# if the field is not editable, don't allow editing in this
# interface
if (!$Field->Editable())
{
$Edit = FALSE;
}
$Error = $ErrorCode && in_array($Field->Id(), $ErrorFieldIds);
$EditValue = $Resource->GetByField($Field);
global $AF;
$SignalResult = $AF->SignalEvent(
($Edit ? "EVENT_PRE_FIELD_EDIT_FILTER"
: "EVENT_FIELD_DISPLAY_FILTER"), array(
"Field" => $Field,
"Resource" => $Resource,
"Value" => $EditValue));
$EditValue = $SignalResult["Value"];
# get additional HTML to display, if any
$Context = $Edit ? "EDIT" : "EDIT_COMPLETE_DISPLAY";
$SignalResult = $AF->SignalEvent(
"EVENT_APPEND_HTML_TO_FIELD_DISPLAY",
array(
"Field" => $Field, "Resource" => $Resource,
"Context" => $Context, "Html" => NULL));
$Html = $SignalResult["Html"];
switch ($Field->Type())
{
case MetadataSchema::MDFTYPE_TEXT:
case MetadataSchema::MDFTYPE_NUMBER:
case MetadataSchema::MDFTYPE_DATE:
case MetadataSchema::MDFTYPE_URL:
DisplayTextField(
$Field, $Resource, $Edit, $Error, $EditValue, $Html);
break;
case MetadataSchema::MDFTYPE_TIMESTAMP:
DisplayTimestampField(
$Field, $Resource, $Edit,
$Error, $EditValue, $Html);
break;
case MetadataSchema::MDFTYPE_POINT:
DisplayPointField(
$Field, $Resource, $Edit, $Error, $EditValue, $Html);
break;
case MetadataSchema::MDFTYPE_PARAGRAPH:
DisplayParagraphField(
$Field, $Resource, $Edit, $Error, $EditValue, $Html);
break;
case MetadataSchema::MDFTYPE_FLAG:
DisplayFlagField(
$Field, $Resource, $Edit, $Error, $EditValue, $Html);
break;
case MetadataSchema::MDFTYPE_TREE:
DisplayTreeField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_CONTROLLEDNAME:
DisplayControlledNameField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_OPTION:
DisplayOptionField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_USER:
DisplayUserField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_IMAGE:
DisplayImageField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_FILE:
DisplayFileField($Field, $Resource, $Edit, $Error, $Html);
break;
case MetadataSchema::MDFTYPE_REFERENCE:
DisplayReferenceField($Field, $Resource, $Edit, $Error, $Html);
}
}
}
function PrintLabelCell($Field, $Error, $IsEditable, $PseudoLabel=FALSE)
{
$FieldName = defaulthtmlentities($Field->GetDisplayName());
$Instructions = $Field->Instructions();
$ClassAttr = NULL;
$OnEditPage = GetArrayValue($_GET, "P") == "EditResource";
# use the field definition if no instructions are available
if (strlen($Instructions) < 1)
{
$Instructions = $Field->Description();
}
$Title = defaulthtmlentities(strip_tags(trim($Instructions)));
$Instructions = defaulthtmlentities(trim($Instructions));
if ($Error)
{
$ClassAttr = "cw-form-error";
}
else if (!$Field->Optional() && $IsEditable)
{
$ClassAttr = "cw-form-required";
}
?>
Get($Field);
asort($Values);
# get all possible values and sort them alphabetically
$PossibleValues = $Field->GetPossibleValues();
asort($PossibleValues);
$MaxValueLength = 0;
# determine the length of the longest value in order to determine how many
# options will be displayed per row
foreach ($PossibleValues as $PossibleValue)
{
$Length = strlen($PossibleValue);
if ($Length > $MaxValueLength)
{
$MaxValueLength = $Length;
}
}
# determine how many values per row based on length of longest value
if ($MaxValueLength > 25) { $OptionsPerRow = 2; }
else if ($MaxValueLength > 17) { $OptionsPerRow = 3; }
else if ($MaxValueLength > 12) { $OptionsPerRow = 4; }
else { $OptionsPerRow = 5; }
# determine how many rows there should be
$NumberOfRows = ceil((count($PossibleValues) + ($OptionsPerRow - 1)) / $OptionsPerRow);
$SafeFieldName = defaulthtmlentities($Field->DBFieldName());
?>
"
name="[]"
value=""
/>
GetPossibleValues();
asort($Names);
$Names = array(-1 => "--") + $Names;
# retrieve values currently selected
$SetNames = $Resource->Get($Field);
asort($SetNames);
# set up javascript function to dynamically populate option lists
$DBFieldName = $Field->DBFieldName();
?>
$Name)
{
PrintOptionList("D_".$DBFieldName."_".$MenuIndex, $Names, $NameId,
"", 1, 0, FALSE,
"CheckAdd('dbentry', 'D_".$DBFieldName."_', ".$MenuIndex.");",
"auto; display: block; max-height: 10000000");
$MenuIndex++;
}
# print option list for use in selecting additional name
PrintOptionList("D_".$DBFieldName."_".$MenuIndex, $Names, -1,
"", 1, 0, FALSE,
"CheckAdd('dbentry', 'D_".$DBFieldName."_', ".$MenuIndex.");",
"auto; display: block; max-height: 10000000");
$MenuIndex++;
# print shells to contain additional option lists
$MaxNames = 21;
for (; $MenuIndex < $MaxNames; $MenuIndex++)
{
?>
DBFieldName());
$SafeFieldId = defaulthtmlentities($Field->Id());
$SafeValues = array();
$SafeNumAjaxResults = defaulthtmlentities($Field->NumAjaxResults());
# get the escaped values for the references
foreach ($Resource->Get($Field) as $NameId => $Name)
{
$SafeValues[$Name] = array(
"Id" => defaulthtmlentities($NameId),
"Title" => defaulthtmlentities($Name));
}
# sort alphabetically by key
ksort($SafeValues);
?>
" />
GetPossibleValues();
# sort values and add "no value" value
$PossibleValues[-1] = "--";
asort($PossibleValues);
# retrieve value currently selected
$Value = $Resource->Get($Field, TRUE);
$SelectedValue = $Value instanceof User ? $Value->Id() : NULL;
# set up javascript function to dynamically populate option lists
$DBFieldName = $Field->DBFieldName();
PrintOptionList(
"F_".$DBFieldName,
$PossibleValues,
$SelectedValue,
"", 1, 0, FALSE,
"",
"auto; display: block; max-height: 10000000");
}
function DisplayTermUsingSearch($Field, $Resource, $Context=NULL)
{
# retrieve field name/id and values currently selected
$DBFieldName = $Field->DBFieldName();
$DBFieldId = $Field->Id();
# retrieve value currently selected
$Value = $Resource->Get($Field, TRUE);
$SelectedValue = $Value instanceof User ? $Value->Name() : NULL;
$SelectedValue = defaulthtmlentities($SelectedValue);
# print search input/text container for use in selecting additional name
?>
OptionListThreshold();
$AjaxThreshold = $Field->AjaxThreshold();
$ValueCount = $Field->GetCountOfPossibleValues();
?>
(no values defined for this field)";
}
else
{
if ($ValueCount < $OptionListThreshold)
{
DisplayTermsUsingOptions($Field, $Resource);
}
else if ($ValueCount < $AjaxThreshold)
{
DisplayTermsUsingLists($Field, $Resource);
}
else
{
DisplayTermsUsingSearch($Field, $Resource);
}
}
}
else
{
?>
GetByField($Field);
# retrieve all possible values if user can edit this field
if ($IsEditable)
{
$Options = $Field->GetPossibleValues();
asort($Options);
}
# otherwise use just options that are set to display
else
{
$Options = $SetOptions;
}
$MaxLength = 0;
# determine the length of the longest value
foreach ($Options as $OptionName)
{
$Length = strlen($OptionName);
if ($Length > $MaxLength)
{
$MaxLength = $Length;
}
}
# determine how many values per row based on length of longest value
if ($MaxLength > 25) { $OptionsPerRow = 2; }
else if ($MaxLength > 17) { $OptionsPerRow = 3; }
else if ($MaxLength > 12) { $OptionsPerRow = 4; }
else { $OptionsPerRow = 5; }
# determine number of rows
$OptionCount = count($Options);
$NumberOfRows = intval(($OptionCount + ($OptionsPerRow - 1)) / $OptionsPerRow);
?>
Id());
$SafeDBFieldName = defaulthtmlentities($Field->DBFieldName());
$SafeReferences = array();
$SafeNumAjaxResults = defaulthtmlentities($Field->NumAjaxResults());
$Schema = new MetadataSchema($Resource->SchemaId());
$TitleField = $Schema->GetFieldByMappedName("Title");
# get the escaped values for the references
foreach ($Resource->Get($Field, TRUE) as $ReferenceId => $Reference)
{
$Title = $Reference->Get($TitleField);
# remove HTML if editing because HTML tags are displayed as text in
# input fields
if ($IsEditable)
{
$Title = strip_tags($Title);
}
# otherwise escape HTML characters if HTML is not allowed in the field
else if (!$TitleField->AllowHTML())
{
$Title = defaulthtmlentities($Title);
}
$SafeReferences[] = array(
"Id" => defaulthtmlentities($ReferenceId),
"Title" => $Title);
}
?>