You are here

function webform_encrypt_encrypt_component_data in Webform Encrypt 7

Encrypt all non-encrypted data of a component.

1 call to webform_encrypt_encrypt_component_data()
webform_encrypt_webform_component_presave in ./webform_encrypt.module
Implementation of hook_webform_component_presave(). Save encryption settings for a component.

File

./webform_encrypt.module, line 139
Main module file for the Webform Encrypt module.

Code

function webform_encrypt_encrypt_component_data($nid = NULL, $cid = NULL, $extra = array()) {
  $results = db_query('SELECT nid, cid, extra FROM {webform_component} where nid = :nid AND cid = :cid', array(
    ':nid' => $nid,
    ':cid' => $cid,
  ))
    ->fetchAll();
  foreach ($results as $row) {
    $components[$row->nid . ':' . $row->cid] = unserialize($row->extra);
  }
  $data = db_query('SELECT nid, sid, cid, data FROM {webform_submitted_data} where nid = :nid AND cid = :cid', array(
    ':nid' => $nid,
    ':cid' => $cid,
  ))
    ->fetchAll();
  foreach ($data as $row) {
    $key = $row->nid . ':' . $row->cid;
    if (isset($components[$key]['encrypt']) && !$components[$key]['encrypt']) {
      db_update('webform_submitted_data')
        ->fields(array(
        'data' => encrypt($row->data, array(
          'base64' => TRUE,
        )),
      ))
        ->condition('nid', $row->nid)
        ->condition('sid', $row->sid)
        ->condition('cid', $row->cid)
        ->execute();
    }
  }
}