CWIS Developer Documentation
FormUI_Base.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: FormUI_Base.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2016 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9 
14 abstract class FormUI_Base
15 {
16  # ---- PUBLIC INTERFACE --------------------------------------------------
17 
19  const FTYPE_FLAG = "Flag";
20  const FTYPE_IMAGE = "Image";
21  const FTYPE_METADATAFIELD = "MetadataField";
22  const FTYPE_NUMBER = "Number";
23  const FTYPE_OPTION = "Option";
24  const FTYPE_PARAGRAPH = "Paragraph";
25  const FTYPE_PASSWORD = "Password";
26  const FTYPE_PRIVILEGES = "Privileges";
27  const FTYPE_SEARCHPARAMS = "Search Parameters";
28  const FTYPE_TEXT = "Text";
29  const FTYPE_URL = "URL";
30  const FTYPE_USER = "User";
32  const FTYPE_HEADING = "Heading";
33 
44  public function __construct(
45  $FieldParams, $FieldValues = array(), $UniqueKey = NULL)
46  {
47  # make sure parameters are legal and complete
48  $BooleanParams = array(
49  "AllowMultiple",
50  "ReadOnly",
51  "Required",
52  "UseWYSIWYG",
53  );
54  foreach ($FieldParams as $FieldName => $Params)
55  {
56  if (!isset($Params["Type"]))
57  {
58  $ErrMsgs[] = "Type missing for form field ".$FieldName.".";
59  }
60  elseif (($Params["Type"] == self::FTYPE_OPTION)
61  && !isset($Params["Options"]))
62  {
63  $ErrMsgs[] = "Option values missing for form field ".$FieldName.".";
64  }
65  if (!isset($Params["Label"]))
66  {
67  $ErrMsgs[] = "Label missing for form field ".$FieldName.".";
68  }
69  if (isset($Params["ValidateFunction"])
70  && !is_callable($Params["ValidateFunction"]))
71  {
72  $ErrMsgs[] = "Uncallable validation function for form field "
73  .$FieldName.".";
74  }
75  if (isset($Params["InsertIntoField"])
76  && !isset($FieldParams[$Params["InsertIntoField"]]))
77  {
78  $ErrMsgs[] = "Unknown insertion field (".$Params["InsertIntoField"]
79  .") found for form field ".$FieldName.".";
80  }
81  foreach ($BooleanParams as $ParamName)
82  {
83  if (!isset($Params[$ParamName]))
84  {
85  $FieldParams[$FieldName][$ParamName] = FALSE;
86  }
87  }
88  }
89  if (isset($ErrMsgs))
90  {
91  $ErrMsgString = implode(" ", $ErrMsgs);
92  throw new InvalidArgumentException($ErrMsgString);
93  }
94 
95  # save form parameters and values
96  $this->FieldParams = $FieldParams;
97  $this->FieldValues = $FieldValues;
98  $this->UniqueKey = $UniqueKey;
99  }
100 
106  abstract public function DisplayFormTable($TableId = NULL, $TableStyle = NULL);
107 
114  public static function LogError($Msg, $Field = NULL)
115  {
116  self::$ErrorMessages[$Field][] = $Msg;
117  }
118 
125  public static function GetLoggedErrors()
126  {
127  return self::$ErrorMessages;
128  }
129 
136  public static function ErrorsLogged($Field = FALSE)
137  {
138  if ($Field === FALSE)
139  {
140  return count(self::$ErrorMessages) ? TRUE : FALSE;
141  }
142  else
143  {
144  return isset(self::$ErrorMessages[$Field]) ? TRUE : FALSE;
145  }
146  }
147 
152  public static function ClearLoggedErrors($Field = FALSE)
153  {
154  if ($Field === FALSE)
155  {
156  self::$ErrorMessages = array();
157  }
158  else
159  {
160  unset(self::$ErrorMessages[$Field]);
161  }
162  }
163 
171  public function ValidateFieldInput()
172  {
173  # retrieve field values
174  $Values = $this->GetNewValuesFromForm();
175 
176  # for each field
177  $ErrorsFound = 0;
178  foreach ($this->FieldParams as $Name => $Params)
179  {
180  # skip header fields
181  if ($Params["Type"] == self::FTYPE_HEADING) { continue; }
182 
183  # determine if field has a value set
184  switch ($Params["Type"])
185  {
186  case self::FTYPE_SEARCHPARAMS:
187  $IsEmpty = !$Values[$Name]->ParameterCount();
188  break;
189 
190  case self::FTYPE_PRIVILEGES:
191  $IsEmpty = !$Values[$Name]->ComparisonCount();
192  break;
193 
194  default:
195  if (is_array($Values[$Name]))
196  {
197  $IsEmpty = !count($Values[$Name]);
198  }
199  else
200  {
201  $IsEmpty = !strlen(trim($Values[$Name]));
202  }
203  break;
204  }
205 
206  # if field has validation function
207  if (isset($Params["ValidateFunction"]))
208  {
209  # swap in our object if this is one of our methods
210  $VFunc = $Params["ValidateFunction"];
211  if (is_array($VFunc) && ($VFunc[0] == "FormUI"))
212  {
213  $VFunc[0] = $this;
214  }
215 
216  # call validation function for value
217  $Args = array_merge(array($Name, $Values[$Name], $Values),
218  $this->ExtraValidationParams);
219  $ErrMsg = call_user_func_array($VFunc, $Args);
220  if ($ErrMsg === FALSE)
221  {
222  throw new Exception("Calling validation function for"
223  ." parameter \"".$Name."\" failed.");
224  }
225 
226  # log any resulting error
227  if ($ErrMsg !== NULL)
228  {
229  self::LogError($ErrMsg, $Name);
230  $ErrorsFound++;
231  }
232  }
233 
234  # if field is required and empty
235  if ($IsEmpty && isset($Params["Required"]) && $Params["Required"])
236  {
237  # log error to indicate required value is missing
238  self::LogError("<i>".$Params["Label"]."</i> is required.", $Name);
239  $ErrorsFound++;
240  }
241  # else validate based on field type
242  else
243  {
244  switch ($Params["Type"])
245  {
246  case self::FTYPE_NUMBER:
247  # make sure value is within any specified range
248  if ((isset($Params["MinVal"])
249  && ($Values[$Name] < $Params["MinVal"]))
250  || (isset($Params["MaxVal"])
251  && ($Values[$Name] > $Params["MaxVal"])))
252  {
253  if (!isset($Params["MaxVal"]))
254  {
255  self::LogError("<i>".$Params["Label"]."</i> must be "
256  .$Params["MinVal"]." or greater.", $Name);
257  }
258  elseif (!isset($Params["MinVal"]))
259  {
260  self::LogError("<i>".$Params["Label"]."</i> must be "
261  .$Params["MaxVal"]." or less.", $Name);
262  }
263  else
264  {
265  self::LogError("<i>".$Params["Label"]."</i> must be"
266  ." in the range ".$Params["MinVal"]
267  ." to ".$Params["MaxVal"].".", $Name);
268  }
269  $ErrorsFound++;
270  }
271  break;
272 
273  case self::FTYPE_URL:
274  # make sure URL entered looks valid
275  if (!$IsEmpty && (filter_var(
276  $Values[$Name], FILTER_VALIDATE_URL) === FALSE))
277  {
278  self::LogError("Value \"".$Values[$Name]
279  ."\" does not appear to be a valid URL for <i>"
280  .$Params["Label"]."</i>.", $Name);
281  $ErrorsFound++;
282  }
283  break;
284 
285  case self::FTYPE_USER:
286  # make sure user name entered is valid
287  $UFactory = new CWUserFactory();
288  if (!$UFactory->UserNameExists($Values[$Name]))
289  {
290  self::LogError("User name \"".$Values[$Name]
291  ."\" not found for <i>"
292  .$Params["Label"]."</i>.", $Name);
293  $ErrorsFound++;
294  }
295  break;
296  }
297  }
298  }
299 
300  # report number of fields with invalid values found to caller
301  return $ErrorsFound;
302  }
303 
309  public function AddValidationParameters()
310  {
311  $this->ExtraValidationParams = func_get_args();
312  }
313 
319  public function GetNewValuesFromForm()
320  {
321  # for each form field
322  $NewSettings = array();
323  foreach ($this->FieldParams as $Name => $Params)
324  {
325  # skip header fields
326  if ($Params["Type"] == self::FTYPE_HEADING) { continue; }
327 
328  # determine form field name (matches mechanism in HTML)
329  $FieldName = $this->GetFormFieldName($Name,
330  ($Params["Type"] != self::FTYPE_PRIVILEGES));
331 
332  # assume the value will not change
333  $DidValueChange = FALSE;
334  $OldValue = isset($this->FieldValues[$Name])
335  ? $this->FieldValues[$Name]
336  : (isset($Params["Value"]) ? $Params["Value"] : NULL);
337  $NewSettings[$Name] = $OldValue;
338 
339  # retrieve value based on configuration parameter type
340  switch ($Params["Type"])
341  {
342  case self::FTYPE_FLAG:
343  # if radio buttons were used
344  if (array_key_exists("OnLabel", $Params)
345  && array_key_exists("OffLabel", $Params))
346  {
347  if (isset($_POST[$FieldName]))
348  {
349  $NewValue = ($_POST[$FieldName] == "1") ? TRUE : FALSE;
350 
351  # flag that the values changed if they did
352  $DidValueChange = self::DidValueChange(
353  $OldValue, $NewValue);
354 
355  $NewSettings[$Name] = $NewValue;
356  }
357  }
358  # else checkbox was used
359  else
360  {
361  $NewValue = isset($_POST[$FieldName]) ? TRUE : FALSE;
362 
363  # flag that the values changed if they did
364  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
365 
366  $NewSettings[$Name] = $NewValue;
367  }
368  break;
369 
370  case self::FTYPE_OPTION:
371  $NewValue = GetArrayValue($_POST, $FieldName, array());
372 
373  # flag that the values changed if they did
374  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
375 
376  $NewSettings[$Name] = $NewValue;
377  break;
378 
379  case self::FTYPE_METADATAFIELD:
380  $NewValue = GetArrayValue($_POST, $FieldName, array());
381  if ($NewValue == "-1") { $NewValue = array(); }
382 
383  # flag that the values changed if they did
384  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
385 
386  $NewSettings[$Name] = $NewValue;
387  break;
388 
389  case self::FTYPE_PRIVILEGES:
390  $Schemas = GetArrayValue($Params, "Schemas");
391  $MFields = GetArrayValue($Params, "MetadataFields", array());
392  $PEditor = new PrivilegeEditingUI($Schemas, $MFields);
393  $NewValues = $PEditor->GetPrivilegeSetsFromForm();
394  $NewValue = $NewValues[$FieldName];
395  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
396  $NewSettings[$Name] = $NewValue;
397  break;
398 
399  case self::FTYPE_SEARCHPARAMS:
400  $SPEditor = new SearchParameterSetEditingUI($FieldName);
401  $NewValue = $SPEditor->GetValuesFromFormData();
402  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
403  $NewSettings[$Name] = $NewValue;
404  break;
405 
406  case self::FTYPE_IMAGE:
407  $NewSettings[$Name] = GetArrayValue(
408  $_POST, $FieldName."_ID", array());
409  foreach ($NewSettings[$Name] as $Index => $ImageId)
410  {
411  if ($ImageId == self::NO_VALUE_FOR_FIELD)
412  {
413  unset($NewSettings[$Name][$Index]);
414  }
415  if (isset($_POST[$FieldName."_AltText_".$ImageId]))
416  {
417  $Image = new SPTImage($ImageId);
418  $Image->AltText($_POST[$FieldName."_AltText_".$ImageId]);
419  }
420  }
421  break;
422 
423  default:
424  if (isset($_POST[$FieldName]))
425  {
426  $NewValue = $_POST[$FieldName];
427 
428  # flag that the values changed if they did
429  $DidValueChange = self::DidValueChange($OldValue, $NewValue);
430 
431  $NewSettings[$Name] = $NewValue;
432  }
433  break;
434  }
435 
436  # if value changed and there is an event to signal for changes
437  if ($DidValueChange && $this->SettingChangeEventName)
438  {
439  # set info about changed value in event parameters if appropriate
440  $EventParams = $this->SettingChangeEventParams;
441  foreach ($EventParams as $ParamName => $ParamValue)
442  {
443  switch ($ParamName)
444  {
445  case "SettingName":
446  $EventParams[$ParamName] = $Name;
447  break;
448 
449  case "OldValue":
450  $EventParams[$ParamName] = $OldValue;
451  break;
452 
453  case "NewValue":
454  $EventParams[$ParamName] = $NewValue;
455  break;
456  }
457  }
458 
459  # signal event
460  $GLOBALS["AF"]->SignalEvent(
461  $this->SettingChangeEventName, $EventParams);
462  }
463  }
464 
465  # return updated setting values to caller
466  return $NewSettings;
467  }
468 
474  public function GetFieldValue($FieldName)
475  {
476  # get base form field name
477  $FieldType = $this->FieldParams[$FieldName]["Type"];
478  $FormFieldName = $this->GetFormFieldName($FieldName,
479  ($FieldType != self::FTYPE_PRIVILEGES));
480 
481  # get fallback value for field (in case no value from form)
482  if (isset($this->FieldValues[$FieldName]))
483  {
484  $Value = $this->FieldValues[$FieldName];
485  }
486  elseif (isset($this->FieldParams[$FieldName]["Value"]))
487  {
488  $Value = self::LoadValue($FieldType,
489  $this->FieldParams[$FieldName]["Value"]);
490  }
491  elseif (isset($this->FieldParams[$FieldName]["Default"]))
492  {
493  $Value = self::LoadValue($FieldType,
494  $this->FieldParams[$FieldName]["Default"]);
495  }
496  else
497  {
498  $Value = self::LoadValue($FieldType, NULL);
499  }
500 
501  switch ($FieldType)
502  {
503  case self::FTYPE_IMAGE:
504  # get name of image ID form field
505  $ImgIdFieldName = $FormFieldName."_ID";
506 
507  # use an updated value for this field if available
508  if (isset($this->HiddenFields[$ImgIdFieldName]))
509  {
510  $Value = $this->HiddenFields[$ImgIdFieldName];
511  }
512  # else use a value from form if available
513  elseif (isset($_POST[$ImgIdFieldName]))
514  {
515  $Value = $_POST[$ImgIdFieldName];
516  }
517 
518  # add in any previously-set extra values
519  if (isset($this->ExtraValues[$ImgIdFieldName])
520  && count($this->ExtraValues[$ImgIdFieldName]))
521  {
522  if (!is_array($Value))
523  {
524  $Value = array($Value);
525  }
526  $Value = array_merge($Value,
527  $this->ExtraValues[$ImgIdFieldName]);
528  }
529  break;
530 
531  case self::FTYPE_SEARCHPARAMS:
532  # use incoming form value if available
533  if (isset($_POST[$FormFieldName]))
534  {
535  # use incoming form value
536  $SPEditor = new SearchParameterSetEditingUI($FormFieldName);
537  $Value = $SPEditor->GetValuesFromFormData();
538  }
539  break;
540 
541  case self::FTYPE_PRIVILEGES:
542  # use incoming form value if available
543  $Schemas = GetArrayValue(
544  $this->FieldParams[$FieldName], "Schemas");
545  $MFields = GetArrayValue(
546  $this->FieldParams[$FieldName], "MetadataFields", array());
547  $PEditor = new PrivilegeEditingUI($Schemas, $MFields);
548  $PSet = $PEditor->GetPrivilegeSetFromForm($FormFieldName);
549  if ($PSet instanceof PrivilegeSet)
550  {
551  # use incoming form value
552  $Value = $PSet;
553  }
554  break;
555 
556  default:
557  # use incoming form value if available
558  if (isset($_POST[$FormFieldName]))
559  {
560  # use incoming form value
561  $Value = $_POST[$FormFieldName];
562  }
563  break;
564  }
565 
566  # return value found to caller
567  return $Value;
568  }
569 
573  public function HandleUploads()
574  {
575  # for each form field
576  foreach ($this->FieldParams as $FieldName => $FieldParams)
577  {
578  # move on to next field if this field does not allow uploads
579  if ($FieldParams["Type"] != self::FTYPE_IMAGE)
580  {
581  continue;
582  }
583 
584  # move on to next field if this field does not have an uploaded file
585  $FormFieldName = $this->GetFormFieldName($FieldName);
586  if (!isset($_FILES[$FormFieldName]["name"]))
587  {
588  continue;
589  }
590  $UploadedFileName = $_FILES[$FormFieldName]["name"];
591  if (!strlen($UploadedFileName))
592  {
593  continue;
594  }
595 
596  # create temp copy of file with correct name
597  $TmpFile = "tmp/".$UploadedFileName;
598  copy($_FILES[$FormFieldName]["tmp_name"], $TmpFile);
599 
600  switch ($FieldParams["Type"])
601  {
602  case self::FTYPE_IMAGE:
603  # create new image object from uploaded file
604  $Image = new SPTImage($TmpFile,
605  $FieldParams["MaxWidth"],
606  $FieldParams["MaxHeight"],
607  $FieldParams["MaxPreviewWidth"],
608  $FieldParams["MaxPreviewHeight"],
609  $FieldParams["MaxThumbnailWidth"],
610  $FieldParams["MaxThumbnailHeight"]);
611 
612  # check for errors during image object creation
613  if ($Image->Status() != AI_OKAY)
614  {
615  switch ($Image->Status())
616  {
617  case AI_UNKNOWNTYPE:
618  $this->LogError("Unknown format for file "
619  .$UploadedFileName.".", $FieldName);
620  break;
621 
623  $this->LogError("Unsupported format for file "
624  .$UploadedFileName." ("
625  .$Image->Format().").", $FieldName);
626  break;
627 
628  default:
629  $this->LogError("Error encountered when"
630  ." processing uploaded image file "
631  .$UploadedFileName.".", $FieldName);
632  break;
633  }
634  unlink($TmpFile);
635  continue;
636  }
637 
638  # set image object alternate text
639  $Image->AltText($_POST[$FormFieldName."_AltText_NEW"]);
640 
641  # add image ID to extra values
642  $this->ExtraValues[$FormFieldName."_ID"][] = $Image->Id();
643  break;
644  }
645  }
646  }
647 
651  public function HandleDeletes()
652  {
653  # if deleted image ID is available
654  $DeleteFieldName = $this->GetFormFieldName("ImageToDelete");
655 
656  $IncomingValue = GetFormValue($DeleteFieldName);
657  if (is_numeric($IncomingValue)
658  || (is_array($IncomingValue) && count($IncomingValue)))
659  {
660  # retrieve ID of image
661  $ImageId = is_array($IncomingValue)
662  ? array_shift($IncomingValue)
663  : $IncomingValue;
664 
665  # add ID to deleted images list
666  $this->DeletedImages[] = $ImageId;
667  }
668  }
669 
681  public function SetEventToSignalOnChange($EventName, $EventParams = array())
682  {
683  $this->SettingChangeEventName = $EventName;
684  $this->SettingChangeEventParams = $EventParams;
685  }
686 
693  public static function DidValueChange($OldValue, $NewValue)
694  {
695  # didn't change if they are identical
696  if ($OldValue === $NewValue)
697  {
698  return FALSE;
699  }
700 
701  # need special cases from this point because PHP returns some odd results
702  # when performing loose equality comparisons:
703  # http://php.net/manual/en/types.comparisons.php#types.comparisions-loose
704 
705  # consider NULL and an empty string to be the same. this is in case a field
706  # is currently set to NULL and receives an empty value from the form.
707  # $_POST values are always strings
708  if ((is_null($OldValue) && is_string($NewValue) && !strlen($NewValue))
709  || (is_null($NewValue) && is_string($OldValue) && !strlen($OldValue)))
710  {
711  return FALSE;
712  }
713 
714  # if they both appear to be numbers and are equal
715  if (is_numeric($OldValue) && is_numeric($NewValue) && $OldValue == $NewValue)
716  {
717  return FALSE;
718  }
719 
720  # true-like values
721  if (($OldValue === TRUE && ($NewValue === 1 || $NewValue === "1"))
722  || ($NewValue === TRUE && ($OldValue === 1 || $OldValue === "1")))
723  {
724  return FALSE;
725  }
726 
727  # false-like values
728  if (($OldValue === FALSE && ($NewValue === 0 || $NewValue === "0"))
729  || ($NewValue === FALSE && ($OldValue === 0 || $OldValue === "0")))
730  {
731  return FALSE;
732  }
733 
734  # arrays
735  if (is_array($OldValue) && is_array($NewValue))
736  {
737  # they certainly changed if the counts are different
738  if (count($OldValue) != count($NewValue))
739  {
740  return TRUE;
741  }
742 
743  # the algorithm for associative arrays is slightly different from
744  # sequential ones. the values for associative arrays must match the keys
745  if (count(array_filter(array_keys($OldValue), "is_string")))
746  {
747  foreach ($OldValue as $Key => $Value)
748  {
749  # it changed if the keys don't match
750  if (!array_key_exists($Key, $NewValue))
751  {
752  return TRUE;
753  }
754 
755  # the arrays changed if a value changed
756  if (self::DidValueChange($Value, $NewValue[$Key]))
757  {
758  return TRUE;
759  }
760  }
761  }
762 
763  # sequential values don't have to have the same keys, just the same
764  # values
765  else
766  {
767  # sort them so all the values match up if they're equal
768  sort($OldValue);
769  sort($NewValue);
770 
771  foreach ($OldValue as $Key => $Value)
772  {
773  # the arrays changed if a value changed
774  if (self::DidValueChange($Value, $NewValue[$Key]))
775  {
776  return TRUE;
777  }
778  }
779  }
780 
781  # the arrays are equal
782  return FALSE;
783  }
784 
785  # they changed
786  return TRUE;
787  }
788 
795  static public function LoadValue($Type, $Data)
796  {
797  switch ($Type)
798  {
799  case self::FTYPE_IMAGE:
800  $Value = ($Data === NULL) ? array() : $Data;
801  break;
802 
803  case self::FTYPE_PRIVILEGES:
804  $Value = ($Data instanceof PrivilegeSet) ? $Data
805  : new PrivilegeSet($Data);
806  break;
807 
808  case self::FTYPE_SEARCHPARAMS:
809  $Value = ($Data instanceof SearchParameterSet) ? $Data
810  : new SearchParameterSet($Data);
811  break;
812 
813  default:
814  $Value = $Data;
815  break;
816  }
817 
818  return $Value;
819  }
820 
833  public function ValidateEmail($FieldName, $FieldValues)
834  {
835  if (!is_array($FieldValues)) { $FieldValues = array($FieldValues); }
836  foreach ($FieldValues as $Value)
837  {
838  if (trim($Value) == "") { continue; }
839  if (filter_var($Value, FILTER_VALIDATE_EMAIL) === FALSE)
840  {
841  return "The value for <i>".$this->FieldParams[$FieldName]["Label"]
842  ."</i> does not appear to be a valid email address.";
843  }
844  }
845  return NULL;
846  }
847 
860  public function ValidateUrl($FieldName, $FieldValues)
861  {
862  if (!is_array($FieldValues)) { $FieldValues = array($FieldValues); }
863  foreach ($FieldValues as $Value)
864  {
865  if (trim($Value) == "") { continue; }
866  if (filter_var($Value, FILTER_VALIDATE_URL) === FALSE)
867  {
868  return "The value for <i>".$this->FieldParams[$FieldName]["Label"]
869  ."</i> does not appear to be a valid URL.";
870  }
871  }
872  return NULL;
873  }
874 
888  public function ValidateHostName($FieldName, $FieldValues)
889  {
890  if (!is_array($FieldValues)) { $FieldValues = array($FieldValues); }
891  foreach ($FieldValues as $Value)
892  {
893  if (trim($Value) == "") { continue; }
894  if (gethostbyname($Value) === $Value)
895  {
896  return "The value for <i>".$this->FieldParams[$FieldName]["Label"]
897  ."</i> does not appear to be a valid host name.";
898  }
899  }
900  return NULL;
901  }
902 
903 
904  # ---- PRIVATE INTERFACE -------------------------------------------------
905 
906  protected $DeletedImages = array();
907  protected $ExtraValidationParams = array();
908  protected $ExtraValues = array();
909  protected $FieldParams;
910  protected $FieldValues;
911  protected $HiddenFields = array();
912  protected $SettingChangeEventName = NULL;
913  protected $SettingChangeEventParams = array();
914 
915  protected static $ErrorMessages = array();
916 
918  const NO_VALUE_FOR_FIELD = "NO VALUE";
919 
926  abstract protected function DisplayFormField($Name, $Value, $Params);
927 
935  protected function GetFormFieldName($FieldName, $IncludePrefix = TRUE)
936  {
937  return ($IncludePrefix ? "F_" : "")
938  .($this->UniqueKey ? $this->UniqueKey."_" : "")
939  .preg_replace("/[^a-zA-Z0-9]/", "", $FieldName);
940  }
941 
945  protected function GetHiddenFieldsHtml()
946  {
947  $Html = "";
948  if (count($this->HiddenFields))
949  {
950  foreach ($this->HiddenFields as $FieldName => $Value)
951  {
952  if (is_array($Value))
953  {
954  foreach ($Value as $EachValue)
955  {
956  $Html .= '<input type="hidden" name="'.$FieldName
957  .'[]" value="'.htmlspecialchars($EachValue).'">';
958  }
959  }
960  else
961  {
962  $Html .= '<input type="hidden" name="'.$FieldName
963  .'[]" id="'.$FieldName.'" value="'
964  .htmlspecialchars($Value).'">';
965  }
966  }
967  }
968  return $Html;
969  }
970 }
static LogError($Msg, $Field=NULL)
Log error message for later display.
Base class (covering non-presentation elements) supplying a standard user interface for presenting an...
Definition: FormUI_Base.php:14
const FTYPE_NUMBER
Definition: FormUI_Base.php:22
const AI_UNKNOWNTYPE
Definition: Image.php:555
GetNewValuesFromForm()
Retrieve values set by form.
Set of parameters used to perform a search.
const FTYPE_SEARCHPARAMS
Definition: FormUI_Base.php:27
const FTYPE_OPTION
Definition: FormUI_Base.php:23
const AI_OKAY
Definition: Image.php:550
GetHiddenFieldsHtml()
Get HTML for hidden form fields associated with form processing.
ValidateHostName($FieldName, $FieldValues)
Validate value as valid host name (i.e.
__construct($FieldParams, $FieldValues=array(), $UniqueKey=NULL)
Class constructor.
Definition: FormUI_Base.php:44
SetEventToSignalOnChange($EventName, $EventParams=array())
Set event to signal when retrieving values from form when settings have changed.
const FTYPE_IMAGE
Definition: FormUI_Base.php:20
const FTYPE_PARAGRAPH
Definition: FormUI_Base.php:24
ValidateFieldInput()
Validate field values on submitted form.
const FTYPE_TEXT
Definition: FormUI_Base.php:28
User interface element for editing PrivilegeSets.
Set of privileges used to access resource information or other parts of the system.
const FTYPE_PRIVILEGES
Definition: FormUI_Base.php:26
static $ErrorMessages
static LoadValue($Type, $Data)
Load value of requested type from supplied data.
CWIS-specific user factory class.
const NO_VALUE_FOR_FIELD
Marker used to indicate currently no value for field.
ValidateEmail($FieldName, $FieldValues)
Validate value as valid-appearing email address.
const FTYPE_PASSWORD
Definition: FormUI_Base.php:25
static ClearLoggedErrors($Field=FALSE)
Clear logged errors.
const FTYPE_FLAG
Supported field types.
Definition: FormUI_Base.php:19
const FTYPE_URL
Definition: FormUI_Base.php:29
const FTYPE_USER
Definition: FormUI_Base.php:30
Encapsulates a full-size, preview, and thumbnail image.
Definition: SPTImage.php:13
static ErrorsLogged($Field=FALSE)
Report whether errors have been logged.
HandleUploads()
Handle image and file uploads.
GetFormFieldName($FieldName, $IncludePrefix=TRUE)
Get HTML form field name for specified field.
static GetLoggedErrors()
Get logged errors.
const FTYPE_HEADING
Supported field pseudo-types.
Definition: FormUI_Base.php:32
ValidateUrl($FieldName, $FieldValues)
Validate value as valid-appearing URL.
GetFieldValue($FieldName)
Get value for form field.
static DidValueChange($OldValue, $NewValue)
Determine if a new form field value is different from an old one.
const FTYPE_METADATAFIELD
Definition: FormUI_Base.php:21
DisplayFormTable($TableId=NULL, $TableStyle=NULL)
Display HTML table with settings parameters.
HandleDeletes()
Handle image and file deletions.
AddValidationParameters()
Add values to be passed to input validation functions, in addition to field name and value...
Class to create a user interface for editing SearchParameterSets.
DisplayFormField($Name, $Value, $Params)
Display HTML form field for specified field.
const AI_UNSUPPORTEDFORMAT
Definition: Image.php:556