CWIS Developer Documentation
FormUI.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: FormUI.php
4 #
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/
8 #
9 
134 class FormUI extends FormUI_Base
135 {
136 
137  # ---- PUBLIC INTERFACE --------------------------------------------------
138 
145  public function DisplayFormTable($TableId = NULL, $TableStyle = NULL,
146  $TableCssClass = NULL)
147  {
148  # display nothing if there are no fields
149  if (!count($this->FieldParams)) { return; }
150 
151  # check whether table should be split into sections
152  $TableIsSectioned = FALSE;
153  foreach ($this->FieldParams as $Name => $Params)
154  {
155  if ($Params["Type"] == self::FTYPE_HEADING)
156  { $TableIsSectioned = TRUE; }
157  }
158 
159  # begin table
160  // @codingStandardsIgnoreStart
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."\""); }
167  ?>>
168  <tbody><?PHP
169  // @codingStandardsIgnoreEnd
170 
171  # for each field
172  foreach ($this->FieldParams as $Name => $Params)
173  {
174  # generate name for field
175  $FormFieldName = $this->GetFormFieldName($Name);
176 
177  # if field is actually a section heading
178  if ($Params["Type"] == self::FTYPE_HEADING)
179  {
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;
186  }
187  else
188  {
189  # determine if row may have taller content
190  $ShortRowFieldTypes = array(
191  self::FTYPE_FLAG,
192  self::FTYPE_METADATAFIELD,
193  self::FTYPE_NUMBER,
194  self::FTYPE_PASSWORD,
195  self::FTYPE_TEXT,
196  self::FTYPE_URL,
197  self::FTYPE_USER,
198  );
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)));
204 
205  # load up value(s) to go into field
206  $Value = $this->GetFieldValue($Name);
207 
208  # set up CSS classes for table row
209  $RowClass = "cw-formui-fieldtype-".strtolower($Params["Type"]);
210  if ($Params["Type"] == "MetadataField")
211  {
212  $RowClass .= " cw-formui-schemaid-"
213  .GetArrayValue($Params, "SchemaId",
215  }
216  $RowClass .= $IsTallRow ? " cw-content-tallrow" : "";
217  $RowClassAttrib = ' class="'.$RowClass.'"';
218 
219  # set up CSS classes for row header cell
220  $HeaderClass = $IsTallRow ? "cw-content-tallrow-th" : "";
221  $HeaderClassAttrib = strlen($HeaderClass)
222  ? ' class="'.$HeaderClass.'"' : "";
223 
224  # set up CSS classes for row label
225  $LabelClass = "cw-form-pseudolabel"
226  .(isset(self::$ErrorMessages[$Name])
227  ? " cw-form-error" : "");
228 
229  # set up min/max note if applicable
230  unset($RangeNotePieces);
231  if (isset($Params["MinVal"]))
232  {
233  $RangeNotePieces[] = "Minimum: <i>".$Params["MinVal"]."</i>";
234  }
235  if (isset($Params["MaxVal"]))
236  {
237  $RangeNotePieces[] = "Maximum: <i>".$Params["MaxVal"]."</i>";
238  }
239  if (isset($Params["RecVal"]))
240  {
241  $RangeNotePieces[] = "Recommended: <i>".$Params["RecVal"]."</i>";
242  }
243  if (isset($RangeNotePieces))
244  {
245  $RangeNote = "(".implode(", ", $RangeNotePieces).")";
246  }
247 
248  // @codingStandardsIgnoreStart
249  ?>
250  <tr<?= ($IsTallRow ? " valign=\"top\"" : "").$RowClassAttrib
251  ?> id="row-<?= $FormFieldName ?>">
252  <th<?= $HeaderClassAttrib ?>>
253  <label for="<?= $FormFieldName
254  ?>" class="<?= $LabelClass ?>"><?=
255  $Params["Label"] ?></label>
256  </th>
257  <td <?PHP if (!isset($Params["Help"]) && !isset($RangeNotePieces)) {
258  print "colspan=\"2\""; } ?>><?PHP
259  $this->DisplayFormField(
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>
265  <?PHP } ?>
266  </tr>
267  <?PHP
268  }
269  }
270 
271  # end table
272  ?></tbody>
273  </table><?PHP
274 
275  # add any hidden form fields
276  print $this->GetHiddenFieldsHtml();
277 
278  # add any needed JavaScript for toggled fields
280 
281  # pull in WYSIWYG editor setup if needed
282  if ($this->UsingWysiwygEditor)
283  {
284  require_once($GLOBALS["AF"]->GUIFile("CKEditorSetup.php"));
285  }
286  }
287  // @codingStandardsIgnoreEnd
288 
292  public static function DisplayErrorBlock()
293  {
294  if (count(self::$ErrorMessages))
295  {
296  print "<ul class=\"cw-form-error\">\n";
297  $DisplayedMsgs = array();
298  foreach (self::$ErrorMessages as $Field => $Msgs)
299  {
300  foreach ($Msgs as $Msg)
301  {
302  if (!in_array($Msg, $DisplayedMsgs))
303  {
304  print "<li>".$Msg."</li>\n";
305  $DisplayedMsgs[] = $Msg;
306  }
307  }
308  }
309  print "</ul>\n";
310  }
311  }
312 
317  public function HandleDeletes()
318  {
319  parent::HandleDeletes();
320 
321  $TextFieldsToCheck = array();
322 
323  # check for text fields that may contain images
324  foreach ($this->FieldParams as $Name => $Params)
325  {
326  if (isset($Params["InsertIntoField"])
327  && (($Params["Type"] == self::FTYPE_FILE)
328  || ($Params["Type"] == self::FTYPE_IMAGE)))
329  {
330  $TextFieldsToCheck[] = $Params["InsertIntoField"];
331  }
332  }
333 
334  # load images to check
335  foreach ($this->DeletedImages as $ImageId)
336  {
337  $Images[$ImageId] = new SPTImage($ImageId);
338  }
339 
340  # load files to check
341  foreach ($this->DeletedFiles as $FileId)
342  {
343  $Files[$FileId] = new File($FileId);
344  }
345 
346  # for each text field potentially containing references to deleted items
347  foreach ($TextFieldsToCheck as $FieldName)
348  {
349  # get HTML form field name for field
350  $FormFieldName = $this->GetFormFieldName($FieldName);
351 
352  # for each deleted image
353  foreach ($this->DeletedImages as $ImageId)
354  {
355  # strip out any tags referencing that image from field content
356  $_POST[$FormFieldName] = preg_replace(
357  "%<img [^>]*src=\""
358  .$Images[$ImageId]->PreviewUrl()."\"[^>]*>%",
359  "",
360  $this->GetFieldValue($FieldName));
361  }
362 
363  # for each deleted file
364  foreach ($this->DeletedFiles as $FileId)
365  {
366  # strip out any tags we inserted that reference that file
367  $FileLink = $Files[$FileId]->GetLink();
368  $_POST[$FormFieldName] = preg_replace(
369  "%<a [^>]*href=\""
370  .preg_quote(htmlspecialchars($FileLink), '%')
371  ."\"[^>]*>(.*?)</a>%",
372  "\1",
373  $this->GetFieldValue($FieldName));
374  }
375  }
376  }
377 
378 
379 
380  # ---- PRIVATE INTERFACE -------------------------------------------------
381 
382  protected $UsingWysiwygEditor = FALSE;
383 
389 
396  protected function DisplayFormField($Name, $Value, $Params)
397  {
398  $FieldName = $this->GetFormFieldName($Name,
399  ($Params["Type"] != self::FTYPE_PRIVILEGES));
400 
401  switch ($Params["Type"])
402  {
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)
409  {
410  if (is_numeric($Value))
411  {
412  $User = new CWUser($Value);
413  $Value = $User->Name();
414  }
415  }
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))
421  : $DefaultSize);
422  $MaxLen = isset($Params["MaxLength"]) ? $Params["MaxLength"]
423  : (isset($Params["MaxVal"])
424  ? (strlen(intval($Params["MaxVal"]) + 3))
425  : $DefaultMaxLen);
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" : "").' />');
436  break;
437 
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)
446  .'</textarea>');
447  if ($Params["UseWYSIWYG"])
448  {
449  $this->UsingWysiwygEditor = TRUE;
450  }
451  break;
452 
453  case self::FTYPE_FLAG:
454  if (array_key_exists("OnLabel", $Params)
455  && array_key_exists("OffLabel", $Params))
456  {
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"]
462  ."</label>\n");
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"]
468  ."</label>\n");
469  }
470  else
471  {
472  print('<input type="checkbox" id="'.$FieldName.'" name="'
473  .$FieldName.'" '
474  .($Value ? ' checked' : '')
475  .($Params["ReadOnly"] ? ' disabled' : '')
476  ." />\n");
477  }
478  break;
479 
480  case self::FTYPE_OPTION:
481  if ($this->IsRadioButtonField($Name))
482  {
483  $OptList = new HtmlRadioButtonSet(
484  $FieldName, $Params["Options"], $Value);
485  }
486  else
487  {
488  $OptList = new HtmlOptionList(
489  $FieldName, $Params["Options"], $Value);
490  $OptList->MultipleAllowed($Params["AllowMultiple"]);
491  $OptList->Size(isset($Params["Rows"]) ? $Params["Rows"] : 1);
492  }
493  $OptList->Disabled($Params["ReadOnly"]);
494  $OptList->PrintHtml();
495  break;
496 
497  case self::FTYPE_METADATAFIELD:
498  $FieldTypes = GetArrayValue($Params, "FieldTypes");
499  $SchemaId = GetArrayValue($Params, "SchemaId",
501  $Schema = new MetadataSchema($SchemaId);
502  print $Schema->GetFieldsAsOptionList(
503  $FieldName, $FieldTypes, $Value,
504  !$Params["AllowMultiple"] && !$Params["Required"],
505  NULL, $Params["AllowMultiple"], $Params["ReadOnly"]);
506  break;
507 
508  case self::FTYPE_PRIVILEGES:
509  # (convert legacy previously-stored values if necessary)
510  if (is_array($Value))
511  {
512  $PrivSet = new PrivilegeSet();
513  $PrivSet->AddPrivilege($Value);
514  $Value = $PrivSet;
515  }
516 
517  $Schemas = GetArrayValue($Params, "Schemas");
518  $MFields = GetArrayValue($Params, "MetadataFields", array());
519  $PEditor = new PrivilegeEditingUI($Schemas, $MFields);
520  $PEditor->DisplaySet($FieldName, $Value);
521  break;
522 
523  case self::FTYPE_SEARCHPARAMS:
524  $SPEditor = new SearchParameterSetEditingUI($FieldName, $Value);
525 
526  if (isset($Params["MaxFieldLabelLength"]))
527  {
528  $SPEditor->MaxFieldLabelLength($Params["MaxFieldLabelLength"]);
529  }
530  if (isset($Params["MaxValueLabelLength"]))
531  {
532  $SPEditor->MaxValueLabelLength($Params["MaxValueLabelLength"]);
533  }
534 
535  $SPEditor->DisplayAsTable();
536  break;
537 
538  case self::FTYPE_FILE:
539  $this->DisplayFileField($FieldName, $Value, $Params);
540  break;
541 
542  case self::FTYPE_IMAGE:
543  $this->DisplayImageField($FieldName, $Value, $Params);
544  break;
545  }
546 
547  if (isset($Params["Units"]))
548  {
549  ?>&nbsp;<span><?PHP
550  print $Params["Units"];
551  ?></span><?PHP
552  }
553  }
554 
561  protected function DisplayImageField($FieldName, $Value, $Params)
562  {
563  # normalize incoming value
564  $Images = is_array($Value) ? $Value
565  : (($Value === NULL) ? array() : array($Value));
566 
567  # begin value table
568  print '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
569 
570  # for each incoming value
571  $ImagesDisplayed = 0;
572  $InsertButtonHtml = "";
573  foreach ($Images as $Image)
574  {
575  # skip if image is a placeholder to indicate no images for field
576  if ($Image == self::NO_VALUE_FOR_FIELD)
577  {
578  continue;
579  }
580 
581  # load up image object if ID supplied
582  if (is_numeric($Image))
583  {
584  $Image = new SPTImage($Image);
585  }
586 
587  # skip image if it has been deleted
588  if (in_array($Image->Id(), $this->DeletedImages))
589  {
590  continue;
591  }
592 
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());
601 
602  $DeleteFieldName = $this->GetFormFieldName("ImageToDelete");
603 
604  # build up HTML for any insert buttons
605  if (isset($Params["InsertIntoField"]))
606  {
607  $InsertField = $this->GetFormFieldName($Params["InsertIntoField"]);
608  $InsertRightCommand = defaulthtmlentities(
609  "CKEDITOR.instances['".$InsertField
610  ."'].insertHtml("
611  ."'<img src=\"".$Image->PreviewUrl()."\" alt=\""
612  .htmlspecialchars($Image->AltText())
613  ."\" class=\"cw-formui-image-right\" />');");
614  $InsertLeftCommand = defaulthtmlentities(
615  "CKEDITOR.instances['".$InsertField
616  ."'].insertHtml("
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>';
624  }
625 
626  # add table row for image
627  ?><tr>
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>
638  </tr><?PHP
639  $ImagesDisplayed++;
640 
641  # add image ID to hidden fields
642  $this->HiddenFields[$FieldName."_ID"][] = $Image->Id();
643 
644  # add container to hold ID of any image to be deleted
645  if (!isset($this->HiddenFields[$DeleteFieldName]))
646  {
647  $this->HiddenFields[$DeleteFieldName] = "";
648  }
649  }
650 
651  # if no images were displayed and an image entry was skipped
652  if (($ImagesDisplayed == 0) && count($Images))
653  {
654  # add marker to indicate no images to hidden fields
655  $this->HiddenFields[$FieldName."_ID"][] = self::NO_VALUE_FOR_FIELD;
656  }
657 
658  # add table row for new image upload
659  if ($Params["AllowMultiple"] || ($ImagesDisplayed == 0))
660  {
661  $ImageAltTextFieldName = $FieldName."_AltText_NEW";
662  ?><tr>
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>
670  </tr><?PHP
671  }
672 
673  # end value table
674  print '</table>';
675  }
676 
683  protected function DisplayFileField($FieldName, $Value, $Params)
684  {
685  # normalize incoming value
686  $Files = is_array($Value) ? $Value
687  : (($Value === NULL) ? array() : array($Value));
688 
689  # begin value table
690  print '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
691 
692  # for each incoming value
693  $FilesDisplayed = 0;
694  $InsertButtonHtml = "";
695  foreach ($Files as $File)
696  {
697  # skip if file is a placeholder to indicate no files for field
698  if ($File == self::NO_VALUE_FOR_FIELD)
699  {
700  continue;
701  }
702 
703  # load up file object if ID supplied
704  if (is_numeric($File))
705  {
706  $File = new File($File);
707  }
708 
709  # skip file if it has been deleted
710  if (in_array($File->Id(), $this->DeletedFiles))
711  {
712  continue;
713  }
714 
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>";
721  $DeleteFieldName = $this->GetFormFieldName("FileToDelete");
722 
723  # build up HTML for any insert buttons
724  if (isset($Params["InsertIntoField"]))
725  {
726  $InsertField = $this->GetFormFieldName($Params["InsertIntoField"]);
727  $InsertCommand = defaulthtmlentities(
728  "CKEDITOR.instances['".$InsertField
729  ."'].insertHtml('".$FileLinkTag."');");
730  $InsertButtonHtml = '<button type="button" onclick="'
731  .$InsertCommand.'">Insert</button>';
732  }
733 
734  # add table row for file
735  ?><tr>
736  <td><?= $FileLinkTag ?></td>
737  <td><?= $InsertButtonHtml ?><input type="submit" name="Submit"
738  onclick="$('#<?= $DeleteFieldName ?>').val('<?= $FileId
739  ?>');" value="Delete"></td>
740  </tr><?PHP
741  $FilesDisplayed++;
742 
743  # add file ID to hidden fields
744  $this->HiddenFields[$FieldName."_ID"][] = $FileId;
745 
746  # add container to hold ID of any file to be deleted
747  if (!isset($this->HiddenFields[$DeleteFieldName]))
748  {
749  $this->HiddenFields[$DeleteFieldName] = "";
750  }
751  }
752 
753  # if no files were displayed and a file entry was skipped
754  if (($FilesDisplayed == 0) && count($Files))
755  {
756  # add marker to indicate no files to hidden fields
757  $this->HiddenFields[$FieldName."_ID"][] = self::NO_VALUE_FOR_FIELD;
758  }
759 
760  # add table row for new file upload
761  if ($Params["AllowMultiple"] || ($FilesDisplayed == 0))
762  {
763  ?><tr>
764  <td><input type="file" name="<?= $FieldName ?>" /></td>
765  <td><input type="submit" name="Submit" value="Upload" /></td>
766  </tr><?PHP
767  }
768 
769  # end value table
770  print '</table>';
771  }
772 
777  protected function PrintFieldHidingJavascript()
778  {
779  # for each form field
780  foreach ($this->FieldParams as $ToggledField => $Params)
781  {
782  # if field has togglers (other fields that can toggle this field)
783  if (isset($Params["DisplayIf"]))
784  {
785  # for each toggler
786  foreach ($Params["DisplayIf"] as $Toggler => $ToggleValues)
787  {
788  # add field to list of fields toggled by this toggler
789  $FieldsToggled[$Toggler][] = $ToggledField;
790 
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;
795  }
796  }
797  }
798 
799  # if there were fields that toggle other fields
800  if (isset($FieldsToggled))
801  {
802  # start JavaScript code
803  ?>
804  <script type="text/javascript">
805  (function($){
806  <?PHP
807 
808  # for each toggler
809  foreach ($FieldsToggled as $Toggler => $ToggledFields)
810  {
811  # begin function called when toggler changes
812  $TogglerFFName = $this->GetFormFieldName($Toggler);
813  ?>
814  $("[id^=<?= $TogglerFFName ?>]").change(function(){
815  <?PHP
816 
817  # for each togglee (field being toggled)
818  foreach ($ToggledFields as $ToggledField)
819  {
820  # get JavaScript condition for this togglee
821  $ConditionJS = $this->GetFieldToggleConditionJS(
822  $FieldToggleValues[$ToggledField]);
823 
824  # add toggle code for togglee
825  $ToggledFieldFFName = $this->GetFormFieldName($ToggledField);
826  ?>
827  $("#row-<?= $ToggledFieldFFName ?>")[<?=
828  $ConditionJS ?> ? "show" : "hide"]();
829  <?PHP
830  }
831 
832  # end function for field changing
833  ?>
834  }).change();
835  <?PHP
836  }
837 
838  # end JavaScript code
839  ?>
840  }(jQuery));
841  </script>
842  <?PHP
843  }
844  }
845 
852  private function GetFieldToggleConditionJS($ToggleValues)
853  {
854  # for each toggler
855  foreach ($ToggleValues as $Toggler => $ToggleValues)
856  {
857  # start with fresh subcondition list
858  $SubConditions = array();
859 
860  # for each toggle value
861  $TogglerFFName = $this->GetFormFieldName($Toggler);
862  foreach ($ToggleValues as $Value)
863  {
864  # build subcondition for value
865  if ($this->FieldParams[$Toggler]["Type"] == self::FTYPE_FLAG)
866  {
867  if ($Value)
868  {
869  $SubConditions[] = "($(\"input[name=".$TogglerFFName
870  ."]\").is(\":checked:visible\"))";
871  }
872  else
873  {
874  $SubConditions[] = "(!$(\"input[name=".$TogglerFFName
875  ."]\").is(\":checked:visible\"))";
876  }
877  }
878  else
879  {
880  if ($this->IsRadioButtonField($Toggler))
881  {
882  $SubConditions[] = "($(\"input[name=".$TogglerFFName
883  ."]:checked\").val() == \"".$Value."\")";
884  }
885  else
886  {
887  $SubConditions[] = "($(\"#".$TogglerFFName
888  ."\").val() == \"".$Value."\")";
889  }
890  }
891  }
892 
893  # assemble subconditions into condition
894  if (count($SubConditions) > 1)
895  {
896  $SubConditionStrings[] = "(".implode(" || ", $SubConditions).")";
897  }
898  else
899  {
900  $SubConditionStrings[] = $SubConditions[0];
901  }
902  }
903 
904  # assemble conditions into condition string
905  $ConditionString = implode(" && ", $SubConditionStrings);
906 
907  return $ConditionString;
908  }
909 
915  private function IsRadioButtonField($FieldName)
916  {
917  $Params = $this->FieldParams[$FieldName];
918  if ($Params["Type"] == self::FTYPE_OPTION)
919  {
920  if (isset($Params["RadioButtons"]))
921  {
922  return $Params["RadioButtons"] ? TRUE : FALSE;
923  }
924  elseif (isset($Params["AllowMultiple"]) && $Params["AllowMultiple"])
925  {
926  return FALSE;
927  }
928  else
929  {
930  return (count($Params["Options"])
931  <= self::OPTION_RADIO_BUTTON_THRESHOLD) ? TRUE : FALSE;
932  }
933  }
934  else
935  {
936  return FALSE;
937  }
938  }
939 }
PrintFieldHidingJavascript()
Print any JavaScript required to support toggling display of fields or sections.
Definition: FormUI.php:777
Base class (covering non-presentation elements) supplying a standard user interface for presenting an...
Definition: FormUI_Base.php:14
Metadata schema (in effect a Factory class for MetadataField).
GetHiddenFieldsHtml()
Get HTML for hidden form fields associated with form processing.
DisplayFormField($Name, $Value, $Params)
Display HTML form field for specified field.
Definition: FormUI.php:396
User interface element for editing PrivilegeSets.
Set of privileges used to access resource information or other parts of the system.
Child class (covering presentation elements only) supplying a standard user interface for presenting ...
Definition: FormUI.php:134
DisplayImageField($FieldName, $Value, $Params)
Display image form field for specified field.
Definition: FormUI.php:561
Convenience class for generating a set of HTML radio button form elements.
Encapsulates a full-size, preview, and thumbnail image.
Definition: SPTImage.php:13
HandleDeletes()
Handle image deletion, removing deleted images from text fields where they may have been inserted...
Definition: FormUI.php:317
const OPTION_RADIO_BUTTON_THRESHOLD
FTYPE_OPTION fields with this many or fewer options will display as radio buttons by default...
Definition: FormUI.php:388
static DisplayErrorBlock()
Display HTML block with error messages (if any).
Definition: FormUI.php:292
GetFormFieldName($FieldName, $IncludePrefix=TRUE)
Get HTML form field name for specified field.
DisplayFileField($FieldName, $Value, $Params)
Display file form field for specified field.
Definition: FormUI.php:683
GetFieldValue($FieldName)
Get value for form field.
$UsingWysiwygEditor
Definition: FormUI.php:382
Class representing a stored (usually uploaded) file.
Definition: File.php:13
DisplayFormTable($TableId=NULL, $TableStyle=NULL, $TableCssClass=NULL)
Display HTML table for form.
Definition: FormUI.php:145
CWIS-specific user class.
Definition: CWUser.php:13
Convenience class for generating an HTML select/option form element.
Class to create a user interface for editing SearchParameterSets.