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 ($Params[
"Type"] == self::FTYPE_IMAGE &&
327 isset($Params[
"InsertIntoField"]))
329 $TextFieldsToCheck[]= $Params[
"InsertIntoField"];
333 # for each image-containing text field 334 foreach ($TextFieldsToCheck as $Name)
336 # and for each deleted image 337 foreach ($this->DeletedImages as $ImageId)
339 # strip out image tags referencing that image from the values 340 # presented in $_POST 344 $_POST[$FieldName] = preg_replace(
345 "%<img [^>]*src=\"".$Image->PreviewUrl().
"\"[^>]*>%",
"",
353 # ---- PRIVATE INTERFACE ------------------------------------------------- 372 ($Params[
"Type"] != self::FTYPE_PRIVILEGES));
374 switch ($Params[
"Type"])
376 case self::FTYPE_TEXT:
377 case self::FTYPE_NUMBER:
378 case self::FTYPE_URL:
379 case self::FTYPE_USER:
380 case self::FTYPE_PASSWORD:
381 if ($Params[
"Type"] == self::FTYPE_USER)
383 if (is_numeric($Value))
385 $User =
new CWUser($Value);
386 $Value = $User->Name();
389 $DefaultSize = ($Params[
"Type"] == self::FTYPE_NUMBER) ? 6 : 40;
390 $DefaultMaxLen = ($Params[
"Type"] == self::FTYPE_NUMBER) ? 12 : 80;
391 $Size = isset($Params[
"Size"]) ? $Params[
"Size"]
392 : (isset($Params[
"MaxVal"])
393 ? (strlen(intval($Params[
"MaxVal"]) + 1))
395 $MaxLen = isset($Params[
"MaxLength"]) ? $Params[
"MaxLength"]
396 : (isset($Params[
"MaxVal"])
397 ? (strlen(intval($Params[
"MaxVal"]) + 3))
399 $Placeholder = isset($Params[
"Placeholder"])
400 ? $Params[
"Placeholder"]
401 :
"(".strtolower($Params[
"Label"]).
")";
402 $InputType = ($Params[
"Type"] == self::FTYPE_PASSWORD)
403 ?
"password" :
"text";
404 print(
'<input type="'.$InputType.
'" size="'.$Size.
'" maxlength="' 405 .$MaxLen.
'" id="'.$FieldName.
'" name="'.$FieldName.
'"' 406 .
' value="'.htmlspecialchars($Value).
'"' 407 .
' placeholder=" '.htmlspecialchars($Placeholder).
'"' 408 .($Params[
"ReadOnly"] ?
" readonly" :
"").
' />');
411 case self::FTYPE_PARAGRAPH:
412 $Rows = isset($Params[
"Rows"]) ? $Params[
"Rows"] : 4;
413 $Columns = isset($Params[
"Columns"]) ? $Params[
"Columns"] : 40;
414 print(
'<textarea rows="'.$Rows.
'" cols="'.$Columns
415 .
'" id="'.$FieldName.
'" name="'.$FieldName.
'"' 416 .($Params[
"ReadOnly"] ?
" readonly" :
"")
417 .($Params[
"UseWYSIWYG"] ?
' class="ckeditor"' :
"").
'>' 418 .htmlspecialchars($Value)
420 if ($Params[
"UseWYSIWYG"])
422 $this->UsingWysiwygEditor = TRUE;
426 case self::FTYPE_FLAG:
427 if (array_key_exists(
"OnLabel", $Params)
428 && array_key_exists(
"OffLabel", $Params))
430 print(
'<input type="radio" id="'.$FieldName.
'On" name="' 431 .$FieldName.
'" value="1"' 432 .($Value ?
' checked' :
'')
433 .($Params[
"ReadOnly"] ?
' disabled' :
'')
434 .
' /> <label for="'.$FieldName.
'On">'.$Params[
"OnLabel"]
436 print(
'<input type="radio" id="'.$FieldName.
'Off" name="' 437 .$FieldName.
'" value="0"' 438 .($Value ?
'' :
' checked')
439 .($Params[
"ReadOnly"] ?
' disabled' :
'')
440 .
' /> <label for="'.$FieldName.
'Off">'.$Params[
"OffLabel"]
445 print(
'<input type="checkbox" id="'.$FieldName.
'" name="' 447 .($Value ?
' checked' :
'')
448 .($Params[
"ReadOnly"] ?
' disabled' :
'')
453 case self::FTYPE_OPTION:
454 if ($this->IsRadioButtonField($Name))
457 $FieldName, $Params[
"Options"], $Value);
462 $FieldName, $Params[
"Options"], $Value);
463 $OptList->MultipleAllowed($Params[
"AllowMultiple"]);
464 $OptList->Size(isset($Params[
"Rows"]) ? $Params[
"Rows"] : 1);
466 $OptList->Disabled($Params[
"ReadOnly"]);
467 $OptList->PrintHtml();
470 case self::FTYPE_METADATAFIELD:
471 $FieldTypes = GetArrayValue($Params,
"FieldTypes");
472 $SchemaId = GetArrayValue($Params,
"SchemaId",
475 print $Schema->GetFieldsAsOptionList(
476 $FieldName, $FieldTypes, $Value,
477 !$Params[
"AllowMultiple"] && !$Params[
"Required"],
478 NULL, $Params[
"AllowMultiple"], $Params[
"ReadOnly"]);
481 case self::FTYPE_PRIVILEGES:
482 # (convert legacy previously-stored values if necessary) 483 if (is_array($Value))
486 $PrivSet->AddPrivilege($Value);
490 $Schemas = GetArrayValue($Params,
"Schemas");
491 $MFields = GetArrayValue($Params,
"MetadataFields", array());
493 $PEditor->DisplaySet($FieldName, $Value);
496 case self::FTYPE_SEARCHPARAMS:
498 $SPEditor->DisplayAsTable();
501 case self::FTYPE_IMAGE:
506 if (isset($Params[
"Units"]))
509 print $Params[
"Units"];
522 # normalize incoming value 523 $Images = is_array($Value) ? $Value
524 : (($Value === NULL) ? array() : array($Value));
527 print
'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
529 # for each incoming value 530 $ImagesDisplayed = 0;
531 $InsertButtonHtml =
"";
532 foreach ($Images as $Image)
534 # skip if image is a placeholder to indicate no images for field 535 if ($Image == self::NO_VALUE_FOR_FIELD)
540 # load up image object if ID supplied 541 if (is_numeric($Image))
546 # skip image if it has been deleted 552 # load various image attributes for use in HTML 553 $ImageUrl = defaulthtmlentities($Image->ThumbnailUrl());
554 $ImageId = $Image->Id();
555 $ImageAltTextFieldName = $FieldName.
"_AltText_".$ImageId;
556 $ImageAltText = defaulthtmlentities(
557 isset($_POST[$ImageAltTextFieldName])
558 ? $_POST[$ImageAltTextFieldName]
559 : $Image->AltText());
563 # build up HTML for any insert buttons 564 if (isset($Params[
"InsertIntoField"]))
567 $InsertRightCommand = defaulthtmlentities(
568 "CKEDITOR.instances['".$InsertField
570 .
"'<img src=\"".$Image->PreviewUrl().
"\" alt=\"" 571 .htmlspecialchars($Image->AltText())
572 .
"\" class=\"cw-formui-image-right\" />');");
573 $InsertLeftCommand = defaulthtmlentities(
574 "CKEDITOR.instances['".$InsertField
576 .
"'<img src=\"".$Image->PreviewUrl().
"\" alt=\"" 577 .htmlspecialchars($Image->AltText())
578 .
"\" class=\"cw-formui-image-left\" />');");
579 $InsertButtonHtml =
'<button type="button" onclick="' 580 .$InsertLeftCommand.
'">Insert-L</button>' 581 .
'<button type="button" onclick="' 582 .$InsertRightCommand.
'">Insert-R</button>';
585 # add table row for image 587 <td><img src=
"<?= $ImageUrl ?>"></td>
588 <td style=
"white-space: nowrap;"><label
for=
"<?= 589 $ImageAltTextFieldName ?>" class=
"cw-form-pseudolabel">
590 Alt Text:</label><input type=
"text" size=
"20" 591 maxlength=
"120" name=
"<?= $ImageAltTextFieldName ?>" 592 value=
"<?= $ImageAltText ?>" 593 placeholder=
" (alternate text for image)"></td>
594 <td><?= $InsertButtonHtml ?><input type=
"submit" name=
"Submit" 595 onclick=
"$('#<?= $DeleteFieldName ?>').val('<?= $ImageId 596 ?>');" value=
"Delete"></td>
600 # add image ID to hidden fields 601 $this->HiddenFields[$FieldName.
"_ID"][] = $Image->Id();
603 # add container to hold ID of any image to be deleted 604 if (!isset($this->HiddenFields[$DeleteFieldName]))
606 $this->HiddenFields[$DeleteFieldName] =
"";
610 # if no images were displayed and an image entry was skipped 611 if (($ImagesDisplayed == 0) && count($Images))
613 # add marker to indicate no images to hidden fields 614 $this->HiddenFields[$FieldName.
"_ID"][] = self::NO_VALUE_FOR_FIELD;
617 # add table row for new image upload 618 if ($Params[
"AllowMultiple"] || ($ImagesDisplayed == 0))
620 $ImageAltTextFieldName = $FieldName.
"_AltText_NEW";
622 <td><input type=
"file" name=
"<?= $FieldName ?>" /></td>
623 <td style=
"white-space: nowrap;"><label
for=
"<?= 624 $ImageAltTextFieldName ?>" class=
"cw-form-pseudolabel">
625 Alt Text:</label><input type=
"text" size=
"20" 626 maxlength=
"120" name=
"<?= $ImageAltTextFieldName ?>" 627 placeholder=
" (alternate text for image)"></td>
628 <td><input type=
"submit" name=
"Submit" value=
"Upload" /></td>
642 # for each form field 643 foreach ($this->FieldParams as $ToggledField => $Params)
645 # if field has togglers (other fields that can toggle this field) 646 if (isset($Params[
"DisplayIf"]))
649 foreach ($Params[
"DisplayIf"] as $Toggler => $ToggleValues)
651 # add field to list of fields toggled by this toggler 652 $FieldsToggled[$Toggler][] = $ToggledField;
654 # add values to list of values that toggle this field 655 if (!is_array($ToggleValues))
656 { $ToggleValues = array($ToggleValues); }
657 $FieldToggleValues[$ToggledField][$Toggler] = $ToggleValues;
662 # if there were fields that toggle other fields 663 if (isset($FieldsToggled))
665 # start JavaScript code 667 <script type=
"text/javascript">
672 foreach ($FieldsToggled as $Toggler => $ToggledFields)
674 # begin function called when toggler changes 677 $(
"[id^=<?= $TogglerFFName ?>]").change(
function(){
680 # for each togglee (field being toggled) 681 foreach ($ToggledFields as $ToggledField)
683 # get JavaScript condition for this togglee 684 $ConditionJS = $this->GetFieldToggleConditionJS(
685 $FieldToggleValues[$ToggledField]);
687 # add toggle code for togglee 690 $(
"#row-<?= $ToggledFieldFFName ?>")[<?=
691 $ConditionJS ?> ?
"show" :
"hide"]();
695 # end function for field changing 701 # end JavaScript code 715 private function GetFieldToggleConditionJS($ToggleValues)
718 foreach ($ToggleValues as $Toggler => $ToggleValues)
720 # start with fresh subcondition list 721 $SubConditions = array();
723 # for each toggle value 725 foreach ($ToggleValues as $Value)
727 # build subcondition for value 728 if ($this->FieldParams[$Toggler][
"Type"] == self::FTYPE_FLAG)
732 $SubConditions[] =
"($(\"input[name=".$TogglerFFName
733 .
"]\").is(\":checked:visible\"))";
737 $SubConditions[] =
"(!$(\"input[name=".$TogglerFFName
738 .
"]\").is(\":checked:visible\"))";
743 if ($this->IsRadioButtonField($Toggler))
745 $SubConditions[] =
"($(\"input[name=".$TogglerFFName
746 .
"]:checked\").val() == \"".$Value.
"\")";
750 $SubConditions[] =
"($(\"#".$TogglerFFName
751 .
"\").val() == \"".$Value.
"\")";
756 # assemble subconditions into condition 757 if (count($SubConditions) > 1)
759 $SubConditionStrings[] =
"(".implode(
" || ", $SubConditions).
")";
763 $SubConditionStrings[] = $SubConditions[0];
767 # assemble conditions into condition string 768 $ConditionString = implode(
" && ", $SubConditionStrings);
770 return $ConditionString;
778 private function IsRadioButtonField($FieldName)
780 $Params = $this->FieldParams[$FieldName];
781 if ($Params[
"Type"] == self::FTYPE_OPTION)
783 if (isset($Params[
"RadioButtons"]))
785 return $Params[
"RadioButtons"] ? TRUE : FALSE;
787 elseif (isset($Params[
"AllowMultiple"]) && $Params[
"AllowMultiple"])
793 return (count($Params[
"Options"])
794 <= 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.
CWIS-specific user class.
Convenience class for generating an HTML select/option form element.
Class to create a user interface for editing SearchParameterSets.