-
Notifications
You must be signed in to change notification settings - Fork 988
/
fck_LimeReplacementFields.php
410 lines (366 loc) · 15 KB
/
fck_LimeReplacementFields.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/
include_once("login_check.php");
if(!isset($_SESSION['loginID']))
{
die ("Unauthenticated Access Forbiden");
}
$surveyid=returnglobal('sid');
if (!isset($gid)) {$gid=returnglobal('gid');}
if (!isset($qid)) {$qid=returnglobal('qid');}
$fieldtype=preg_replace("/[^_.a-zA-Z0-9-]/", "",$_GET['fieldtype']);
$action=preg_replace("/[^_.a-zA-Z0-9-]/", "",$_GET['editedaction']);
//$InsertansUnsupportedtypes=Array('TEST-A','TEST-B','TEST-C','TEST-D');
$InsertansUnsupportedtypes=Array(); // Currently all question types are supported
$replFields=Array();
$isInstertansEnabled=false;
$limereplacementoutput="\t\t<script language=\"javascript\">\n"
. "\t\t\$(document).ready(function ()\n"
. "\t\t\t{\n"
. "\t\t\t\tLoadSelected() ;\n"
. "\t\t\t\tmydialog.SetOkButton( true ) ;\n"
. "\n"
. "SelectField( 'cquestions' ) ;\n"
. "\t});\n"
. "\n";
/**$limereplacementoutput="\n"
. "if (! oEditor.FCKBrowserInfo.IsIE)\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorWindow.getSelection() + '' ;\n"
. "}\n"
. "else\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorDocument.selection.createRange().text + '' ;\n"
. "}\n";
**/
$limereplacementoutput .= ""
. "\tvar eSelected = dialog.Selection.GetSelectedElement() ;\n"
. "\n";
/**
$limereplacementoutput="\n"
. "function LoadSelected()\n"
. "{\n"
. "\tif ( innertext == '' )\n"
. "return ;\n"
. "var replcode=innertext.substring(innertext.indexOf('{')+1,innertext.lastIndexOf('}'));\n"
. "document.getElementById('cquestions').value = replcode;\n"
. "}\n";
**/
$limereplacementoutput .= ""
. "\tfunction LoadSelected()\n"
. "\t{\n"
. "if ( !eSelected )\n"
. "\treturn ;\n"
. "if ( eSelected.tagName == 'SPAN' && eSelected._fckLimeReplacementFields )\n"
. "\t document.getElementById('cquestions').value = eSelected._fckLimeReplacementFields ;\n"
. "else\n"
. "\teSelected == null ;\n"
. "\t}\n";
$limereplacementoutput .= ""
. "\tfunction Ok()\n"
. "\t{\n"
. "var sValue = document.getElementById('cquestions').value ;\n"
. "FCKLimeReplacementFieldss.Add( sValue ) ;\n"
. "return true ;\n"
. "\t}\n";
$limereplacementoutput .= ""
. "\t</script>\n"
. "</head>\n";
$limereplacementoutput .= "\t<body scroll=\"no\" style=\"OVERFLOW: hidden;\">\n"
. "<table height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n"
. "\t<tr>\n"
. "<td>\n";
switch ($fieldtype)
{
case 'survey-desc':
case 'survey-welc':
case 'survey-endtext':
case 'edittitle': // for translation
case 'editdescription': // for translation
case 'editwelcome': // for translation
case 'editend': // for translation
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array('TOKEN:'.strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
break;
case 'email-admin-conf':
case 'email-admin-resp':
$replFields[]=array('RELOADURL',$clang->gT("Reload URL"));
$replFields[]=array('VIEWRESPONSEURL',$clang->gT("View response URL"));
$replFields[]=array('EDITRESPONSEURL',$clang->gT("Edit response URL"));
$replFields[]=array('STATISTICSURL',$clang->gT("Statistics URL"));
$replFields[]=array('ANSWERTABLE',$clang->gT("Answers from this response"));
case 'email-inv':
case 'email-rem':
// these 2 fields are supported by email-inv and email-rem
// but not email-reg for the moment
$replFields[]=array('EMAIL',$clang->gT("Email from the token"));
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('OPTOUTURL',$clang->gT("URL for a respondent to opt-out this survey"));
case 'email-reg':
$replFields[]=array('FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
$replFields[]=array('SURVEYURL',$clang->gT("URL of the survey"));
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
break;
case 'email-conf':
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
$replFields[]=array('SURVEYURL',$clang->gT("URL of the survey"));
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
// email-conf can accept insertans fields for non anonymous surveys
if (isset($surveyid))
{
$surveyInfo = getSurveyInfo($surveyid);
if ($surveyInfo['anonymized'] == "N")
{
$isInstertansEnabled=true;
}
}
break;
case 'group-desc':
case 'question-text':
case 'question-help':
case 'editgroup': // for translation
case 'editgroup_desc': // for translation
case 'editquestion': // for translation
case 'editquestion_help': // for translation
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array('TOKEN:'.strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
case 'editanswer':
$isInstertansEnabled=true;
break;
case 'assessment-text':
$replFields[]=array('TOTAL',$clang->gT("Overall assessment score"));
$replFields[]=array('PERC',$clang->gT("Assessment group score"));
break;
}
if ($isInstertansEnabled===true)
{
if (empty($surveyid)) {safe_die("No SID provided.");}
//2: Get all other questions that occur before this question that are pre-determined answer types
$fieldmap = createFieldMap($surveyid, 'full');
$surveyInfo = getSurveyInfo($surveyid);
$surveyformat = $surveyInfo['format'];// S, G, A
$prevquestion=null;
$previouspagequestion = true;
//Go through each question until we reach the current one
//error_log(print_r($qrows,true));
$questionlist=array();
foreach ($fieldmap as $field)
{
if (empty($field['qid'])) continue;
$AddQuestion=True;
switch ($action)
{
case 'addgroup':
$AddQuestion=True;
break;
case 'editgroup':
case 'editgroup_desc':
case 'translategroup':
if (empty($gid)) {safe_die("No GID provided.");}
if ($field['gid'] == $gid)
{
$AddQuestion=False;
}
break;
case 'addquestion':
if (empty($gid)) {safe_die("No GID provided.");}
if ( !is_null($prevquestion) &&
$prevquestion['gid'] == $gid &&
$field['gid'] != $gid)
{
$AddQuestion=False;
}
break;
case 'editanswer':
case 'copyquestion':
case 'editquestion':
case 'translatequestion':
case 'translateanswer':
if (empty($gid)) {safe_die("No GID provided.");}
if (empty($qid)) {safe_die("No QID provided.");}
if ($field['gid'] == $gid &&
$field['qid'] == $qid)
{
$AddQuestion=False;
}
break;
case 'emailtemplates':
// this is the case for email-conf
$AddQuestion=True;
break;
default:
safe_die("No Action provided.");
break;
}
if ( $AddQuestion===True)
{
if ($action == 'tokens' && $fieldtype == 'email-conf')
{
//For confirmation email all fields are valid
$previouspagequestion = true;
}
elseif ($surveyformat == "S")
{
$previouspagequestion = true;
}
elseif ($surveyformat == "G")
{
if ($previouspagequestion === true)
{ // Last question was on a previous page
if ($field["gid"] == $gid)
{ // This question is on same page
$previouspagequestion = false;
}
}
}
elseif ($surveyformat == "A")
{
$previouspagequestion = false;
}
$questionlist[]=array_merge($field,Array( "previouspage" => $previouspagequestion));
$prevquestion=$field;
}
else
{
break;
}
}
$questionscount=count($questionlist);
if ($questionscount > 0)
{
foreach($questionlist as $rows)
{
$question = $rows['question'];
if (isset($rows['subquestion'])) $question = "[{$rows['subquestion']}] " . $question;
if (isset($rows['subquestion1'])) $question = "[{$rows['subquestion1']}] " . $question;
if (isset($rows['subquestion2'])) $question = "[{$rows['subquestion2']}] " . $question;
$shortquestion=$rows['title'].": ".FlattenText($question);
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['fieldname'],$rows['previouspage']);
} //foreach questionlist
} //if questionscount > 0
// Now I´ll add a hack to add the questions before as option
// if they are date type
}
if (count($replFields) > 0 || isset($cquestions) )
{
$limereplacementoutput .= "\t<select name='cquestions' id='cquestions' style='font-family:verdana; background-color: #FFFFFF; font-size:10; border: 0px;width:99%;' size='15' ondblclick='Ok();'>\n";
$noselection = false;
}
else
{
$limereplacementoutput .= $clang->gT("No replacement variable available for this field");
$noselection = true;
}
if (count($replFields) > 0)
{
$limereplacementoutput .= "<optgroup label='".$clang->gT("Standard Fields")."'>\n";
foreach ($replFields as $stdfield)
{
$limereplacementoutput .= "\t<option value='".$stdfield[0]."' title='".$stdfield[1]."'";
$limereplacementoutput .= ">".$stdfield[1]."</option>\n";
}
$limereplacementoutput .= "</optgroup>\n";
}
if (isset($cquestions))
{
$limereplacementoutput .= "<optgroup label='".$clang->gT("Previous Answers Fields")."'>\n";
foreach ($cquestions as $cqn)
{
$isDisabled="";
if (in_array($cqn[2],$InsertansUnsupportedtypes))
{
$isDisabled=" disabled='disabled'";
}
elseif ($cqn[4] === false)
{
$isDisabled=" disabled='disabled'";
}
$limereplacementoutput .= "\t<option value='INSERTANS:$cqn[3]' title='".$cqn[0]."'";
$limereplacementoutput .= " $isDisabled >$cqn[0]</option>\n";
}
$limereplacementoutput .= "</optgroup>\n";
}
if ($noselection === false)
{
$limereplacementoutput .= "\t</select>\n";
}
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
if (isset($surveyformat))
{
switch ($surveyformat)
{
case 'A':
$limereplacementoutput .= "\t<tr>\n"
. "<td>\n";
$limereplacementoutput .= "\t<br />\n"
. "\t<font color='orange'>".$clang->gT("Some Question have been disabled")."</font>\n";
$limereplacementoutput .= "\t<br />\n"
. "\t".sprintf($clang->gT("Survey Format is %s:"), $clang->gT("All in one"))
. "\t<br />\n"
. "\t<i>".$clang->gT("Only Previous pages answers are available")."</i>\n"
. "\t<br />\n";
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
break;
case 'G':
$limereplacementoutput .= "\t<tr>\n"
. "<td>\n";
$limereplacementoutput .= "\t<br /><font color='orange'>".$clang->gT("Some Question have been disabled")."</font>";
$limereplacementoutput .= "<br />".sprintf($clang->gT("Survey mode is set to %s:"), $clang->gT("Group by Group"))."<br/><i>".$clang->gT("Only Previous pages answers are available")."</i><br />";
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
break;
}
}
$limereplacementoutput .= "</table>\n";
echo $limereplacementoutput;
exit;
?>