Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
e2d122cd
Commit
e2d122cd
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Make phone number field configurable
Fixes #23
parent
7761b165
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.forms.php
+46
-9
46 additions, 9 deletions
include/class.forms.php
with
46 additions
and
9 deletions
include/class.forms.php
+
46
−
9
View file @
e2d122cd
...
@@ -500,27 +500,58 @@ class TextareaField extends FormField {
...
@@ -500,27 +500,58 @@ class TextareaField extends FormField {
class
PhoneField
extends
FormField
{
class
PhoneField
extends
FormField
{
static
$widget
=
'PhoneNumberWidget'
;
static
$widget
=
'PhoneNumberWidget'
;
function
getConfigurationOptions
()
{
return
array
(
'ext'
=>
new
BooleanField
(
array
(
'label'
=>
'Extension'
,
'default'
=>
true
,
'configuration'
=>
array
(
'desc'
=>
'Add a separate field for the extension'
,
),
)),
'digits'
=>
new
TextboxField
(
array
(
'label'
=>
'Minimum length'
,
'default'
=>
7
,
'hint'
=>
'Fewest digits allowed in a valid phone number'
,
'configuration'
=>
array
(
'validator'
=>
'number'
,
'size'
=>
5
),
)),
'format'
=>
new
ChoiceField
(
array
(
'label'
=>
'Display format'
,
'default'
=>
'us'
,
'choices'
=>
array
(
''
=>
'-- Unformatted --'
,
'us'
=>
'United States'
),
)),
);
}
function
validateEntry
(
$value
)
{
function
validateEntry
(
$value
)
{
parent
::
validateEntry
(
$value
);
parent
::
validateEntry
(
$value
);
$config
=
$this
->
getConfiguration
();
# Run validator against $this->value for email type
# Run validator against $this->value for email type
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$value
,
2
);
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$value
,
2
);
if
(
$phone
&&
!
Validator
::
is_phone
(
$phone
))
if
(
$phone
&&
(
!
is_numeric
(
$phone
)
||
strlen
(
$phone
)
<
$config
[
'digits'
]))
$this
->
_errors
[]
=
"Enter a valid phone number"
;
$this
->
_errors
[]
=
"Enter a valid phone number"
;
if
(
$ext
)
{
if
(
$ext
&&
$config
[
'ext'
]
)
{
if
(
!
is_numeric
(
$ext
))
if
(
!
is_numeric
(
$ext
))
$this
->
_errors
[]
=
"Enter a valid
e
phone extension"
;
$this
->
_errors
[]
=
"Enter a valid phone extension"
;
elseif
(
!
$phone
)
elseif
(
!
$phone
)
$this
->
_errors
[]
=
"Enter a phone number for the extension"
;
$this
->
_errors
[]
=
"Enter a phone number for the extension"
;
}
}
}
}
function
to_database
(
$value
)
{
function
parse
(
$value
)
{
return
preg_replace
(
'/[()+. -]/'
,
''
,
$value
);
// NOTE: Value may have a legitimate 'X' to separate the number and
// extension parts. Don't remove the 'X'
return
preg_replace
(
'/[^\dX]/'
,
''
,
$value
);
}
}
function
toString
(
$value
)
{
function
toString
(
$value
)
{
$config
=
$this
->
getConfiguration
();
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$value
,
2
);
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$value
,
2
);
$phone
=
Format
::
phone
(
$phone
);
switch
(
$config
[
'format'
])
{
case
'us'
:
$phone
=
Format
::
phone
(
$phone
);
break
;
}
if
(
$ext
)
if
(
$ext
)
$phone
.
=
" x
$ext
"
;
$phone
.
=
" x
$ext
"
;
return
$phone
;
return
$phone
;
...
@@ -569,7 +600,7 @@ class ChoiceField extends FormField {
...
@@ -569,7 +600,7 @@ class ChoiceField extends FormField {
if
(
is_numeric
(
$value
))
if
(
is_numeric
(
$value
))
return
$value
;
return
$value
;
foreach
(
$this
->
getChoices
()
as
$k
=>
$v
)
foreach
(
$this
->
getChoices
()
as
$k
=>
$v
)
if
(
strcasecmp
(
$value
,
$
v
)
===
0
)
if
(
strcasecmp
(
$value
,
$
k
)
===
0
)
return
$k
;
return
$k
;
}
}
...
@@ -828,12 +859,17 @@ class TextareaWidget extends Widget {
...
@@ -828,12 +859,17 @@ class TextareaWidget extends Widget {
class
PhoneNumberWidget
extends
Widget
{
class
PhoneNumberWidget
extends
Widget
{
function
render
()
{
function
render
()
{
$config
=
$this
->
field
->
getConfiguration
();
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$this
->
value
);
list
(
$phone
,
$ext
)
=
explode
(
"X"
,
$this
->
value
);
?>
?>
<input
type=
"text"
name=
"
<?php
echo
$this
->
name
;
?>
"
value=
"
<?php
<input
type=
"text"
name=
"
<?php
echo
$this
->
name
;
?>
"
value=
"
<?php
echo
$phone
;
?>
"
/>
Ext:
<input
type=
"text"
name=
"
<?php
echo
$phone
;
?>
"
/>
<?php
// Allow display of extension field even if disabled if the phone
// number being edited has an extension
if
(
$ext
||
$config
[
'ext'
])
{
?>
Ext:
<input
type=
"text"
name=
"
<?php
echo
$this
->
name
;
?>
-ext"
value=
"
<?php
echo
$ext
;
?>
"
size=
"5"
/>
echo
$this
->
name
;
?>
-ext"
value=
"
<?php
echo
$ext
;
?>
"
size=
"5"
/>
<?php
<?php
}
}
}
function
getValue
()
{
function
getValue
()
{
...
@@ -842,6 +878,7 @@ class PhoneNumberWidget extends Widget {
...
@@ -842,6 +878,7 @@ class PhoneNumberWidget extends Widget {
if
(
$base
===
null
)
if
(
$base
===
null
)
return
$base
;
return
$base
;
$ext
=
$data
[
"
{
$this
->
name
}
-ext"
];
$ext
=
$data
[
"
{
$this
->
name
}
-ext"
];
// NOTE: 'X' is significant. Don't change it
if
(
$ext
)
$ext
=
'X'
.
$ext
;
if
(
$ext
)
$ext
=
'X'
.
$ext
;
return
$base
.
$ext
;
return
$base
.
$ext
;
}
}
...
...
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