1: <?php
2: /**
3: * Class QFormStateHandler
4: * This is the default FormState handler, storing the base64 encoded session data
5: * (and if requested by QForm, encrypted) as a hidden form variable on the page, itself. It is meant to be a "quick
6: * and dirty" handler that works in limited situations.
7: *
8: * We recommend that you do NOT use this formstate handler in general. It sends the entire formstate back and forth
9: * to the client browser on every server and ajax request, which is slow, and could potentially reach limits quickly. It
10: * encrypts the data, but there are still potential security problems if the data is sensitive.
11: *
12: * To change the formstate handler, define the __FORM_STATE_HANDLER__ in your configuration.inc.php file. See that
13: * file for more detail.
14: *
15: * This form state handler is NOT safe to use when making asynchronous AJAX calls. The reason is that since the entire
16: * formstate is sent to the browser, each ajax call must wait for the return trip to get the new formstate, before
17: * sending the formstate back to the server on the next ajax call.
18: */
19:
20: class QFormStateHandler extends QBaseClass {
21: public static function Save($strFormState, $blnBackButtonFlag) {
22: // Compress (if available)
23: if (function_exists('gzcompress'))
24: $strFormState = gzcompress($strFormState, 9);
25:
26: if (is_null(QForm::$EncryptionKey)) {
27: // Don't Encrypt the FormState -- Simply Base64 Encode it
28: $strFormState = base64_encode($strFormState);
29:
30: // Cleanup FormState Base64 Encoding
31: $strFormState = str_replace('+', '-', $strFormState);
32: $strFormState = str_replace('/', '_', $strFormState);
33: } else {
34: // Use QCryptography to Encrypt
35: $objCrypto = new QCryptography(QForm::$EncryptionKey, true);
36: $strFormState = $objCrypto->Encrypt($strFormState);
37: }
38: return $strFormState;
39: }
40:
41: public static function Load($strPostDataState) {
42: $strSerializedForm = $strPostDataState;
43:
44: if (is_null(QForm::$EncryptionKey)) {
45: // Cleanup from FormState Base64 Encoding
46: $strSerializedForm = str_replace('-', '+', $strSerializedForm);
47: $strSerializedForm = str_replace('_', '/', $strSerializedForm);
48:
49: $strSerializedForm = base64_decode($strSerializedForm);
50: } else {
51: // Use QCryptography to Decrypt
52: $objCrypto = new QCryptography(QForm::$EncryptionKey, true);
53: $strSerializedForm = $objCrypto->Decrypt($strSerializedForm);
54: }
55:
56: // Uncompress (if available)
57: if (function_exists('gzcompress'))
58: $strSerializedForm = gzuncompress($strSerializedForm);
59:
60: return $strSerializedForm;
61: }
62: }