-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnsessionapi.php
284 lines (257 loc) · 7.89 KB
/
pnsessionapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
* FEproc - Mail template backend module for FormExpress for
* Zikula Content Management System
*
* @copyrightt (C) 2002 by Jason Judge, 2011 Chris Candreva
* @Version $Id: tables.php 84 2011-05-27 18:19:28Z ccandreva $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package FEproc
*
*
* LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WIthOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* To read the license please visit http://www.gnu.org/copyleft/gpl.html
* ----------------------------------------------------------------------
* Original Author of file: Jason Judge.
* Based on template by Jim MacDonald.
* Current Maintainer of file: Chris Candreva <[email protected]>
* ----------------------------------------------------------------------
*
*/
class feprocSession {
/**
* $forms is an array of the form(s) user data
*/
var $formdata;
var $currentSet;
var $messages;
/** ****************************************************************************
* Constructor
* Gets the session variables
*/
function feprocSession() {
$this->formdata = pnSessionGetVar('FEprocFormData');
if (empty($this->formdata))
{
$this->formdata = Array();
pnSessionSetVar('FEprocFormData', $this->formdata);
}
$this->currentSet = pnSessionGetVar('FEprocCurrentSet');
if (empty($this->currentSet))
{
$this->currentSet = Array(
'setid' => false,
'stageid' => false,
'starttime' => false,
'trxid' => false
);
}
$this->messages = pnSessionGetVar('FEprocMessages');
if (empty($this->messages))
{
$this->messages = Array();
pnSessionSetVar('FEprocMessages', $this->messages);
}
}
/*
* Get the timestamp when the session started.
*/
function getSessionStart()
{
if (! $this->currentSet['starttime'])
{
return false;
} else {
return $this->currentSet['starttime'];
}
}
/*
* Get the current set ID or false if a set is not running.
*/
function getSetID() {
if (! $this->currentSet['setid'])
{
return false;
} else {
return $this->currentSet['setid'];
}
}
/*
* Get the current set ID or false if a set is not running.
*/
function getTRXID() {
if (! $this->currentSet['trxid'])
{
return false;
} else {
return $this->currentSet['trxid'];
}
}
/*
* Get the current messages array.
*/
function getMessages() {
if (! $this->messages)
{
return false;
} else {
return $this->messages;
}
}
/*
* Set a message or messages.
*
*/
function setMessages($messages, $append = false) {
// Parameter is:
// Array('name1' => 'value1' [,'name2' => 'value2', ...])
// If $append is true, then value will be concatenated with
// existing message that may exist.
if (is_array($messages))
{
foreach($messages as $name => $message)
{
// Append if required, otherwise just set it.
$this->messages[$name] = (($append && $this->messages[$name]) ? $message ."\n". $this->messages[$name] : $message);
}
pnSessionSetVar('FEprocMessages', $this->messages);
}
return true;
}
/*
* Get the current stage ID or false if a set is not running.
*/
function getStageID() {
if (! $this->currentSet['stageid'])
{
return false;
} else {
return $this->currentSet['stageid'];
}
}
/*
* Get the actual starting stage for the current set.
* This is initialised when the set is initiated.
*/
function getStartStageID() {
if (! $this->currentSet['startstageid'])
{
return false;
} else {
return $this->currentSet['startstageid'];
}
}
/*
* Set the current stage ID or false if a set is not running.
*/
function putStageID($stageid) {
if (is_numeric($stageid))
{
$this->currentSet['stageid'] = $stageid;
pnSessionSetVar('FEprocCurrentSet', $this->currentSet);
}
return true;
}
/*
* Start a new set running. This also closes any existing set that
* may be running.
*/
function startSet($setid, $stageid) {
if (is_numeric($setid) && is_numeric($stageid))
{
// At the start of a set, the set and the stage are the same.
$this->currentSet = Array();
$this->currentSet['setid'] = $setid;
$this->currentSet['stageid'] = $stageid;
$this->currentSet['startstageid'] = $stageid;
// Save the start time so session can time out if necessary.
$this->currentSet['starttime'] = time();
// Create an ID for the transaction.
$this->currentSet['trxid'] = time();
pnSessionSetVar('FEprocCurrentSet', $this->currentSet);
// Clear any old form data in the session.
$this->formdata = Array();
pnSessionSetVar('FEprocFormData', $this->formdata);
// Set the first stack message if required.
if (pnModGetVar('FEproc', 'tracestack'))
{
$this->setMessages(Array('stack' => "Start: set $setid; stage $stageid"), true);
}
return true;
} else {
return false;
}
}
/*
* Add the contents of a submitted form.
* The content is an array of name/value pairs, keyed on the name.
*/
function addFormData($formdata) {
$this->formdata = pnSessionGetVar('FEprocFormData');
if (!is_array($this->formdata))
{
$this->formdata = Array();
}
if (is_array($formdata))
{
foreach ($formdata as $key => $item)
{
$this->formdata[$key] = $item;
}
}
// Store the updated form data in the session.
pnSessionSetVar('FEprocFormData', $this->formdata);
}
/*
* Get the contents of all submitted forms.
* The content is an array of name/value pairs, keyed on the name.
*/
function getFormData()
{
if(empty($this->formdata))
{
return false;
} else {
return $this->formdata;
}
}
/*
* Close the session completely and remove all session variables.
*/
function closeSession()
{
$this->formdata = false;
pnSessionDelVar('FEprocFormData');
$this->currentset = false;
pnSessionDelVar('FEprocCurrentSet');
$this->messages = false;
pnSessionSetVar('FEprocMessages', $this->messages);
// Clear FormExpress data.
if (pnModLoad('FormExpress', 'user'))
{
$fxSession = new FXSession();
// Loop for all FormExpress forms and clear them down.
$allforms = $fxSession->getForms();
if (is_array($allforms))
{
foreach ($allforms as $formid => $form)
{
$fxSession->delForm($formid);
}
}
}
return true;
}
}
?>