CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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