Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
W
webform_encrypt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
webform_encrypt
Commits
a4b0e6f8
Commit
a4b0e6f8
authored
May 16, 2011
by
Jake Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit.
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
154 additions
and
0 deletions
+154
-0
webform_encrypt.info
webform_encrypt.info
+11
-0
webform_encrypt.install
webform_encrypt.install
+36
-0
webform_encrypt.module
webform_encrypt.module
+107
-0
No files found.
webform_encrypt.info
0 → 100644
View file @
a4b0e6f8
name
=
Webform
Encrypt
description
=
Provides
encryption
for
webform
components
core
=
7.
x
package
=
Webform
files
[]
=
webform_encrypt
.
module
files
[]
=
webform_encrypt
.
install
dependencies
[]
=
aes
dependencies
[]
=
webform
webform_encrypt.install
0 → 100644
View file @
a4b0e6f8
<?php
/**
* Implementation of hook_schema()
*/
function
webform_encrypt_schema
()
{
$schema
[
'webform_encrypt'
]
=
array
(
'description'
=>
'Form metadata'
,
'fields'
=>
array
(
'cid'
=>
array
(
'description'
=>
'The component ID from webform'
,
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
),
'encrypt'
=>
array
(
'description'
=>
'Whether to encrypt the value'
,
'type'
=>
'int'
,
'size'
=>
'tiny'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
),
),
'unique keys'
=>
array
(
'cid'
=>
array
(
'cid'
),
),
);
return
$schema
;
}
/**
* Implementation of hook_uninstall().
*/
function
webform_encrypt_uninstall
()
{
drupal_uninstall_schema
(
'webform_encrypt'
);
}
webform_encrypt.module
0 → 100644
View file @
a4b0e6f8
<?php
/**
* Implementation of hook_permission().
*/
function
webform_encrypt_permission
()
{
return
array
(
'view encrypted values'
=>
array
(
'title'
=>
t
(
'View Encrypted Values in Webform Results'
),
'description'
=>
t
(
'Users that do not have this permission will see placeholder text.'
),
),
);
}
/**
* Implementation of hook_form_alter()
*/
function
webform_encrypt_form_alter
(
&
$form
,
$form_state
,
$form_id
)
{
// Add our fields to the component add/edit form.
if
(
$form_id
==
'webform_component_edit_form'
)
{
$profile
=
db_query
(
'SELECT * FROM {webform_encrypt} WHERE cid = ?'
,
array
(
$form
[
'cid'
][
'#value'
]))
->
fetchAssoc
();
// Add settings for security.
$form
[
'encryption'
]
=
array
(
'#type'
=>
'fieldset'
,
'#title'
=>
t
(
'Encryption'
),
'#tree'
=>
TRUE
,
);
$form
[
'encryption'
][
'encrypt'
]
=
array
(
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Encrypt this field\'s value'
),
'#description'
=>
t
(
'!link to edit encryption settings.'
,
array
(
'!link'
=>
l
(
'Click here'
,
'admin/settings/aes'
))),
'#default_value'
=>
isset
(
$profile
[
'encrypt'
])
?
$profile
[
'encrypt'
]
:
0
,
);
// Add new submit handler to save our config data.
array_unshift
(
$form
[
'#submit'
],
'_webform_encrypt_component_save'
);
}
}
/**
* Submit callback to save form component settings.
*/
function
_webform_encrypt_component_save
(
$form
,
$form_state
)
{
$record
=
new
StdClass
();
$record
->
cid
=
$form_state
[
'values'
][
'cid'
];
foreach
(
$form_state
[
'values'
][
'encryption'
]
as
$key
=>
$value
)
{
$record
->
$key
=
$value
;
}
drupal_write_record
(
'webform_encrypt'
,
$record
,
'cid'
);
}
/**
* Implementation of hook_node_load().
* Adding our extra data in to the webform component.
*/
function
webform_encrypt_node_load
(
$nodes
,
$types
)
{
// Abort if none of the nodes are webforms.
if
(
!
in_array
(
'webform'
,
$types
))
{
return
;
}
// Otherwise, let's loop through the nodes.
foreach
(
$nodes
as
$nid
=>
$node
)
{
$component_ids
=
array_keys
(
$node
->
webform
[
'components'
]);
$encrypt
=
db_select
(
'webform_encrypt'
,
'we'
)
->
fields
(
'we'
,
array
(
'cid'
,
'encrypt'
))
->
condition
(
'cid'
,
$component_ids
,
'IN'
)
->
execute
()
->
fetchAllKeyed
();
foreach
(
$node
->
webform
[
'components'
]
as
$cid
=>
$component
)
{
$node
->
webform
[
'components'
][
$cid
][
'encrypt'
]
=
$encrypt
[
$cid
];
}
}
}
/**
* Implementation of hook_webform_submission_presave().
* Encrypt the value if the component has been marked as such.
*/
function
webform_encrypt_webform_submission_presave
(
$node
,
&
$submission
)
{
foreach
(
$submission
->
data
as
$cid
=>
$entry
)
{
if
(
$node
->
webform
[
'components'
][
$cid
][
'encrypt'
])
{
$submission
->
data
[
$cid
][
'value'
][
0
]
=
aes_encrypt
(
$entry
[
'value'
][
0
]);
}
}
}
/**
* Implementation of hook_webform_submission_render_alter().
* Decrypt values when displaying webform submissions.
*/
function
webform_encrypt_webform_submission_render_alter
(
&
$renderable
)
{
foreach
(
$renderable
[
'#submission'
]
->
data
as
$cid
=>
$entry
)
{
if
(
$renderable
[
'#node'
]
->
webform
[
'components'
][
$cid
][
'encrypt'
])
{
$form_key
=
$renderable
[
'#node'
]
->
webform
[
'components'
][
$cid
][
'form_key'
];
if
(
user_access
(
'view encrypted values'
))
{
$renderable
[
$form_key
][
'#value'
]
=
aes_decrypt
(
$entry
[
'value'
][
0
]);
}
else
{
$renderable
[
$form_key
][
'#value'
]
=
t
(
'<Value Encrypted>'
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment