Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
cade4520
Commit
cade4520
authored
11 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Unify user util routines
parent
ad54dda1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ajax.forms.php
+11
-56
11 additions, 56 deletions
include/ajax.forms.php
include/class.user.php
+66
-7
66 additions, 7 deletions
include/class.user.php
with
77 additions
and
63 deletions
include/ajax.forms.php
+
11
−
56
View file @
cade4520
...
...
@@ -38,71 +38,26 @@ class DynamicFormsAjaxAPI extends AjaxController {
}
function
getUserInfo
(
$user_id
)
{
$user
=
User
::
lookup
(
$user_id
);
$data
=
$user
->
ht
;
$data
[
'email'
]
=
$user
->
default_email
->
address
;
$custom
=
array
();
foreach
(
$user
->
getDynamicData
()
as
$cd
)
{
$cd
->
addMissingFields
();
foreach
(
$cd
->
getFields
()
as
$f
)
{
if
(
$f
->
get
(
'name'
)
==
'name'
)
$f
->
value
=
$user
->
getFullName
();
elseif
(
$f
->
get
(
'name'
)
==
'email'
)
$f
->
value
=
$user
->
getEmail
();
}
$custom
[]
=
$cd
->
getForm
();
}
if
(
!
(
$user
=
User
::
lookup
(
$user_id
)))
Http
::
response
(
404
,
'Unknown user'
);
$custom
=
$user
->
getForms
();
include
(
STAFFINC_DIR
.
'templates/user-info.tmpl.php'
);
}
function
saveUserInfo
(
$user_id
)
{
$user
=
User
::
lookup
(
$user_id
);
$custom_data
=
$user
->
getDynamicData
();
$custom
=
array
();
$valid
=
true
;
foreach
(
$custom_data
as
$cd
)
{
$cd
->
addMissingFields
();
$cf
=
$custom
[]
=
$cd
->
getForm
();
$valid
&=
$cd
->
isValid
();
}
$errors
=
array
();
if
(
!
(
$user
=
User
::
lookup
(
$user_id
)))
Http
::
response
(
404
,
'Unknown user'
);
if
(
$valid
)
{
foreach
(
$custom_data
as
$cd
)
foreach
(
$cd
->
getFields
()
as
$f
)
if
(
$f
->
get
(
'name'
)
==
'email'
)
$email
=
$f
;
$u
=
User
::
lookup
(
array
(
'emails__address'
=>
$email
->
getClean
()));
if
(
$u
&&
$u
->
id
!=
$user_id
)
{
$valid
=
false
;
$email
->
addError
(
'Email is assigned to another user'
);
}
}
if
(
$user
->
updateInfo
(
$_POST
,
$errors
))
return
Http
::
response
(
201
,
$user
->
to_json
());
if
(
!
$valid
)
{
include
(
STAFFINC_DIR
.
'templates/user-info.tmpl.php'
);
return
;
}
// Save custom data
foreach
(
$custom_data
as
$cd
)
{
foreach
(
$cd
->
getFields
()
as
$f
)
{
if
(
$f
->
get
(
'name'
)
==
'name'
)
{
$user
->
name
=
$f
->
getClean
();
$user
->
save
();
}
elseif
(
$f
->
get
(
'name'
)
==
'email'
)
{
$user
->
default_email
->
address
=
$f
->
getClean
();
$user
->
default_email
->
save
();
}
}
$cd
->
save
();
}
return
Http
::
response
(
201
,
$user
->
to_json
());
$custom
=
$user
->
getForms
(
$_POST
);
include
(
STAFFINC_DIR
.
'templates/user-info.tmpl.php'
);
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
include/class.user.php
+
66
−
7
View file @
cade4520
...
...
@@ -88,14 +88,8 @@ class User extends UserModel {
));
$user
->
save
(
true
);
$user
->
emails
->
add
(
$user
->
default_email
);
// Attach initial custom fields
$uf
=
UserForm
::
getInstance
();
foreach
(
$uf
->
getFields
()
as
$f
)
if
(
isset
(
$data
[
$f
->
get
(
'name'
)]))
$uf
->
setAnswer
(
$f
->
get
(
'name'
),
$data
[
$f
->
get
(
'name'
)]);
$uf
->
setClientId
(
$user
->
id
);
$uf
->
save
();
$user
->
addDynamicData
(
$data
);
}
return
$user
;
...
...
@@ -142,6 +136,18 @@ class User extends UserModel {
return
$a
;
}
function
addDynamicData
(
$data
)
{
$uf
=
UserForm
::
getInstance
();
$uf
->
setClientId
(
$this
->
id
);
foreach
(
$uf
->
getFields
()
as
$f
)
if
(
isset
(
$data
[
$f
->
get
(
'name'
)]))
$uf
->
setAnswer
(
$f
->
get
(
'name'
),
$data
[
$f
->
get
(
'name'
)]);
$uf
->
save
();
return
$uf
;
}
function
getDynamicData
()
{
if
(
!
isset
(
$this
->
_entries
))
{
$this
->
_entries
=
DynamicFormEntry
::
forClient
(
$this
->
id
)
->
all
();
...
...
@@ -154,6 +160,57 @@ class User extends UserModel {
return
$this
->
_entries
;
}
function
updateInfo
(
$source
,
&
$errors
)
{
//Get forms and validate
$custom_data
=
$this
->
getDynamicData
();
$valid
=
true
;
foreach
(
$custom_data
as
$cd
)
{
$cd
->
addMissingFields
();
$valid
&=
$cd
->
isValid
();
}
if
(
!
$valid
)
return
false
;
// Save custom data
foreach
(
$custom_data
as
$cd
)
{
foreach
(
$cd
->
getFields
()
as
$f
)
{
if
(
$f
->
get
(
'name'
)
==
'name'
)
{
$this
->
name
=
$f
->
getClean
();
$this
->
save
();
}
elseif
(
$f
->
get
(
'name'
)
==
'email'
)
{
$this
->
default_email
->
address
=
$f
->
getClean
();
$this
->
default_email
->
save
();
}
}
$cd
->
save
();
}
return
true
;
}
function
getForms
(
$data
=
null
)
{
$forms
=
array
();
foreach
(
$this
->
getDynamicData
()
as
$cd
)
{
$cd
->
addMissingFields
();
if
(
$data
)
$cd
->
isValid
();
else
{
foreach
(
$cd
->
getFields
()
as
$f
)
{
if
(
$f
->
get
(
'name'
)
==
'name'
)
$f
->
value
=
$this
->
getFullName
();
elseif
(
$f
->
get
(
'name'
)
==
'email'
)
$f
->
value
=
$this
->
getEmail
();
}
}
$forms
[]
=
$cd
->
getForm
();
}
return
$forms
;
}
function
save
(
$refetch
=
false
)
{
// Drop commas and reorganize the name without them
$parts
=
array_map
(
'trim'
,
explode
(
','
,
$this
->
name
));
...
...
@@ -352,3 +409,5 @@ class UserEmail extends UserEmailModel {
return
$email
;
}
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment