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