5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2016-2017 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 137 # ---- PUBLIC INTERFACE -------------------------------------------------- 146 $TableCssClass = NULL)
148 # display nothing if there are no fields 149 if (!count($this->FieldParams)) {
return; }
151 # check whether table should be split into sections 152 $TableIsSectioned = FALSE;
153 foreach ($this->FieldParams as $Name => $Params)
155 if ($Params[
"Type"] == self::FTYPE_HEADING)
156 { $TableIsSectioned = TRUE; }
161 ?><table
class=
"cw-table cw-table-fullsize cw-table-sideheaders cw-table-padded cw-table-striped<?PHP 162 if ($TableIsSectioned) { print(" cw-table-sectioned
"); } 163 if (!is_null($TableCssClass)) { print(" ".$TableCssClass); } 164 ?> cw-content-sysconfigtable"<?
PHP 165 if ($TableId) { print(
" id=\"".$TableId.
"\""); }
166 if ($TableStyle) { print(
" style=\"".$TableStyle.
"\""); }
172 foreach ($this->FieldParams as $Name => $Params)
174 # generate name for field 177 # if field is actually a section heading 178 if ($Params[
"Type"] == self::FTYPE_HEADING)
180 # split table section and display heading 181 if (isset($HeadingAlreadyDisplayed)) { print(
"</tbody><tbody>"); }
182 ?><tr
id=
"section-<?= $FormFieldName 183 ?>"><th colspan=
"3" scope=
"rowspan"><?=
184 $Params[
"Label"] ?></th></tr><?
PHP 185 $HeadingAlreadyDisplayed = TRUE;
189 # determine if row may have taller content 190 $ShortRowFieldTypes = array(
192 self::FTYPE_METADATAFIELD,
194 self::FTYPE_PASSWORD,
199 $IsTallRow = !isset($Params[
"Units"])
200 && !in_array($Params[
"Type"], $ShortRowFieldTypes)
201 && (($Params[
"Type"] != self::FTYPE_OPTION)
202 || (isset($Params[
"Rows"])
203 && ($Params[
"Rows"] > 1)));
205 # load up value(s) to go into field 208 # set up CSS classes for table row 209 $RowClass =
"cw-formui-fieldtype-".strtolower($Params[
"Type"]);
210 if ($Params[
"Type"] ==
"MetadataField")
212 $RowClass .=
" cw-formui-schemaid-" 213 .GetArrayValue($Params,
"SchemaId",
216 $RowClass .= $IsTallRow ?
" cw-content-tallrow" :
"";
217 $RowClassAttrib =
' class="'.$RowClass.
'"';
219 # set up CSS classes for row header cell 220 $HeaderClass = $IsTallRow ?
"cw-content-tallrow-th" :
"";
221 $HeaderClassAttrib = strlen($HeaderClass)
222 ?
' class="'.$HeaderClass.
'"' :
"";
224 # set up CSS classes for row label 225 $LabelClass =
"cw-form-pseudolabel" 226 .(isset(self::$ErrorMessages[$Name])
227 ?
" cw-form-error" :
"");
229 # set up min/max note if applicable 230 unset($RangeNotePieces);
231 if (isset($Params[
"MinVal"]))
233 $RangeNotePieces[] =
"Minimum: <i>".$Params[
"MinVal"].
"</i>";
235 if (isset($Params[
"MaxVal"]))
237 $RangeNotePieces[] =
"Maximum: <i>".$Params[
"MaxVal"].
"</i>";
239 if (isset($Params[
"RecVal"]))
241 $RangeNotePieces[] =
"Recommended: <i>".$Params[
"RecVal"].
"</i>";
243 if (isset($RangeNotePieces))
245 $RangeNote =
"(".implode(
", ", $RangeNotePieces).
")";
250 <tr<?= ($IsTallRow ?
" valign=\"top\"" :
"").$RowClassAttrib
251 ?>
id=
"row-<?= $FormFieldName ?>">
252 <th<?= $HeaderClassAttrib ?>>
253 <label
for=
"<?= $FormFieldName 254 ?>" class=
"<?= $LabelClass ?>"><?=
255 $Params[
"Label"] ?></label>
257 <td <?
PHP if (!isset($Params[
"Help"]) && !isset($RangeNotePieces)) {
258 print
"colspan=\"2\""; } ?>><?
PHP 260 $Name, $Value, $Params); ?></td>
261 <?
PHP if (isset($Params[
"Help"])) { ?>
262 <td
class=
"cw-content-help-cell"><?= $Params[
"Help"] ?></td>
263 <?
PHP } elseif (isset($RangeNotePieces)) { ?>
264 <td
class=
"cw-content-help-cell"><?= $RangeNote ?></td>
275 # add any hidden form fields 278 # add any needed JavaScript for toggled fields 281 # pull in WYSIWYG editor setup if needed 282 if ($this->UsingWysiwygEditor)
284 require_once($GLOBALS[
"AF"]->GUIFile(
"CKEditorSetup.php"));
294 if (count(self::$ErrorMessages))
296 print
"<ul class=\"cw-form-error\">\n";
297 $DisplayedMsgs = array();
298 foreach (self::$ErrorMessages as $Field => $Msgs)
300 foreach ($Msgs as $Msg)
302 if (!in_array($Msg, $DisplayedMsgs))
304 print
"<li>".$Msg.
"</li>\n";
305 $DisplayedMsgs[] = $Msg;
319 parent::HandleDeletes();
321 $TextFieldsToCheck = array();
323 # check for text fields that may contain images 324 foreach ($this->FieldParams as $Name => $Params)
326 if (isset($Params[
"InsertIntoField"])
327 && (($Params[
"Type"] == self::FTYPE_FILE)
328 || ($Params[
"Type"] == self::FTYPE_IMAGE)))
330 $TextFieldsToCheck[] = $Params[
"InsertIntoField"];
334 # load images to check 335 foreach ($this->DeletedImages as $ImageId)
337 $Images[$ImageId] =
new SPTImage($ImageId);
340 # load files to check 341 foreach ($this->DeletedFiles as $FileId)
343 $Files[$FileId] =
new File($FileId);
346 # for each text field potentially containing references to deleted items 347 foreach ($TextFieldsToCheck as $FieldName)
349 # get HTML form field name for field 352 # for each deleted image 353 foreach ($this->DeletedImages as $ImageId)
355 # strip out any tags referencing that image from field content 356 $_POST[$FormFieldName] = preg_replace(
358 .$Images[$ImageId]->PreviewUrl().
"\"[^>]*>%",
363 # for each deleted file 364 foreach ($this->DeletedFiles as $FileId)
366 # strip out any tags we inserted that reference that file 367 $FileLink = $Files[$FileId]->GetLink();
368 $_POST[$FormFieldName] = preg_replace(
370 .preg_quote(htmlspecialchars($FileLink),
'%')
371 .
"\"[^>]*>(.*?)</a>%",
380 # ---- PRIVATE INTERFACE ------------------------------------------------- 399 ($Params[
"Type"] != self::FTYPE_PRIVILEGES));
401 switch ($Params[
"Type"])
403 case self::FTYPE_TEXT:
404 case self::FTYPE_NUMBER:
405 case self::FTYPE_URL:
406 case self::FTYPE_USER:
407 case self::FTYPE_PASSWORD:
408 if ($Params[
"Type"] == self::FTYPE_USER)
410 if (is_numeric($Value))
412 $User =
new CWUser($Value);
413 $Value = $User->Name();
416 $DefaultSize = ($Params[
"Type"] == self::FTYPE_NUMBER) ? 6 : 40;
417 $DefaultMaxLen = ($Params[
"Type"] == self::FTYPE_NUMBER) ? 12 : 80;
418 $Size = isset($Params[
"Size"]) ? $Params[
"Size"]
419 : (isset($Params[
"MaxVal"])
420 ? (strlen(intval($Params[
"MaxVal"]) + 1))
422 $MaxLen = isset($Params[
"MaxLength"]) ? $Params[
"MaxLength"]
423 : (isset($Params[
"MaxVal"])
424 ? (strlen(intval($Params[
"MaxVal"]) + 3))
426 $Placeholder = isset($Params[
"Placeholder"])
427 ? $Params[
"Placeholder"]
428 :
"(".strtolower($Params[
"Label"]).
")";
429 $InputType = ($Params[
"Type"] == self::FTYPE_PASSWORD)
430 ?
"password" :
"text";
431 print(
'<input type="'.$InputType.
'" size="'.$Size.
'" maxlength="' 432 .$MaxLen.
'" id="'.$FieldName.
'" name="'.$FieldName.
'"' 433 .
' value="'.htmlspecialchars($Value).
'"' 434 .
' placeholder=" '.htmlspecialchars($Placeholder).
'"' 435 .($Params[
"ReadOnly"] ?
" readonly" :
"").
' />');
438 case self::FTYPE_PARAGRAPH:
439 $Rows = isset($Params[
"Rows"]) ? $Params[
"Rows"] : 4;
440 $Columns = isset($Params[
"Columns"]) ? $Params[
"Columns"] : 40;
441 print(
'<textarea rows="'.$Rows.
'" cols="'.$Columns
442 .
'" id="'.$FieldName.
'" name="'.$FieldName.
'"' 443 .($Params[
"ReadOnly"] ?
" readonly" :
"")
444 .($Params[
"UseWYSIWYG"] ?
' class="ckeditor"' :
"").
'>' 445 .htmlspecialchars($Value)
447 if ($Params[
"UseWYSIWYG"])
449 $this->UsingWysiwygEditor = TRUE;
453 case self::FTYPE_FLAG:
454 if (array_key_exists(
"OnLabel", $Params)
455 && array_key_exists(
"OffLabel", $Params))
457 print(
'<input type="radio" id="'.$FieldName.
'On" name="' 458 .$FieldName.
'" value="1"' 459 .($Value ?
' checked' :
'')
460 .($Params[
"ReadOnly"] ?
' disabled' :
'')
461 .
' /> <label for="'.$FieldName.
'On">'.$Params[
"OnLabel"]
463 print(
'<input type="radio" id="'.$FieldName.
'Off" name="' 464 .$FieldName.
'" value="0"' 465 .($Value ?
'' :
' checked')
466 .($Params[
"ReadOnly"] ?
' disabled' :
'')
467 .
' /> <label for="'.$FieldName.
'Off">'.$Params[
"OffLabel"]
472 print(
'<input type="checkbox" id="'.$FieldName.
'" name="' 474 .($Value ?
' checked' :
'')
475 .($Params[
"ReadOnly"] ?
' disabled' :
'')
480 case self::FTYPE_OPTION:
481 if ($this->IsRadioButtonField($Name))
484 $FieldName, $Params[
"Options"], $Value);
489 $FieldName, $Params[
"Options"], $Value);
490 $OptList->MultipleAllowed($Params[
"AllowMultiple"]);
491 $OptList->Size(isset($Params[
"Rows"]) ? $Params[
"Rows"] : 1);
493 $OptList->Disabled($Params[
"ReadOnly"]);
494 $OptList->PrintHtml();
497 case self::FTYPE_METADATAFIELD:
498 $FieldTypes = GetArrayValue($Params,
"FieldTypes");
499 $SchemaId = GetArrayValue($Params,
"SchemaId",
502 print $Schema->GetFieldsAsOptionList(
503 $FieldName, $FieldTypes, $Value,
504 !$Params[
"AllowMultiple"] && !$Params[
"Required"],
505 NULL, $Params[
"AllowMultiple"], $Params[
"ReadOnly"]);
508 case self::FTYPE_PRIVILEGES:
509 # (convert legacy previously-stored values if necessary) 510 if (is_array($Value))
513 $PrivSet->AddPrivilege($Value);
517 $Schemas = GetArrayValue($Params,
"Schemas");
518 $MFields = GetArrayValue($Params,
"MetadataFields", array());
520 $PEditor->DisplaySet($FieldName, $Value);
523 case self::FTYPE_SEARCHPARAMS:
526 if (isset($Params[
"MaxFieldLabelLength"]))
528 $SPEditor->MaxFieldLabelLength($Params[
"MaxFieldLabelLength"]);
530 if (isset($Params[
"MaxValueLabelLength"]))
532 $SPEditor->MaxValueLabelLength($Params[
"MaxValueLabelLength"]);
535 $SPEditor->DisplayAsTable();
538 case self::FTYPE_FILE:
542 case self::FTYPE_IMAGE:
547 if (isset($Params[
"Units"]))
550 print $Params[
"Units"];
563 # normalize incoming value 564 $Images = is_array($Value) ? $Value
565 : (($Value === NULL) ? array() : array($Value));
568 print
'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
570 # for each incoming value 571 $ImagesDisplayed = 0;
572 $InsertButtonHtml =
"";
573 foreach ($Images as $Image)
575 # skip if image is a placeholder to indicate no images for field 576 if ($Image == self::NO_VALUE_FOR_FIELD)
581 # load up image object if ID supplied 582 if (is_numeric($Image))
587 # skip image if it has been deleted 593 # load various image attributes for use in HTML 594 $ImageUrl = defaulthtmlentities($Image->ThumbnailUrl());
595 $ImageId = $Image->Id();
596 $ImageAltTextFieldName = $FieldName.
"_AltText_".$ImageId;
597 $ImageAltText = defaulthtmlentities(
598 isset($_POST[$ImageAltTextFieldName])
599 ? $_POST[$ImageAltTextFieldName]
600 : $Image->AltText());
604 # build up HTML for any insert buttons 605 if (isset($Params[
"InsertIntoField"]))
608 $InsertRightCommand = defaulthtmlentities(
609 "CKEDITOR.instances['".$InsertField
611 .
"'<img src=\"".$Image->PreviewUrl().
"\" alt=\"" 612 .htmlspecialchars($Image->AltText())
613 .
"\" class=\"cw-formui-image-right\" />');");
614 $InsertLeftCommand = defaulthtmlentities(
615 "CKEDITOR.instances['".$InsertField
617 .
"'<img src=\"".$Image->PreviewUrl().
"\" alt=\"" 618 .htmlspecialchars($Image->AltText())
619 .
"\" class=\"cw-formui-image-left\" />');");
620 $InsertButtonHtml =
'<button type="button" onclick="' 621 .$InsertLeftCommand.
'">Insert-L</button>' 622 .
'<button type="button" onclick="' 623 .$InsertRightCommand.
'">Insert-R</button>';
626 # add table row for image 628 <td><img src=
"<?= $ImageUrl ?>"></td>
629 <td style=
"white-space: nowrap;"><label
for=
"<?= 630 $ImageAltTextFieldName ?>" class=
"cw-form-pseudolabel">
631 Alt Text:</label><input type=
"text" size=
"20" 632 maxlength=
"120" name=
"<?= $ImageAltTextFieldName ?>" 633 value=
"<?= $ImageAltText ?>" 634 placeholder=
" (alternate text for image)"></td>
635 <td><?= $InsertButtonHtml ?><input type=
"submit" name=
"Submit" 636 onclick=
"$('#<?= $DeleteFieldName ?>').val('<?= $ImageId 637 ?>');" value=
"Delete"></td>
641 # add image ID to hidden fields 642 $this->HiddenFields[$FieldName.
"_ID"][] = $Image->Id();
644 # add container to hold ID of any image to be deleted 645 if (!isset($this->HiddenFields[$DeleteFieldName]))
647 $this->HiddenFields[$DeleteFieldName] =
"";
651 # if no images were displayed and an image entry was skipped 652 if (($ImagesDisplayed == 0) && count($Images))
654 # add marker to indicate no images to hidden fields 655 $this->HiddenFields[$FieldName.
"_ID"][] = self::NO_VALUE_FOR_FIELD;
658 # add table row for new image upload 659 if ($Params[
"AllowMultiple"] || ($ImagesDisplayed == 0))
661 $ImageAltTextFieldName = $FieldName.
"_AltText_NEW";
663 <td><input type=
"file" name=
"<?= $FieldName ?>" /></td>
664 <td style=
"white-space: nowrap;"><label
for=
"<?= 665 $ImageAltTextFieldName ?>" class=
"cw-form-pseudolabel">
666 Alt Text:</label><input type=
"text" size=
"20" 667 maxlength=
"120" name=
"<?= $ImageAltTextFieldName ?>" 668 placeholder=
" (alternate text for image)"></td>
669 <td><input type=
"submit" name=
"Submit" value=
"Upload" /></td>
685 # normalize incoming value 686 $Files = is_array($Value) ? $Value
687 : (($Value === NULL) ? array() : array($Value));
690 print
'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
692 # for each incoming value 694 $InsertButtonHtml =
"";
695 foreach ($Files as $File)
697 # skip if file is a placeholder to indicate no files for field 698 if ($File == self::NO_VALUE_FOR_FIELD)
703 # load up file object if ID supplied 704 if (is_numeric($File))
706 $File =
new File($File);
709 # skip file if it has been deleted 715 # load various attributes for use in HTML 716 $FileId = $File->Id();
717 $FileUrl = $File->GetLink();
718 $FileName = $File->Name();
719 $FileLinkTag =
"<a href=\"".htmlspecialchars($FileUrl).
"\">" 720 .htmlspecialchars($FileName).
"</a>";
723 # build up HTML for any insert buttons 724 if (isset($Params[
"InsertIntoField"]))
727 $InsertCommand = defaulthtmlentities(
728 "CKEDITOR.instances['".$InsertField
729 .
"'].insertHtml('".$FileLinkTag.
"');");
730 $InsertButtonHtml =
'<button type="button" onclick="' 731 .$InsertCommand.
'">Insert</button>';
734 # add table row for file 736 <td><?= $FileLinkTag ?></td>
737 <td><?= $InsertButtonHtml ?><input type=
"submit" name=
"Submit" 738 onclick=
"$('#<?= $DeleteFieldName ?>').val('<?= $FileId 739 ?>');" value=
"Delete"></td>
743 # add file ID to hidden fields 744 $this->HiddenFields[$FieldName.
"_ID"][] = $FileId;
746 # add container to hold ID of any file to be deleted 747 if (!isset($this->HiddenFields[$DeleteFieldName]))
749 $this->HiddenFields[$DeleteFieldName] =
"";
753 # if no files were displayed and a file entry was skipped 754 if (($FilesDisplayed == 0) && count($Files))
756 # add marker to indicate no files to hidden fields 757 $this->HiddenFields[$FieldName.
"_ID"][] = self::NO_VALUE_FOR_FIELD;
760 # add table row for new file upload 761 if ($Params[
"AllowMultiple"] || ($FilesDisplayed == 0))
764 <td><input type=
"file" name=
"<?= $FieldName ?>" /></td>
765 <td><input type=
"submit" name=
"Submit" value=
"Upload" /></td>
779 # for each form field 780 foreach ($this->FieldParams as $ToggledField => $Params)
782 # if field has togglers (other fields that can toggle this field) 783 if (isset($Params[
"DisplayIf"]))
786 foreach ($Params[
"DisplayIf"] as $Toggler => $ToggleValues)
788 # add field to list of fields toggled by this toggler 789 $FieldsToggled[$Toggler][] = $ToggledField;
791 # add values to list of values that toggle this field 792 if (!is_array($ToggleValues))
793 { $ToggleValues = array($ToggleValues); }
794 $FieldToggleValues[$ToggledField][$Toggler] = $ToggleValues;
799 # if there were fields that toggle other fields 800 if (isset($FieldsToggled))
802 # start JavaScript code 804 <script type=
"text/javascript">
809 foreach ($FieldsToggled as $Toggler => $ToggledFields)
811 # begin function called when toggler changes 814 $(
"[id^=<?= $TogglerFFName ?>]").change(
function(){
817 # for each togglee (field being toggled) 818 foreach ($ToggledFields as $ToggledField)
820 # get JavaScript condition for this togglee 821 $ConditionJS = $this->GetFieldToggleConditionJS(
822 $FieldToggleValues[$ToggledField]);
824 # add toggle code for togglee 827 $(
"#row-<?= $ToggledFieldFFName ?>")[<?=
828 $ConditionJS ?> ?
"show" :
"hide"]();
832 # end function for field changing 838 # end JavaScript code 852 private function GetFieldToggleConditionJS($ToggleValues)
855 foreach ($ToggleValues as $Toggler => $ToggleValues)
857 # start with fresh subcondition list 858 $SubConditions = array();
860 # for each toggle value 862 foreach ($ToggleValues as $Value)
864 # build subcondition for value 865 if ($this->FieldParams[$Toggler][
"Type"] == self::FTYPE_FLAG)
869 $SubConditions[] =
"($(\"input[name=".$TogglerFFName
870 .
"]\").is(\":checked:visible\"))";
874 $SubConditions[] =
"(!$(\"input[name=".$TogglerFFName
875 .
"]\").is(\":checked:visible\"))";
880 if ($this->IsRadioButtonField($Toggler))
882 $SubConditions[] =
"($(\"input[name=".$TogglerFFName
883 .
"]:checked\").val() == \"".$Value.
"\")";
887 $SubConditions[] =
"($(\"#".$TogglerFFName
888 .
"\").val() == \"".$Value.
"\")";
893 # assemble subconditions into condition 894 if (count($SubConditions) > 1)
896 $SubConditionStrings[] =
"(".implode(
" || ", $SubConditions).
")";
900 $SubConditionStrings[] = $SubConditions[0];
904 # assemble conditions into condition string 905 $ConditionString = implode(
" && ", $SubConditionStrings);
907 return $ConditionString;
915 private function IsRadioButtonField($FieldName)
917 $Params = $this->FieldParams[$FieldName];
918 if ($Params[
"Type"] == self::FTYPE_OPTION)
920 if (isset($Params[
"RadioButtons"]))
922 return $Params[
"RadioButtons"] ? TRUE : FALSE;
924 elseif (isset($Params[
"AllowMultiple"]) && $Params[
"AllowMultiple"])
930 return (count($Params[
"Options"])
931 <= self::OPTION_RADIO_BUTTON_THRESHOLD) ? TRUE : FALSE;
User interface element for editing PrivilegeSets.
Set of privileges used to access resource information or other parts of the system.
Encapsulates a full-size, preview, and thumbnail image.
Class representing a stored (usually uploaded) file.
CWIS-specific user class.
Convenience class for generating an HTML select/option form element.
Class to create a user interface for editing SearchParameterSets.