CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

UserEditingUI.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: UserEditingUI.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2015 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
14 class UserEditingUI
15 {
20 public function __construct($CWUser)
21 {
22 $this->User = $CWUser;
23 }
24
32 public function UpdateUserAttributes(
33 array $FormValues,
34 $IsNewUser=FALSE,
35 $UpdateUserEmail=FALSE)
36 {
37 # save other user information
38 $UserFields = array(
39 "WebSite",
40 "AddressLineOne",
41 "AddressLineTwo",
42 "City",
43 "State",
44 "ZipCode",
45 "Country",
46 );
47
48 if ($UpdateUserEmail)
49 {
50 $UserFields[] = "EMail";
51 }
52 foreach ($UserFields as $VarName)
53 {
54 $FormVarName = "F_".$VarName;
55 if (isset($FormValues[$FormVarName]) && strlen($FormValues[$FormVarName]))
56 {
57 $this->User->Set($VarName, $FormValues[$FormVarName]);
58 }
59 }
60
61 # real name is handled separately so we can signal
62 # EVENT_USER_REAL_NAME_CHANGED if needed
63
64 # if a new real name was provided
65 $NewRealName = GetArrayValue($FormValues, "F_RealName", "");
66 if (strlen($NewRealName))
67 {
68 # pull out the old value
69 $OldRealName = $this->User->Get("RealName");
70
71 # update the stored value
72 $this->User->Set("RealName", $NewRealName);
73
74 # if this was an existing user and the value changed
75 if (!$IsNewUser && $OldRealName != $NewRealName)
76 {
77 # signal the real name change
78 $GLOBALS["AF"]->SignalEvent(
79 "EVENT_USER_REAL_NAME_CHANGED",
80 array(
81 "UserId" => $this->User->Id(),
82 "OldRealName" => $OldRealName,
83 "NewRealName" => $NewRealName));
84 }
85 }
86 }
87
95 public function UpdateUserFields(array $Fields)
96 {
97 global $AF;
98
99 $Schema = new MetadataSchema(MetadataSchema::SCHEMAID_USER);
100 $Resource = $this->User->GetResource();
101 $EmptyFields = array();
102 $RecordChanged = FALSE;
103
104 # for each metadata field in the User schema
105 foreach ($Fields as $Field)
106 {
107 # if user has permission to edit field
108 if ($Resource->UserCanEditField($this->User, $Field))
109 {
110 $OldValue = $Resource->Get($Field);
111 switch ($Field->Type())
112 {
113 case MetadataSchema::MDFTYPE_TEXT:
114 case MetadataSchema::MDFTYPE_NUMBER:
115 case MetadataSchema::MDFTYPE_DATE:
116 case MetadataSchema::MDFTYPE_TIMESTAMP:
117 case MetadataSchema::MDFTYPE_PARAGRAPH:
118 case MetadataSchema::MDFTYPE_FLAG:
119 case MetadataSchema::MDFTYPE_URL:
120 # if we have a value from the form for this field
121 # (check necessary because user may push Save button
122 # before form has finished loading)
123 if (isset($_POST["F_".$Field->DBFieldName()]))
124 {
125 # run value through any hooked filters
126 $NewValue = trim($_POST["F_".$Field->DBFieldName()]);
127 $SignalResult = $AF->SignalEvent(
128 "EVENT_POST_FIELD_EDIT_FILTER", array(
129 "Field" => $Field,
130 "Resource" => $Resource,
131 "Value" => $NewValue));
132 $NewValue = $SignalResult["Value"];
133
134 # clean out xss threats
135 $NewValue = StripXSSThreats($NewValue);
136
137 # filter date field values for validity
138 if ($Field->Type() & (MetadataSchema::MDFTYPE_DATE
139 |MetadataSchema::MDFTYPE_TIMESTAMP))
140 {
141 $TestDate = new Date($NewValue);
142 if ($TestDate->Precision() == 0) { $NewValue = ""; }
143 }
144
145 # filter url values for URI
146 if ($Field->Type() == MetadataSchema::MDFTYPE_URL
147 && strlen($NewValue)
148 && !preg_match('/^[a-zA-Z]+:\/\//', $NewValue))
149 {
150 $NewValue = "http://".$NewValue;
151 }
152
153 # filter HTML tags out of text values if appropriate
154 if ($Field->Type() & (MetadataSchema::MDFTYPE_TEXT
155 |MetadataSchema::MDFTYPE_PARAGRAPH))
156 {
157 if (!$Field->AllowHTML())
158 {
159 $NewValue = strip_tags($NewValue);
160 }
161 }
162
163 # if value was supplied or field is not required
164 if (strlen($NewValue) || $Field->Optional())
165 {
166 # save field
167 $Resource->Set($Field, $NewValue);
168 }
169 else
170 {
171 # add field to error list
172 $EmptyFields[] = $Field;
173 }
174 }
175 break;
176
177 case MetadataSchema::MDFTYPE_POINT:
178 # if there are no values set
179 if (!isset($_POST["F_".$Field->DBFieldName()."X"])
180 || !isset($_POST["F_".$Field->DBFieldName()."Y"]))
181 {
182 # if the field isn't optional, add it to the error list
183 if (!$Field->Optional())
184 {
185 $EmptyFields[] = $Field;
186 }
187
188 # go to the next field
189 continue;
190 }
191
192 # run value through any hooked filters
193 $NewValue = array(
194 "X" => $_POST["F_".$Field->DBFieldName()."X"],
195 "Y" => $_POST["F_".$Field->DBFIeldName()."Y"]);
196 $SignalResult = $AF->SignalEvent(
197 "EVENT_POST_FIELD_EDIT_FILTER", array(
198 "Field" => $Field,
199 "Resource" => $Resource,
200 "Value" => $NewValue));
201 $NewValue = $SignalResult["Value"];
202
203 # if value looks valid
204 if (is_numeric($NewValue["X"])
205 && is_numeric($NewValue["Y"]))
206 {
207 # save new value
208 $Resource->Set($Field, $NewValue);
209 }
210
211 # the field is optional and the values are blank
212 else if ($Field->Optional()
213 && !strlen(trim($NewValue["X"]))
214 && !strlen(trim($NewValue["Y"])))
215 {
216 # save blank value
217 $Resource->Set($Field, array("X" => "", "Y" => ""));
218 }
219
220 # empty fields and field is required
221 else if (!$Field->Optional())
222 {
223 # flag field as empty
224 $EmptyFields[] = $Field;
225 }
226 break;
227
228 case MetadataSchema::MDFTYPE_TREE:
229 case MetadataSchema::MDFTYPE_CONTROLLEDNAME:
230 # while there are form values for this field
231 $ValueCount = $Field->GetCountOfPossibleValues();
232 $InterfaceToggleThreshold = 250;
233 $Factory = $Field->GetFactory();
234 $ValuesToSet = array();
235 $InputValues = array();
236
237 # old way it was being set
238 $BaseFieldName = "D_".$Field->DBFieldName()."_";
239 $FieldIndex = 1;
240
241 # set values the old way
242 if (isset($_POST[$BaseFieldName.$FieldIndex]))
243 {
244 while (isset($_POST[$BaseFieldName.$FieldIndex]))
245 {
246 # retrieve value from form field
247 $InputValues[] = $_POST[$BaseFieldName.$FieldIndex];
248
249 # move to the next form value
250 $FieldIndex++;
251 }
252 }
253
254 # set values the new way
255 else if (isset($_POST["F_".$Field->DBFieldName()]))
256 {
257 $InputValues = $_POST["F_".$Field->DBFieldName()];
258 }
259
260 foreach ($InputValues as $Value)
261 {
262 # If we have a non-empty value
263 if (strlen($Value))
264 {
265 # Check to see if it was a name, and if so
266 # convert it to an index. Otherwise,
267 # it was already an index and we should use it
268 # directly.
269 $Item = $Factory->GetItemByName($Value);
270 if ($Item)
271 {
272 $Value = $Item->Id();
273 }
274
275 # it looks like it was being wrongly assumed that
276 # this would always be a number, but when there's
277 # an error, it won't find an item and display SQL
278 # errors later on. So, if the value isn't numeric,
279 # refuse to work with it
280 else if (!is_numeric($Value))
281 {
282 $Value = -1;
283 }
284 else
285 {
286 $Value = intval($Value);
287 }
288 }
289 else
290 {
291 $Value = -1;
292 }
293
294 # if form value appears valid
295 if ($Value >= 0)
296 {
297 # add value to list of those to be set
298 # (set method expects IDs to appear as indexes)
299 $ValuesToSet[$Value] = 1;
300 }
301 }
302
303 # if value found to set or field is not required
304 if (count($ValuesToSet) || $Field->Optional())
305 {
306 $OldKeys = array_keys($OldValue);
307 $NewKeys = array_keys($ValuesToSet);
308
309 sort($OldKeys);
310 sort($NewKeys);
311
312 if ($OldKeys != $NewKeys)
313 {
314 # clear any existing values for this field
315 $Resource->ClearByField($Field);
316
317 # if values found to set
318 if (count($ValuesToSet))
319 {
320 # set values in resource
321 $Resource->Set($Field, $ValuesToSet);
322 }
323 }
324 }
325 else
326 {
327 # add field to error list
328 $EmptyFields[] = $Field;
329 }
330 break;
331
332 case MetadataSchema::MDFTYPE_OPTION:
333 # if field allows multiple values
334 $ValuesToSet = array();
335 if ($Field->AllowMultiple())
336 {
337 # retrieve possible values for this field
338 $PossibleValues = $Field->GetPossibleValues();
339
340 # newer way to get the values
341 if (isset($_POST["F_".$Field->DBFieldName()]))
342 {
343 $GivenValues = $_POST["F_".$Field->DBFieldName()];
344
345 # for each possible value
346 foreach ($PossibleValues as $ValueId => $ValueName)
347 {
348 # if form field is set for value
349 if (in_array($ValueId, $GivenValues))
350 {
351 # add value to list of those to be set
352 $ValuesToSet[$ValueId] = 1;
353 }
354 }
355 }
356
357 # old way to get the values
358 else
359 {
360 # for each possible value
361 foreach ($PossibleValues as $ValueId => $ValueName)
362 {
363 # if form field is set for value
364 if (isset($_POST["D_".$Field->DBFieldName()
365 ."_".$ValueId]))
366 {
367 # add value to list of those to be set
368 $ValuesToSet[$ValueId] = 1;
369 }
370 }
371 }
372 }
373 else
374 {
375 # retrieve value for this field (if available)
376 if (isset($_POST["F_".$Field->DBFieldName()]))
377 {
378 $ValuesToSet[$_POST["F_".$Field->DBFieldName()]] = 1;
379 }
380 }
381
382 # if value found to set or field is not required
383 if (count($ValuesToSet) || $Field->Optional())
384 {
385 $OldKeys = array_keys($OldValue);
386 $NewKeys = array_keys($ValuesToSet);
387
388 sort($OldKeys);
389 sort($NewKeys);
390
391 if ($OldKeys != $NewKeys)
392 {
393 # clear any existing values for this field
394 $Resource->ClearByField($Field);
395
396 # if values found to set
397 if (count($ValuesToSet))
398 {
399 # set values in resource
400 $Resource->Set($Field, $ValuesToSet);
401 }
402 }
403 }
404 else
405 {
406 # add field to error list
407 $EmptyFields[] = $Field;
408 }
409 break;
410
411 case MetadataSchema::MDFTYPE_USER:
412 $NewValue = trim(GetArrayValue(
413 $_POST,
414 "F_".$Field->DBFieldName()));
415
416 if (strlen($NewValue))
417 {
418 $SignalResult = $AF->SignalEvent(
419 "EVENT_POST_FIELD_EDIT_FILTER", array(
420 "Field" => $Field,
421 "Resource" => $Resource,
422 "Value" => $NewValue));
423
424 $NewValue = $SignalResult["Value"];
425 $Resource->Set($Field, $NewValue);
426 }
427
428 # allow the field to be unset if it's optional
429 else if ($Field->Optional())
430 {
431 $SignalResult = $AF->SignalEvent(
432 "EVENT_POST_FIELD_EDIT_FILTER", array(
433 "Field" => $Field,
434 "Resource" => $Resource,
435 "Value" => $NewValue));
436
437 $NewValue = $SignalResult["Value"];
438 $Resource->Set($Field, $NewValue);
439 }
440
441 break;
442
443 case MetadataSchema::MDFTYPE_REFERENCE:
444 # get the new value from the submitted form data
445 $NewValue = GetArrayValue(
446 $_POST,
447 "F_".$Field->DBFieldName(),
448 array());
449
450 foreach ($NewValue as $Key => $ReferenceId)
451 {
452 # remove any blank values
453 if (strlen(trim($ReferenceId)) < 1)
454 {
455 unset($NewValue[$Key]);
456 }
457
458 # remove any values that don't look right
459 if (!is_numeric($ReferenceId))
460 {
461 unset($NewValue[$Key]);
462 }
463 }
464
465 # set the new value
466 $Resource->Set($Field, $NewValue);
467 break;
468
469 case MetadataSchema::MDFTYPE_IMAGE:
470 case MetadataSchema::MDFTYPE_FILE:
471 # (these types handled via special upload mechanisms)
472 break;
473
474 default:
475 break;
476 }
477 # If anything changed, set the update flag.
478 $RecordChanged |= ($OldValue
479 != $Resource->Get($Field));
480 }
481 }
482
483 # If the record was changed, modify the appropriate timestamp fields
484 if ($RecordChanged)
485 {
486 $Resource->UpdateAutoupdateFields(
487 MetadataField::UPDATEMETHOD_ONRECORDCHANGE,
488 $GLOBALS["G_User"]);
489
490 # update search and recommender DBs if configured to do so
491 $Resource->QueueSearchAndRecommenderUpdate();
492
493 # signal the modified event if the resource isn't a temp one
494 if (!$Resource->IsTempResource())
495 {
496 $AF->SignalEvent("EVENT_RESOURCE_MODIFY", array("Resource" => $Resource));
497 }
498 }
499
500 # return list of any empty required fields to caller
501 return $EmptyFields;
502 }
503
509 public function UploadFiles($FormValues, $Files)
510 {
511 # for each metadata field that might have an uploaded image
512 $Schema = new MetadataSchema(MetadataSchema::SCHEMAID_USER);
513 $Resource = $this->User->GetResource();
514 $Fields = $Schema->GetFields(MetadataSchema::MDFTYPE_FILE);
515 foreach ($Fields as $Field)
516 {
517 $FormFieldName = "F_".$Field->DBFieldName();
518
519 # if field is modifiable by specified user
520 # and we have an uploaded file for this field
521 if ($Resource->UserCanEditField($this->User, $Field)
522 && isset($Files[$FormFieldName]["tmp_name"])
523 && is_uploaded_file($Files[$FormFieldName]["tmp_name"]))
524 {
525 # save uploaded file
526 $TmpFileName = $Files[$FormFieldName]["tmp_name"];
527 $NewFile = new File($TmpFileName, $Resource->Id(), $Field->Id(),
528 $Files[$FormFieldName]["name"]);
529
530 # if file save went fine
531 if ($NewFile->Status() == File::FILESTAT_OK)
532 {
533 $GLOBALS["AF"]->SignalEvent(
534 "EVENT_RESOURCE_FILE_ADD",
535 array(
536 "Field" => $Field,
537 "Resource" => $Resource,
538 "File" => $NewFile));
539 }
540
541 else
542 {
543 # set error message and error out
544 switch ($NewFile->Status())
545 {
546 case File::FILESTAT_ZEROLENGTH:
547 $Error = ERR_ZEROLENGTH;
548 break;
549
550 default:
551 $Error = ERR_FILEUPLOADERROR;
552 break;
553 }
554 $ErrParamOne = $Files[$FormFieldName]['name'];
555 $ErrParamTwo = $NewFile->Status();
556 }
557
558 # remove temp file
559 unlink($TmpFileName);
560 }
561
562 # delete images that have been selected for delete
563 if (isset($FormValues[$FormFieldName."_Delete"]))
564 {
565 $DeletionIds = $FormValues[$FormFieldName."_Delete"];
566
567 foreach ($DeletionIds as $DeletionId)
568 {
569 $File = new File($DeletionId);
570
571 $GLOBALS["AF"]->SignalEvent(
572 "EVENT_RESOURCE_FILE_DELETE",
573 array(
574 "Field" => $Field,
575 "Resource" => $Resource,
576 "File" => $File));
577
578 $Resource->Clear($Field, $File->Id());
579 }
580 }
581 }
582 }
583
584
590 public function UploadImages($FormValues, $Files)
591 {
592 # for each metadata field that might have an uploaded image
593 $Schema = new MetadataSchema(MetadataSchema::SCHEMAID_USER);
594 $Resource = $this->User->GetResource();
595 $Fields = $Schema->GetFields(MetadataSchema::MDFTYPE_IMAGE);
596 foreach ($Fields as $Field)
597 {
598 $FormFieldName = "F_".$Field->DBFieldName();
599
600 # if field is modifiable by specified user
601 # and we have an uploaded file for this field
602 if ($Resource->UserCanEditField($this->User, $Field)
603 && isset($Files[$FormFieldName]["tmp_name"])
604 && is_uploaded_file($Files[$FormFieldName]["tmp_name"]))
605 {
606 # create temp copy of file with correct name
607 $TempFile = "tmp/".$Files[$FormFieldName]['name'];
608 copy($Files[$FormFieldName]["tmp_name"], $TempFile);
609
610 # create new Image object from uploaded file
611 $Image = new SPTImage(
612 $TempFile,
613 $Field->MaxWidth(), $Field->MaxHeight(),
614 $Field->MaxPreviewWidth(), $Field->MaxPreviewHeight(),
615 $Field->MaxThumbnailWidth(), $Field->MaxThumbnailHeight());
616
617 # if file save failed
618 if ($Image->Status() != AI_OKAY)
619 {
620 # set error message and error out
621 switch ($Image->Status())
622 {
623 case AI_UNKNOWNTYPE:
624 case AI_UNSUPPORTEDFORMAT:
625 $Error = ($Image->Status() == AI_UNSUPPORTEDFORMAT)
626 ? ERR_UNSUPPORTEDIMAGEFORMAT : ERR_UNKNOWNIMAGETYPE;
627 $ErrParamOne = $Files[$Field->DBFieldName()]['name'];
628 break;
629
630 default:
631 $Error = ERR_IMAGEUPLOADERROR;
632 $ErrParamOne = $Files[$FormFieldName]['name'];
633 $ErrParamTwo = $Image->Status();
634 break;
635 }
636 }
637 else
638 {
639 # attach image to resource
640 $Resource->Set($Field, $Image->Id());
641 }
642 }
643
644 # delete images that have been selected for delete
645 if (isset($FormValues[$FormFieldName."_Delete"]))
646 {
647 $DeletionIds = $FormValues[$FormFieldName."_Delete"];
648
649 foreach ($DeletionIds as $DeletionId)
650 {
651 $Resource->Clear($Field, new SPTImage($DeletionId));
652 }
653 }
654 }
655 }
656
666 public static function UserFormHasErrors(&$FTool, $UserErrorCodes,
667 $ErrorMessages = NULL)
668 {
669 # FormTool
670 if ($FTool instanceof FormTool)
671 {
672 # if errors were found in incoming values
673 if ($FTool->IncomingFieldValuesHaveErrors() || count($UserErrorCodes))
674 {
675 # make form fields based on error codes
676 $CodeToFieldMap = array(
677 U_DUPLICATEUSERNAME => "F_UserName",
678 U_ILLEGALUSERNAME => "F_UserName",
679 U_PASSWORDSDONTMATCH => array("F_Password", "F_PasswordAgain"),
680 U_EMAILSDONTMATCH => array("F_EMail", "F_EMailAgain"),
681 U_ILLEGALPASSWORD => "F_Password",
682 U_ILLEGALPASSWORDAGAIN => "F_PasswordAgain",
683 U_ILLEGALEMAIL => "F_EMail",
684 U_ILLEGALEMAILAGAIN => "F_EMailAgain",
685 U_EMPTYPASSWORD => "F_Password",
686 U_EMPTYPASSWORDAGAIN => "F_PasswordAgain",
687 U_EMPTYEMAIL => "F_EMail",
688 U_EMPTYEMAILAGAIN => "F_EMailAgain",
689 U_DUPLICATEEMAIL => array("F_EMail", "F_EMailAgain"),
690 );
691
692 foreach ($UserErrorCodes as $Code)
693 {
694 if (isset($CodeToFieldMap[$Code]))
695 {
696 if (is_array(isset($CodeToFieldMap[$Code])))
697 {
698 foreach ($CodeToFieldMap[$Code] as $FieldName)
699 {
700 $FTool->SetAdditionalErrorFields($FieldName);
701 }
702 }
703 else
704 {
705 $FTool->SetAdditionalErrorFields($CodeToFieldMap[$Code]);
706 }
707 }
708 }
709
710 $FTool->SetAdditionalErrorCodes($ErrorMessages);
711
712 return TRUE;
713 }
714 }
715 # FormUI
716 else
717 {
718 # mark form fields based on the associated errors
719 $CodeToFieldMap = array(
720 U_DUPLICATEUSERNAME => array("UserName"),
721 U_ILLEGALUSERNAME => array("UserName"),
722 U_PASSWORDSDONTMATCH => array("Password", "PasswordAgain"),
723 U_EMAILSDONTMATCH => array("EMail", "EMailAgain"),
724 U_ILLEGALPASSWORD => array("Password"),
725 U_ILLEGALPASSWORDAGAIN => array("PasswordAgain"),
726 U_ILLEGALEMAIL => array("EMail"),
727 U_ILLEGALEMAILAGAIN => array("EMailAgain"),
728 U_EMPTYPASSWORD => array("Password"),
729 U_EMPTYPASSWORDAGAIN => array("PasswordAgain"),
730 U_DUPLICATEEMAIL => array("EMail", "EMailAgain"),
731 U_EMPTYUSERNAME => array("UserName"),
732 U_EMPTYEMAIL => array("F_EMail"),
733 U_EMPTYEMAILAGAIN => array("F_EMailAgain"),
734 );
735
736 if ($FTool->ErrorsLogged() || count($UserErrorCodes))
737 {
738 # if the user did not provide error message strings, get the defaults
739 if (is_null($ErrorMessages))
740 {
741 $ErrorMessages = self::GetAdditionalErrorCodes($_POST["F_UserName"]);
742 }
743
744 # look up messages for any unknown error codes
745 foreach ($UserErrorCodes as $Code)
746 {
747 if (!isset($ErrorMessages[$Code]))
748 {
749 $ErrorMessages[$Code] = CWUser::GetStatusMessageForCode($Code);
750 }
751 }
752
753 # for each reported error
754 foreach ($UserErrorCodes as $Code)
755 {
756 # see if this error corresponds to a field or fields
757 if (isset($CodeToFieldMap[$Code]))
758 {
759 # if so, log the error for each implicated field
760 foreach ($CodeToFieldMap[$Code] as $Field)
761 {
762 $FTool->LogError($ErrorMessages[$Code], $Field);
763 }
764 }
765 else
766 {
767 # otherwise, log the error as a general error
768 $FTool->LogError($ErrorMessages[$Code]);
769 }
770 }
771
772 return TRUE;
773 }
774 }
775
776 # return
777 return FALSE;
778 }
779
786 public static function GetActivationEmailSubstitutions($NewUser)
787 {
788 $Protocol = isset($_SERVER["HTTPS"]) ? "https://" : "http://";
789
790 $ActivationUrlParameters = "?UN=".urlencode($NewUser->Get("UserName"))
791 ."&AC=".$NewUser->GetActivationCode();
792 $ActivationUrl = $Protocol.$_SERVER["SERVER_NAME"]
793 .dirname($_SERVER["SCRIPT_NAME"])
794 ."/index.php".$ActivationUrlParameters."&P=ActivateAccount";
795 $ManualActivationUrl = $Protocol.$_SERVER["SERVER_NAME"]
796 .dirname($_SERVER["SCRIPT_NAME"])
797 ."/index.php?P=ManuallyActivateAccount";
798
799 return array(
800 "X-PORTALNAME-X" => $GLOBALS["G_SysConfig"]->PortalName(),
801 "X-ACTIVATIONURL-X" => $ActivationUrl,
802 "X-ACTIVATIONPARAMETERS-X" => $ActivationUrlParameters,
803 "X-MANUALACTIVATIONURL-X" => $ManualActivationUrl,
804 );
805 }
806
814 public static function GetRequestAccountForm($ReadOnlyFields = array(),
815 $FieldsToExclude = array(), $AdditionalFields = array())
816 {
817 $UsStates = StdLib::GetUsStatesList();
818 array_unshift($UsStates, "--");
819
820 # blank Placeholder values overwrite default of "($Label)"
821 $FormFields = array(
822 "LoginInformation" => array(
823 "Type" => FormUI::FTYPE_HEADING,
824 "Label" => "Login Information",
825 ),
826 "UserName" => array(
827 "Type" => FormUI::FTYPE_USER,
828 "Label" => "User Name",
829 "Required" => TRUE,
830 "Size" => 23,
831 "MaxLength" => 64,
832 "Placeholder" => "",
833 ),
834 "Password" => array(
835 "Type" => FormUI::FTYPE_PASSWORD,
836 "Label" => "Password",
837 "Required" => TRUE,
838 "Size" => 17,
839 "Placeholder" => "",
840 "Help" => "(".CWUser::GetPasswordRulesDescription().")",
841 ),
842 "PasswordAgain" => array(
843 "Type" => FormUI::FTYPE_PASSWORD,
844 "Label" => "Password (Again)",
845 "Required" => TRUE,
846 "Size" => 17,
847 "Placeholder" => "",
848 "Help" => "(passwords are case sensitive)",
849 ),
850 "EMail" => array(
851 "Type" => FormUI::FTYPE_TEXT,
852 "Label" => "E-mail Address",
853 "Required" => TRUE,
854 "Size" => 30,
855 "MaxLength" => 80,
856 "Placeholder" => "",
857 "Help" => "(must be valid to activate account)",
858 ),
859 "EMailAgain" => array(
860 "Type" => FormUI::FTYPE_TEXT,
861 "Label" => "E-mail Address (Again)",
862 "Required" => TRUE,
863 "Size" => 30,
864 "MaxLength" => 80,
865 "Placeholder" => "",
866 ),
867 "UserInformation" => array(
868 "Type" => FormUI::FTYPE_HEADING,
869 "Label" => "User Information (Optional)"
870 ),
871 "RealName" => array(
872 "Type" => FormUI::FTYPE_TEXT,
873 "Label" => "Real Name",
874 "Required" => FALSE,
875 "Size" => 23,
876 "MaxLength" => 40,
877 "Placeholder" => "",
878 ),
879 "WebSite" => array(
880 "Type" => FormUI::FTYPE_TEXT,
881 "Label" => "Web Site",
882 "Required" => FALSE,
883 "Size" => 23,
884 "MaxLength" => 80,
885 "Placeholder" => "",
886 ),
887 "AddressLineOne" => array(
888 "Type" => FormUI::FTYPE_TEXT,
889 "Label" => "Address",
890 "Required" => FALSE,
891 "Size" => 23,
892 "MaxLength" => 60,
893 "Placeholder" => "",
894 ),
895 "AddressLineTwo" => array(
896 "Type" => FormUI::FTYPE_TEXT,
897 "Label" => "",
898 "Required" => FALSE,
899 "Size" => 23,
900 "MaxLength" => 60,
901 "Placeholder" => "",
902 ),
903 "City" => array(
904 "Type" => FormUI::FTYPE_TEXT,
905 "Label" => "City",
906 "Required" => FALSE,
907 "Size" => 23,
908 "MaxLength" => 40,
909 "Placeholder" => "",
910 ),
911 "State" => array(
912 "Type" => FormUI::FTYPE_OPTION,
913 "Label" => "State",
914 "Required" => FALSE,
915 "AllowMultiple" => FALSE,
916 "Options" => $UsStates,
917 ),
918 "ZipCode" => array(
919 "Type" => FormUI::FTYPE_TEXT,
920 "Label" => "Zip Code",
921 "Required" => FALSE,
922 "Size" => 10,
923 "MaxLength" => 10,
924 "Placeholder" => "",
925 ),
926 "Country" => array(
927 "Type" => FormUI::FTYPE_TEXT,
928 "Label" => "Country",
929 "Required" => FALSE,
930 "Size" => 23,
931 "MaxLength" => 40,
932 "Placeholder" => "",
933 ),
934 );
935
936 if (isset($ReadOnlyFields))
937 {
938 foreach ($ReadOnlyFields as $ReadOnly)
939 {
940 $FormFields[$ReadOnly]["ReadOnly"] = TRUE;
941 }
942 }
943
944 if (isset($FieldsToExclude))
945 {
946 foreach ($FieldsToExclude as $Exclude)
947 {
948 unset($FormFields[$Exclude]);
949 }
950
951 }
952 if (isset($AdditionalFields)) {
953 $FormFields = array_merge($FormFields, $AdditionalFields);
954 }
955
956 return $FormFields;
957 }
958
964 public static function GetAdditionalErrorCodes($UserName)
965 {
966 return array(
967 U_DUPLICATEEMAIL => "The e-mail address you entered is already associated"
968 ." with an account. If you have forgotten the account user name or"
969 ." password you can click"
970 ." <a href=\"index.php?P=ForgottenPasswordComplete&UN="
971 .urlencode($UserName)."\">here</a>"
972 ." to send a reminder via e-mail.",
973 );
974 }
975
981 public static function TestUserValues($FormValues)
982 {
983 $UserFactory = new CWUserFactory();
984 $UserErrorCodes = $UserFactory->TestNewUserValues($FormValues["F_UserName"],
985 $FormValues["F_Password"], $FormValues["F_PasswordAgain"],
986 $FormValues["F_EMail"], $FormValues["F_EMailAgain"]);
987
988 $SignupStatus = $GLOBALS["AF"]->SignalEvent(
989 "EVENT_USER_SIGNUP_VERIFY",
990 array(
991 "UserName" => $FormValues["F_UserName"],
992 "Password" => $FormValues["F_Password"],
993 "EMail" => $FormValues["F_EMail"],
994 "Status" => U_OKAY ));
995
996 if ($SignupStatus["Status"] !== U_OKAY)
997 {
998 $UserErrorCodes[]= $SignupStatus["Status"];
999 }
1000
1001 return $UserErrorCodes;
1002 }
1003
1004 # ---- PRIVATE INTERFACE -------------------------------------------------
1005 private $User;
1006 }
User\Get
Get($FieldName)
Definition: User.php:275
MetadataSchema\MDFTYPE_IMAGE
const MDFTYPE_IMAGE
Definition: MetadataSchema.php:31
UserEditingUI\GetActivationEmailSubstitutions
static GetActivationEmailSubstitutions($NewUser)
Retrieve the array of substitutions for new user activation mails.
Definition: UserEditingUI.php:786
File\FILESTAT_ZEROLENGTH
const FILESTAT_ZEROLENGTH
Definition: File.php:22
MetadataSchema\MDFTYPE_TIMESTAMP
const MDFTYPE_TIMESTAMP
Definition: MetadataSchema.php:25
U_EMPTYUSERNAME
const U_EMPTYUSERNAME
Definition: User.php:26
U_ILLEGALEMAILAGAIN
const U_ILLEGALEMAILAGAIN
Definition: User.php:32
MetadataSchema\MDFTYPE_FILE
const MDFTYPE_FILE
Definition: MetadataSchema.php:32
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
UserEditingUI\UpdateUserAttributes
UpdateUserAttributes(array $FormValues, $IsNewUser=FALSE, $UpdateUserEmail=FALSE)
Save user attributes that aren&#39;t stored in User Schema fields.
Definition: UserEditingUI.php:32
MetadataField\UPDATEMETHOD_ONRECORDCHANGE
const UPDATEMETHOD_ONRECORDCHANGE
Definition: MetadataField.php:22
AI_UNKNOWNTYPE
const AI_UNKNOWNTYPE
Definition: Image.php:555
UserEditingUI\TestUserValues
static TestUserValues($FormValues)
Check potential form values for a user including event signals.
Definition: UserEditingUI.php:981
FormUI_Base\FTYPE_OPTION
const FTYPE_OPTION
Definition: FormUI_Base.php:24
MetadataSchema\MDFTYPE_REFERENCE
const MDFTYPE_REFERENCE
Definition: MetadataSchema.php:35
U_EMAILSDONTMATCH
const U_EMAILSDONTMATCH
Definition: User.php:23
AI_OKAY
const AI_OKAY
Definition: Image.php:550
UserEditingUI\GetRequestAccountForm
static GetRequestAccountForm($ReadOnlyFields=array(), $FieldsToExclude=array(), $AdditionalFields=array())
Retrieve the array of Request Account Form information.
Definition: UserEditingUI.php:814
FormTool
Helps print and validate form fields, and their errors, associated with a form.
Definition: FormTool.php:14
U_EMPTYPASSWORD
const U_EMPTYPASSWORD
Definition: User.php:29
U_ILLEGALPASSWORDAGAIN
const U_ILLEGALPASSWORDAGAIN
Definition: User.php:28
MetadataSchema\MDFTYPE_NUMBER
const MDFTYPE_NUMBER
Definition: MetadataSchema.php:23
U_ILLEGALEMAIL
const U_ILLEGALEMAIL
Definition: User.php:31
FormUI_Base\FTYPE_TEXT
const FTYPE_TEXT
Definition: FormUI_Base.php:29
MetadataSchema\SCHEMAID_USER
const SCHEMAID_USER
Definition: MetadataSchema.php:55
User
Definition: User.php:48
UserEditingUI
Class supplying standard methods that process changes to user entered via HTML forms.
Definition: UserEditingUI.php:14
UserEditingUI\UploadImages
UploadImages($FormValues, $Files)
Process image upload requests for a user.
Definition: UserEditingUI.php:590
U_EMPTYPASSWORDAGAIN
const U_EMPTYPASSWORDAGAIN
Definition: User.php:30
MetadataSchema\MDFTYPE_TREE
const MDFTYPE_TREE
Definition: MetadataSchema.php:27
Date
Definition: Date.php:18
UserEditingUI\GetAdditionalErrorCodes
static GetAdditionalErrorCodes($UserName)
Get the list of account creation-related error messages.
Definition: UserEditingUI.php:964
MetadataSchema\MDFTYPE_OPTION
const MDFTYPE_OPTION
Definition: MetadataSchema.php:29
MetadataSchema\MDFTYPE_FLAG
const MDFTYPE_FLAG
Definition: MetadataSchema.php:26
MetadataSchema\MDFTYPE_CONTROLLEDNAME
const MDFTYPE_CONTROLLEDNAME
Definition: MetadataSchema.php:28
CWUserFactory
CWIS-specific user factory class.
Definition: CWUserFactory.php:13
User\GetStatusMessageForCode
static GetStatusMessageForCode($StatusCode)
Get text error message for a specified error code.
Definition: User.php:133
FormUI_Base\FTYPE_PASSWORD
const FTYPE_PASSWORD
Definition: FormUI_Base.php:26
U_EMPTYEMAIL
const U_EMPTYEMAIL
Definition: User.php:33
PHP
PHP
Definition: RSSClient--Test.php:12
User\Set
Set($FieldName, $NewValue)
Definition: User.php:307
FormUI_Base\FTYPE_USER
const FTYPE_USER
Definition: FormUI_Base.php:31
User\GetPasswordRulesDescription
static GetPasswordRulesDescription()
Get a string describing the password rules.
Definition: User.php:1276
SPTImage
Encapsulates a full-size, preview, and thumbnail image.
Definition: SPTImage.php:13
U_DUPLICATEUSERNAME
const U_DUPLICATEUSERNAME
Definition: User.php:24
U_OKAY
const U_OKAY
Definition: User.php:18
U_EMPTYEMAILAGAIN
const U_EMPTYEMAILAGAIN
Definition: User.php:34
U_DUPLICATEEMAIL
const U_DUPLICATEEMAIL
Definition: User.php:38
File\FILESTAT_OK
const FILESTAT_OK
Definition: File.php:19
MetadataSchema\MDFTYPE_PARAGRAPH
const MDFTYPE_PARAGRAPH
Definition: MetadataSchema.php:22
MetadataSchema\MDFTYPE_DATE
const MDFTYPE_DATE
Definition: MetadataSchema.php:24
MetadataSchema\MDFTYPE_URL
const MDFTYPE_URL
Definition: MetadataSchema.php:33
UserEditingUI\UploadFiles
UploadFiles($FormValues, $Files)
Process file upload requests.
Definition: UserEditingUI.php:509
User\Id
Id()
Definition: User.php:217
MetadataSchema\MDFTYPE_TEXT
const MDFTYPE_TEXT
Definition: MetadataSchema.php:21
MetadataSchema\MDFTYPE_USER
const MDFTYPE_USER
Definition: MetadataSchema.php:30
StdLib\GetUsStatesList
static GetUsStatesList()
Get an array of US state names with their two-letter abbreviations as the index.
Definition: StdLib.php:736
FormUI_Base\FTYPE_HEADING
const FTYPE_HEADING
Supported field pseudo-types.
Definition: FormUI_Base.php:33
U_ILLEGALUSERNAME
const U_ILLEGALUSERNAME
Definition: User.php:25
UserEditingUI\UpdateUserFields
UpdateUserFields(array $Fields)
Save updated values for fields from the User schema based on data supplised in HTML forms...
Definition: UserEditingUI.php:95
MetadataSchema\MDFTYPE_POINT
const MDFTYPE_POINT
Definition: MetadataSchema.php:34
File
Class representing a stored (usually uploaded) file.
Definition: File.php:13
UserEditingUI\UserFormHasErrors
static UserFormHasErrors(&$FTool, $UserErrorCodes, $ErrorMessages=NULL)
Determine if a user editing form has errors, setting error codes in the correspnding FormTool...
Definition: UserEditingUI.php:666
UserEditingUI\__construct
__construct($CWUser)
Set up a new UserEditingUI.
Definition: UserEditingUI.php:20
U_ILLEGALPASSWORD
const U_ILLEGALPASSWORD
Definition: User.php:27
AI_UNSUPPORTEDFORMAT
const AI_UNSUPPORTEDFORMAT
Definition: Image.php:556
U_PASSWORDSDONTMATCH
const U_PASSWORDSDONTMATCH
Definition: User.php:22