Framework  3.9
signature_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
7 
15 {
16  var $errorMessage = "Your signature does not match your password. Please try again.";
17 
18  var $password = true;
19  var $autocomplete = false;
20  var $signatureField = "password";
21 
23  {
25  $this->password = true;
26  $this->autocomplete = false;
27  }
28 
29  function addValidatorsToForm($field, $required = false)
30  {
31  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
32 
33  $this->parent->validator->add(new SignatureValidator($field, $label, $this->errorMessage, $this->signatureField));
34  if ($required)
35  {
36  $this->parent->validator->add(new RequiredValidator($field, $label));
37  }
38  }
39 
46  {
47  $this->signatureField = $signatureField;
48  $this->errorMessage = $errorMessage;
49  }
50 
51  function renderField($field = "")
52  {
53  if ($this->parent->msg)
54  {
55  //Clear out field if the form is in error, to force user to re-enter
56  $this->parent->data->set($field, '');
57  }
58 
59  if ($this->parent->data->get($field))
60  {
61  $this->renderReadOnly($field);
62  }
63  else
64  {
65  parent::renderField($field);
66  }
67  }
68 
69  function renderReadOnly($field = "")
70  {
71  if (!$field) $field = $this->field;
72  $value = $this->parent->data->get($field);
73  list($signature,$date,$user_id) = explode(":", $value);
74 
75  if ($user_id)
76  {
77  try
78  {
79  $mgr = new UserManager();
80  $u = $mgr->getUser($user_id);
81  $msg = "Signed by ".$mgr->getUserFullName($u)." on $date";
82  }
83  catch(Exception $e)
84  {
85  $msg = "Invalid Signature";
86  }
87  }
88  else
89  {
90  $msg = "Not signed";
91  }
92 
93  $this->_startField($field);
94 
95  echo $msg;
96 
97  $this->_endField($field);
98  }
99 
100  function preProcess($field = "")
101  {
102  global $user;
103 
104  if (!$_POST[$field]) return;
105 
106  $obj = $this->parent->data;
107  if ($this->signatureField == "password")
108  {
109  $obj->set($field, $user->hashPassword($_POST[$field]).":".today().":".$user->get($user->getPrimaryKey()));
110  }
111  else
112  {
113  $obj->set($field, $_POST[$field]).":".today().":".$user->get($user->getPrimaryKey());
114  }
115  }
116 }
117 
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
RequiredField Validator.
Definition: validation.inc:76
Provides a very simple digital signature implementation.
$signatureField
The field to check for a match when signing.
$autocomplete
Whether to allow autocomplete.
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...
setSignatureField($signatureField, $errorMessage)
Overrides the default field used to match when signing.
$password
Whether to mask the input in the signature field.
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
renderField($field="")
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
Validates that the user's supplied password is correct.
Field renderer for string data fields.
today()
Returns today as a string.
Definition: functions.inc:424