-
Notifications
You must be signed in to change notification settings - Fork 986
/
lsrc.helper.php
2461 lines (2157 loc) · 110 KB
/
lsrc.helper.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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$
*
*/
/**
* @author Wahrendorff
*
*/
class LsrcHelper {
/**
* simple debug function to make life a bit easier
*
* @param string $text
*/
function debugLsrc($text)
{
include("lsrc.config.php");
if($lsrcDebug)
{
error_log("\n".date("Y-m-d H:i:s")." ".$text, 3 , $lsrcDebugLog);
}
return;
}
/**
* function to get the id of the surveyowner
*
* @param unknown_type $iVid
* @return unknown
*/
function getSurveyOwner($iVid)
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
//$this= new LsrcHelper();
if($this->surveyExists($iVid))
{
$query2num = "SELECT owner_id FROM {$dbprefix}surveys WHERE sid=".sanitize_int($iVid)."";
$rs = db_execute_assoc($query2num);
$field=$rs->FetchRow();
return $field['owner_id'];
}else{return false;}
}
/**
* This function changes data in LS-DB, its very sensitive, because every table can be changed.
*
* @param unknown_type $table
* @param unknown_type $key
* @param unknown_type $value
* @param unknown_type $where
* @return String
*/
function changeTable($table, $key, $value, $where, $mode='0')//XXX
{//be aware that this function may be a security risk
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
if($mode=='' || !isset($mode) || $mode=='0')
{
$where = str_replace("\\","",$where);
$query2num = "SELECT {$key} FROM {$dbprefix}{$table} WHERE {$where}";
$rs = db_execute_assoc($query2num);
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ($query2num)");
$query2update = "update ".$dbprefix.$table." set ".$key."='".$value."' where ".$where."";
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ($query2update)");
if($connect->Execute($query2update)){
return $rs->RecordCount()." Rows changed";
}
else{
return "nothing changed";
}
}
if($mode==1 || $mode=='1')
{
$query2insert = "INSERT INTO {$dbprefix}{$table} ({$key}) VALUES ({$value});";
$this->debugLsrc("wir sind in Line ".__LINE__.", inserting ($query2insert)");
if($connect->Execute($query2insert))
{
$this->debugLsrc("wir sind in Line ".__LINE__.", inserting OK");
return true;
}
else
{
return false;
}
}
}
/**
*
* Enter description here...
* @param $surveyid
* @param $type
* @param $maxLsrcEmails
* @return unknown_type
*/
function emailSender($surveyid, $type, $maxLsrcEmails='') //XXX
{
global $publicurl,$maxemails;
global $connect,$sitename ;
global $dbprefix ;
$surveyid = sanitize_int($surveyid);
include("lsrc.config.php");
// wenn maxmails ber den lsrc gegeben wird das nutzen, ansonsten die default werte aus der config.php
if($maxLsrcEmails!='')
$maxemails = $maxLsrcEmails;
switch ($type){
case "custom":
break;
case "invite":
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START invite ");
if(isset($surveyid) && getEmailFormat($surveyid) == 'html')
{
$ishtml=true;
}
else
{
$ishtml=false;
}
//$tokenoutput .= ("Sending Invitations");
//if (isset($tokenid)) {$tokenoutput .= " (".("Sending to Token ID").": {$tokenid})";}
//$tokenoutput .= "\n";
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", $surveyid, $type");
// Texte für Mails aus der Datenbank holen und in die POST Dinger schreiben. Nicht schön aber praktikabel
$sql = "SELECT surveyls_language, surveyls_email_invite_subj, surveyls_email_invite ".
"FROM {$dbprefix}surveys_languagesettings ".
"WHERE surveyls_survey_id = ".$surveyid." ";
//GET SURVEY DETAILS
$thissurvey=getSurveyInfo($surveyid);
// $connect->SetFetchMode(ADODB_FETCH_ASSOC);
// $sqlResult=$connect->Execute($sql);
$sqlResult = db_execute_assoc($sql);
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
while($languageRow = $sqlResult->FetchRow())
{
$_POST['message_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_invite'];
$_POST['subject_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_invite_subj'];
}
// if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y')
// {
// $SQLemailstatuscondition = " AND emailstatus = 'OK'";
// }
// else
// {
// $SQLemailstatuscondition = "";
// }
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
$ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' ";
if (isset($tokenid)) {$ctquery .= " AND tid='{$tokenid}'";}
//$tokenoutput .= "<!-- ctquery: $ctquery -->\n";
$ctresult = $connect->Execute($ctquery);
$ctcount = $ctresult->RecordCount();
$ctfieldcount = $ctresult->FieldCount();
$emquery = "SELECT * ";
//if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
$emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' ";
if (isset($tokenid)) {$emquery .= " and tid='{$tokenid}'";}
//$tokenoutput .= "\n\n<!-- emquery: $emquery -->\n\n";
$emresult = db_select_limit_assoc($emquery,$maxemails);
$emcount = $emresult->RecordCount();
//$tokenoutput .= "<table width='500px' align='center' >\n"
////."\t<tr>\n"
//."\t\t<td><font size='1'>\n";
$surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselanguage = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($surveylangs,$baselanguage);
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
foreach ($surveylangs as $language)
{
$_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]);
$_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]);
if ($ishtml) $_POST['message_'.$language] = html_entity_decode($_POST['message_'.$language], ENT_QUOTES, $emailcharset);
}
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
if ($emcount > 0)
{
$mailsSend = 0;
while ($emrow = $emresult->FetchRow())
{
$c=1;
unset($fieldsarray);
$to = $emrow['email'];
$fieldsarray["{EMAIL}"]=$emrow['email'];
$fieldsarray["{FIRSTNAME}"]=$emrow['firstname'];
$fieldsarray["{LASTNAME}"]=$emrow['lastname'];
$fieldsarray["{TOKEN}"]=$emrow['token'];
$fieldsarray["{LANGUAGE}"]=$emrow['language'];
while(isset($emrow["attribute_$c"]))
{
$fieldsarray["{ATTRIBUTE_$c}"]=$emrow["attribute_$c"];
++$c;
}
$fieldsarray["{ADMINNAME}"]= $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
$fieldsarray["{EXPIRY}"]=$thissurvey["expiry"];
$emrow['language']=trim($emrow['language']);
if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default
$found = array_search($emrow['language'], $surveylangs);
if ($found==false) {$emrow['language']=$baselanguage;}
$from = $thissurvey['adminemail'];
if ($ishtml === false)
{
if ( $modrewrite )
{
$fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}";
}
else
{
$fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}";
}
}
else
{
if ( $modrewrite )
{
$fieldsarray["{SURVEYURL}"]="<a href='$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}'>".htmlspecialchars("$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}")."</a>";
}
else
{
$fieldsarray["{SURVEYURL}"]="<a href='$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}'>".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}")."</a>";
}
}
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
$modsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray);
$modmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray);
if (SendEmailMessage($modmessage, $modsubject, $to , $from, $sitename, $ishtml, getBounceEmail($surveyid)))
{
// Put date into sent
//$timeadjust = 0;
$today = date("Y-m-d H:i");
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite Today:".$today);
$udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n"
."SET sent='$today' WHERE tid={$emrow['tid']}";
//
$uderesult = $connect->Execute($udequery);
$mailsSend++;
//$tokenoutput .= "[".("Invitation sent to:")."{$emrow['firstname']} {$emrow['lastname']} ($to)]\n";
}
else
{
//$tokenoutput .= ReplaceFields(("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."", $fieldsarray);
if($n==1)
$failedAddresses .= ",".$to;
else
{
$failedAddresses = $to;
$n=1;
}
}
}
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
if ($ctcount > $emcount)
{
$lefttosend = $ctcount-$maxemails;
}else{$lefttosend = 0;}
}
else
{
return "No Mails to send";
}
if($maxemails>0 && $maxemails!='')
{
$returnValue = "".$mailsSend." Mails send. ".$lefttosend." Mails left to send";
if(isset($failedAddresses))
$returnValue .= "\nCould not send to: ".$failedAddresses;
return $returnValue;
}
if(isset($mailsSend))
{
$returnValue = "".$mailsSend." Mails send. ";
if(isset($failedAddresses))
$returnValue .= "\nCould not send to: ".$failedAddresses;
return $returnValue;
}
break;
case "remind":
// XXX:
// TODO:
// if (!isset($_POST['ok']) || !$_POST['ok'])
// {
/*
* look if there were reminders send in the past, and if some tokens got lesser reminders than others
*
* - if so: send reminders to the unremindet participants until they got the same remindcount than the others
* - if not: send reminders normally
*/
$remSQL = "SELECT tid, remindercount "
. "FROM ".db_table_name("tokens_{$surveyid}")." "
. "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' "
. "ORDER BY remindercount desc LIMIT 1";
$this->debugLsrc("Executing SQL: ".$remSQL);
$remResult = db_execute_assoc($remSQL);
$remRow = $remResult->FetchRow();
/* Get the reminder count from the row, if we have a row. If
* we don't have a row then we set reminderCount to 0 to prevent
* queries down below from bombing out. */
$reminderCount = $remRow['remindercount'];
if(empty($reminderCount)) {
$this->debugLsrc("There are no reminders to send.");
$reminderCount = 0;
}
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$remRow['tid']."; ".$reminderCount." ");
$sendOnlySQL = "SELECT tid, remindercount "
. "FROM ".db_table_name("tokens_{$surveyid}")." "
. "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' AND remindercount < ".$reminderCount." "
. "ORDER BY tid asc LIMIT 1";
$this->debugLsrc("Executing SQL: ".$sendOnlySQL);
if($sendOnlyResult->RecordCount()>0)
{
$sendOnlyRow = $sendOnlyResult->FetchRow();
$starttokenid = $sendOnlyRow['tid'];
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$sendOnlyRow['tid']."; ".$sendOnlyRow['remindercount']." ");
}
if(isset($surveyid) && getEmailFormat($surveyid) == 'html')
{
$ishtml=true;
}
else
{
$ishtml=false;
}
//GET SURVEY DETAILS
$thissurvey=getSurveyInfo($surveyid);
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", $surveyid, $type");
// Texte für Mails aus der Datenbank holen.
$sql = "SELECT surveyls_language, surveyls_email_remind_subj, surveyls_email_remind ".
"FROM {$dbprefix}surveys_languagesettings ".
"WHERE surveyls_survey_id = ".$surveyid." ";
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
$sqlResult = db_execute_assoc($sql);
while($languageRow = $sqlResult->FetchRow())
{
$_POST['message_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind'];
$_POST['subject_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind_subj'];
}
//$tokenoutput .= ("Sending Reminders")."\n";
$surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselanguage = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($surveylangs,$baselanguage);
foreach ($surveylangs as $language)
{
$_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]);
$_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]);
}
$SQLemailstatuscondition = " AND emailstatus = 'OK'";
if (isset($_POST['maxremindercount']) &&
$_POST['maxremindercount'] != '' &&
intval($_POST['maxremindercount']) != 0)
{
$SQLremindercountcondition = " AND remindercount < ".intval($_POST['maxremindercount']);
}
else
{
$SQLremindercountcondition = "";
}
if (isset($_POST['minreminderdelay']) &&
$_POST['minreminderdelay'] != '' &&
intval($_POST['minreminderdelay']) != 0)
{
// $_POST['minreminderdelay'] in days (86400 seconds per day)
$compareddate = date_shift(date("Y-m-d H:i:s",time() - 86400 * intval($_POST['minreminderdelay'])),
"Y-m-d H:i",$timeadjust);
$SQLreminderdelaycondition = " AND ( "
. " (remindersent = 'N' AND sent < '".$compareddate."') "
. " OR "
. " (remindersent < '".$compareddate."'))";
}
else
{
$SQLreminderdelaycondition = "";
}
$ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed ='N' or completed ='') AND sent<>'' AND sent<>'N' AND token <>'' AND email <> '' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition";
if (isset($starttokenid)) {$ctquery .= " AND tid >= '{$starttokenid}'";}
// if (isset($tokenid) && $tokenid) {$ctquery .= " AND tid = '{$tokenid}'";}
// //$tokenoutput .= "<!-- ctquery: $ctquery -->\n";
$ctresult = $connect->Execute($ctquery) or $this->debugLsrc ("Database error!\n" . $connect->ErrorMsg());
$ctcount = $ctresult->RecordCount();
$ctfieldcount = $ctresult->FieldCount();
$emquery = "SELECT * ";
//if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
// TLR change to put date into sent
$emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition";
if (isset($starttokenid)) {$emquery .= " AND tid >= '{$starttokenid}'";}
if (isset($tokenid) && $tokenid) {$emquery .= " AND tid = '{$tokenid}'";}
$emquery .= " ORDER BY tid ";
$emresult = db_select_limit_assoc($emquery, $maxemails);
//$emresult = db_execute_assoc($emquery);
$emcount = $emresult->RecordCount();
if ($emcount > 0)
{
while ($emrow = $emresult->FetchRow())
{
$c=1;
unset($fieldsarray);
$to = $emrow['email'];
$fieldsarray["{EMAIL}"]=$emrow['email'];
$fieldsarray["{FIRSTNAME}"]=$emrow['firstname'];
$fieldsarray["{LASTNAME}"]=$emrow['lastname'];
$fieldsarray["{TOKEN}"]=$emrow['token'];
$fieldsarray["{LANGUAGE}"]=$emrow['language'];
while(isset($emrow["attribute_$c"]))
{
$fieldsarray["{ATTRIBUTE_$c}"]=$emrow["attribute_$c"];
++$c;
}
$fieldsarray["{ADMINNAME}"]= $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
$fieldsarray["{EXPIRY}"]=$thissurvey["expiry"];
$emrow['language']=trim($emrow['language']);
if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default
if(!in_array($emrow['language'], $surveylangs)) {$emrow['language']=$baselanguage;} // if given language is not available use default
$found = array_search($emrow['language'], $surveylangs);
if ($found==false) {$emrow['language']=$baselanguage;}
$from = $thissurvey['adminemail'];
if (getEmailFormat($surveyid) == 'html')
{
$ishtml=true;
}
else
{
$ishtml=false;
}
if ($ishtml == false)
{
if ( $modrewrite )
{
$fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}";
}
else
{
$fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}";
}
}
else
{
if ( $modrewrite )
{
$fieldsarray["{SURVEYURL}"]="<a href='$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}'>".htmlspecialchars("$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}")."</a>";
}
else
{
$fieldsarray["{SURVEYURL}"]="<a href='$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}'>".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}")."</a>";
$_POST['message_'.$emrow['language']] = html_entity_decode($_POST['message_'.$emrow['language']], ENT_QUOTES, $emailcharset);
}
}
$msgsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray);
$sendmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray);
if (SendEmailMessage($sendmessage, $msgsubject, $to, $from, $sitename, $ishtml, getBounceEmail($surveyid)))
{
// Put date into remindersent
$today = date("Y-m-d H:i");
$udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n"
."SET remindersent='$today',remindercount = remindercount+1 WHERE tid={$emrow['tid']}";
//
$uderesult = $connect->Execute($udequery) or $this->debugLsrc ("Could not update tokens$udequery".$connect->ErrorMsg());
//orig: $tokenoutput .= "\t\t\t({$emrow['tid']})[".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]\n";
//$tokenoutput .= "\t\t\t({$emrow['tid']}) [".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']} ($to)]\n";
$mailsSend++;
}
else
{
//$tokenoutput .= ReplaceFields(("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."", $fieldsarray);
if($n==1)
$failedAddresses .= ",".$to;
else
{
$failedAddresses = $to;
$n=1;
}
}
//$lasttid = $emrow['tid'];
}
if ($ctcount > $emcount)
{
$lefttosend = $ctcount-$maxemails;
}else{$lefttosend = 0;}
}
else
{
return "No Reminders to send";
}
if($maxemails>0)
{
$returnValue = "".$mailsSend." Reminders send. ".$lefttosend." Reminders left to send";
if(isset($failedAddresses))
$returnValue .= "\nCould not send to: ".$failedAddresses;
return $returnValue;
}
if(isset($mailsSend))
{
$returnValue = "".$mailsSend." Reminders send. ";
if(isset($failedAddresses))
$returnValue .= "\nCould not send to: ".$failedAddresses;
return $returnValue;
}
break;
default:
break;
}
}
/**
* loginCheck for Lsrc, checks if the user with given password exists in LS Database and
* sets the SESSION rights for this user
* @param String $sUser
* @param String $sPass
* @return boolean
*/
function checkUser($sUser, $sPass) // XXX
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
require(dirname(__FILE__)."/../classes/core/sha256.php");
$query="SELECT uid, password, lang, superadmin FROM {$dbprefix}users WHERE users_name=".$connect->qstr(sanitize_user($sUser));
// echo $query;
$result = db_execute_assoc($query);
$gv = $result->FetchRow();
if($result->RecordCount() < 1)
{
return false;
}
else
{
if((SHA256::hashing($sPass)==$gv['password']))
{
$_SESSION['loginID']=$gv['uid'];
$_SESSION['lang']=$gv['lang'];
$squery = "SELECT create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label FROM {$dbprefix}users WHERE uid={$gv['uid']}";
$sresult = db_execute_assoc($squery); //Checked
if ($sresult->RecordCount()>0)
{
$fields = $sresult->FetchRow();
$_SESSION['USER_RIGHT_CREATE_SURVEY'] = $fields['create_survey'];
$_SESSION['USER_RIGHT_CONFIGURATOR'] = $fields['configurator'];
$_SESSION['USER_RIGHT_CREATE_USER'] = $fields['create_user'];
$_SESSION['USER_RIGHT_DELETE_USER'] = $fields['delete_user'];
$_SESSION['USER_RIGHT_SUPERADMIN'] = $fields['superadmin'];
$_SESSION['USER_RIGHT_MANAGE_TEMPLATE'] = $fields['manage_template'];
$_SESSION['USER_RIGHT_MANAGE_LABEL'] = $fields['manage_label'];
}
return true;
}
else
{
return false;
}
}
}
/**
* Lsrc checks the existence of Surveys more than one time, so this makes sense to be DRY
*
* @param int $sid
* @return boolean
*/
function surveyExists($sid)//XXX
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$query="SELECT * FROM {$dbprefix}surveys WHERE sid = ".$sid;
// echo $query;
$result = db_execute_assoc($query);
if($result->RecordCount() < 1)
{
return false;
}
else
{
return true;
}
}
/**
* function to import surveys
*
* @param $iVid - desired survey id
* @param $importFile - name of the file to import in core(survey) dir
* @return boolean
*/
function importSurvey($iVid, $importFile)
{
global $connect ;
global $dbprefix ;
global $clang;
include("lsrc.config.php");
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ");
// HINT FOR IMPORTERS: go to Line 714 to manipulate the Survey, while it's imported
$the_full_file_path = $coreDir.$importFile;
$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",the_full_file_path ='$the_full_file_path' OK ");
include("../import_functions.php");
include("../admin_functions.php");
if (!isset($copyfunction))
{
$sFullFilepath=$the_full_file_path;
$aPathInfo = pathinfo($sFullFilepath);
$sExtension = $aPathInfo['extension'];
}
if (isset($sExtension) && strtolower($sExtension)=='csv')
{
$aImportResults=CSVImportSurvey($sFullFilepath,$iVid);
}
elseif (isset($sExtension) && strtolower($sExtension)=='lss')
{
$aImportResults=XMLImportSurvey($sFullFilepath,NULL,NULL,$iVid);
} elseif (isset($copyfunction))
{
$aImportResults=XMLImportSurvey('',$copysurveydata,$sNewSurveyName,$iVid);
}
//CANNOT BE USED BY LSRC RIGHT NOW
// Translate INSERTANS codes if chosen
// if (isset($aImportResults['fieldnames']) && $sTransLinks === true)
// {
// transInsertAns($aImportResults['newsid'],$aImportResults['oldsid'],$aImportResults['fieldnames']);
// }
return $aImportResults['newsid'];
}
/**
* function to activate surveys based on new activate.php 5771 2008-10-13 02:28:40Z jcleeland $
*
* @param unknown_type $surveyid
* @return boolean
*/
function activateSurvey($surveyid)//XXX activateSurvey
{
global $dbprefix, $connect, $clang, $databasetype,$databasetabletype;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
include('../admin_functions.php');
include('../activate_functions.php');
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
$returnOutput = activateSurvey($surveyid,$surveyid,'lsrc');
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", $returnOutput ");
return $returnOutput;
} // end activateSurvey();
/**
* not used, a test, thought this could maybe enhance security, may be deleted
*
* @return Error 404 fake
*/
function fake404()// XXX
{
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
<head>
<title>Objekt nicht gefunden!</title>
<link rev="made" href="" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/
body { color: #000000; background-color: #FFFFFF; }
a:link { color: #0000CC; }
p, address {margin-left: 3em;}
span {font-size: smaller;}
/*]]>*/--></style>
</head>
<body>
<h1>Objekt nicht gefunden!</h1>
<p>
Der angeforderte URL konnte auf dem Server nicht gefunden werden.
Sofern Sie den URL manuell eingegeben haben,
überprüfen Sie bitte die Schreibweise und versuchen Sie es erneut.
</p>
<p>
Sofern Sie dies für eine Fehlfunktion des Servers halten,
informieren Sie bitte den
<a href="mailto:webmaster@'.$_SERVER["SERVER_NAME"].'">Webmaster</a>
hierüber.
</p>
<h2>Error 404</h2>
<address>
<a href="/">'.$_SERVER["SERVER_NAME"].'</a>
<span>'.date("m/d/Y H:i:s").'
Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.6 mod_jk/1.2.26</span>
</address>
</body>
</html>
';
}
/**
* importing a group into an existing survey
*
* @param int $iVid SurveyID
* @param string $sMod Group that should be loaded into the Survey
*/
function importGroup($surveyid, $sMod) //XXX
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$newsid = $surveyid;
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
$the_full_file_path = $modDir.$sMod.".csv";
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK $the_full_file_path ");
$handle = fopen($the_full_file_path, "r");
while (!feof($handle))
{
$buffer = fgets($handle);
$bigarray[] = $buffer;
}
fclose($handle);
if (substr($bigarray[0], 0, 23) != "# LimeSurvey Group Dump" && substr($bigarray[0], 0, 24) != "# PHPSurveyor Group Dump")
{
//$importgroup .= "<strong><font color='red'>".("Error")."</font></strong>\n";
//$importgroup .= ("This file is not a LimeSurvey group file. Import failed.")."\n";
//$importgroup .= "<input type='submit' value='".("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\">\n";
//$importgroup .= "</td></tr></table>\n";
//unlink($the_full_file_path);
return false;
}
for ($i=0; $i<9; $i++)
{
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
//GROUPS
if (array_search("# QUESTIONS TABLE\n", $bigarray))
{
$stoppoint = array_search("# QUESTIONS TABLE\n", $bigarray);
}
elseif (array_search("# QUESTIONS TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# QUESTIONS TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$grouparray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//QUESTIONS
if (array_search("# ANSWERS TABLE\n", $bigarray))
{
$stoppoint = array_search("# ANSWERS TABLE\n", $bigarray);
}
elseif (array_search("# ANSWERS TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# ANSWERS TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$questionarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//ANSWERS
if (array_search("# CONDITIONS TABLE\n", $bigarray))
{
$stoppoint = array_search("# CONDITIONS TABLE\n", $bigarray);
}
elseif (array_search("# CONDITIONS TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# CONDITIONS TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$answerarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//CONDITIONS
if (array_search("# LABELSETS TABLE\n", $bigarray))
{
$stoppoint = array_search("# LABELSETS TABLE\n", $bigarray);
}
elseif (array_search("# LABELSETS TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# LABELSETS TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray);
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$conditionsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//LABELSETS
if (array_search("# LABELS TABLE\n", $bigarray))
{
$stoppoint = array_search("# LABELS TABLE\n", $bigarray);
}
elseif (array_search("# LABELS TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# LABELS TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$labelsetsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//LABELS
if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
}
elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$labelsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
//LAST LOT (now question_attributes)
if (!isset($noconditions) || $noconditions != "Y")
{
// stoppoint is the last line number
// this is an empty line after the QA CSV lines
$stoppoint = count($bigarray)-1;
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<=$stoppoint-1) {$question_attributesarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
}
$bigarray = array_values($bigarray);