-
Notifications
You must be signed in to change notification settings - Fork 988
/
lsrc.server.php
997 lines (888 loc) · 30.5 KB
/
lsrc.server.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
<?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 the lsrc.config.php
include_once("lsrc.config.php");
// functions helping lsrcService to do some things with Limesurvey (import, activation, checks)
include("lsrc.helper.php");
/**
* if ?wsdl is set, generate wsdl with correct uri and send it back to whoever requesting
*/
if(isset($_GET['wsdl']))
{
if($lsrcOverSSL)
$http = "https://";
else
$http = "http://";
$wsdlString = file_get_contents("lsrc_orig.wsdl");
$wsdlString = str_replace("{lsrclocation}",$http.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'],$wsdlString);
file_put_contents("lsrc.wsdl",$wsdlString);
header('Content-type: text/wsdl');
header('Content-Disposition: attachment; filename=lsrc.wsdl');
}
//we initiate a SoapServer Objekt
if($useCert && $sslCert!=''){
// I don't know for sure how this works... no developerdocumentation on this.
$context["ssl"]["local_cert"] = $sslCert;
$context["ssl"]["verify_peer"] = FALSE;
$context["ssl"]["allow_self_signed"] = TRUE;
$context["ssl"]["cafile"] = "D://xampp//htdocs//apache//conf//keys//cacert.pem";
$stream_context = stream_context_create($context);
$server = new SoapServer($wsdl, array('soap_version' => SOAP_1_1,
'stream_context' => $stream_context,
'local_cert' => $sslCert));
}
else{
$server = new SoapServer($wsdl, array('soap_version' => SOAP_1_1));
}
//adds the functions to the SoapServer Object,
//the sChangeSurvey and sDeleteSurvey function should be commented out for productive Use
//$server->addFunction("sChangeSurvey");
$server->addFunction("sDeleteSurvey");
$server->addFunction("sActivateSurvey");
$server->addFunction("sCreateSurvey");
$server->addFunction("sInsertToken");
$server->addFunction("sTokenReturn");
$server->addFunction("sInsertParticipants");
$server->addFunction("sImportGroup");
$server->addFunction("sAvailableModules");
$server->addFunction("sImportQuestion");
$server->addFunction("sImportMatrix");
$server->addFunction("sImportFreetext");
$server->addFunction("sSendEmail");
// handle the soap request!
$server->handle();
/**
* Function to change tables in Limesurvey Database, this is too sensitive for productive use, but useful for development and testing
*
*/
function sChangeSurvey($sUser, $sPass, $table, $key, $value, $where, $mode='0') //XXX
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
//check for Surveyowner. Only owners and superadmins can change and activate surveys
if(!$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Databasetables");
exit;
}
return $lsrcHelper->changeTable($table, $key, $value, $where, $mode);
}
/*
* Function to send reminder, invitation or custom mails to participants of a specific survey
* $iVid = Survey ID
* $type = invite, remind, custom
* $subject = subject of custom mails
* $emailText = Text of custom mails
*
*/
function sSendEmail($sUser, $sPass, $iVid, $type, $maxemails='', $subject='', $emailText='')
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
// Check if all mandatory parameters are present, else abort...
if(!is_int($iVid) || $iVid==0 || $type=='')
{
throw new SoapFault("Server: ", "Mandatory Parameters missing");
exit;
}
if($type=='custom' && $subject!='' && $emailText!='')
{
$emquery = "SELECT firstname, lastname, email, token, tid, language";
if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
$emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != '' $SQLemailstatuscondition";
if (isset($tokenid)) {$emquery .= " and tid='{$tokenid}'";}
$tokenoutput .= "\n\n<!-- emquery: $emquery -->\n\n";
$emresult = db_select_limit_assoc($emquery,$maxemails);
MailTextMessage();
}
if($type=='invite' || $type=='remind')
{
$emailSenderReturn = $lsrcHelper->emailSender($iVid, $type, $maxemails);
return $emailSenderReturn;
// if($maxemails != '')
// {
// return $emailSenderReturn;
// if($emailSenderReturn)
// {
// return "Mails send successfully";
// }
// else
// return $emailSenderReturn;
// }
// else
// {
// if($emailSenderReturn)
// {
// return "Mails send successfully";
// }
// else
// {
// throw new SoapFault("Sending Mail: ", "".$emailSenderReturn);
// exit;
// }
// }
}
else
{
throw new SoapFault("Type: ", "Wrong send Type given. Possible types are: custom, invite or remind");
exit;
}
}
/**
* Function to activate a survey in the database and change some Values (starttime, endtime. Required parameters are:
* $iVid= Survey ID
* $dStart = datetime
* $dE = datetime
* $sUser = have to be an existing admin or superadmin in limesurvey
* $sPass = password have to be the right one for the existing user in limesurvey
*/
function sActivateSurvey($sUser, $sPass, $iVid, $dStart, $dEnd)
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for apropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
// Check if all mandatory parameters are present, else abort...
if(!is_int($iVid) || $iVid==0)
{
throw new SoapFault("Server: ", "Mandatory Parameters missing");
exit;
}
// Check if the survey to create already exists. If not, abort with Fault.
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey you want to activate does not exists");
exit;
}
//check for Surveyowner. Only owners and superadmins can change and activate surveys
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Surveys from other people");
exit;
}
if(!$lsrcHelper->activateSurvey($iVid))
{
throw new SoapFault("Server: ", "Activation went wrong somehow");
exit;
}
if($dStart!='')
{
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", CHANGE start ");
$lsrcHelper->changeTable('surveys','usestartdate','Y','sid='.$iVid);
$lsrcHelper->changeTable('surveys','startdate',$dStart,'sid='.$iVid);
}
if($dEnd!='')
{
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", CHANGE end ");
$lsrcHelper->changeTable('surveys','useexpiry','Y','sid='.$iVid);
$lsrcHelper->changeTable('surveys','expires',$dEnd,'sid='.$iVid);
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", aktivierung OK ");
return $iVid;
}
/**
* Function to import a survey into the database and change some Values. Required parameters are:
* $iVid = Survey ID
* $sVtit = Survey Titel
* $sVbes = Surveydescription
* $sVwel = Welcometext
* $sUser = have to be an existing accounts with appropriate rights in limesurvey
* $sPass = password have to be the right one for the existing user in limesurvey
* $sVtyp = Veranstaltungstyp (Vorlesung, Seminar, Uebung, Exkursion)
*/
function sCreateSurvey($sUser, $sPass, $iVid, $sVtit , $sVbes, $sVwel, $sMail, $sName, $sUrl, $sUbes, $sVtyp ) //XXX
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
if($sVwel=='')
{//if no welcometext is given, set this one
$sVwel = "Herzlich Willkommen zur Evaluation von \"".$sVtit."\"";
}
if(!$lsrcHelper->checkUser($sUser, $sPass))
{// check for appropriate rights
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
if((!is_int($iVid) || $iVid==0) || $sVtit=='' || $sVbes=='')
{// Check if mandatory parameters are empty, if so-> abort
throw new SoapFault("Server: ", "Mandatory Parameters missing");
exit;
}
if($lsrcHelper->surveyExists($iVid))
{// Check if the survey to create already exists. If so, abort with Fault.
throw new SoapFault("Database: ", "Survey already exists");
exit;
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",vor import OK ");
if($lsrcHelper->importSurvey($iVid, $sVtit , $sVbes, $sVwel, $sUbes, $sVtyp))
{// if import of survey went ok it returns true, else nothing
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", nach import OK ");
//get the optional data into db
if($sMail!='')
{
$lsrcHelper->changeTable("surveys", "adminemail", $sMail, "sid='$iVid'");
$lsrcHelper->changeTable("surveys", "bounce_email", $sMail, "sid='$iVid'");
}
if($sName!='')
$lsrcHelper->changeTable("surveys", "admin", $sName, "sid='$iVid'");
if($sUrl!='')
$lsrcHelper->changeTable("surveys", "url", $sUrl, "sid='$iVid'");
$lsrcHelper->changeTable("surveys", "datecreated", date("Y-m-d"), "sid='$iVid'");
return $iVid;
}
else
{
throw new SoapFault("Server: ", "Import went wrong somehow");
exit;
}
}//end of function sCreateSurvey
/**
* Function to insert Tokens to an existing Survey, makes it "closed"
* $iVid = Survey ID
* $sToken = String of tokens in this pattern: token1,token2,token3,token4,token5 and so on...
* $sUser = have to be an existing admin or superadmin in Limesurvey
* $sPass = password have to be the right one for the existing user in limesurvey
*/
function sInsertToken($sUser, $sPass, $iVid, $sToken) //XXX
{
global $connect ;
global $dbprefix ;
//$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for apropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
// check if there is a $iVid, else abort
if(!isset($iVid) || $iVid=='' || $iVid==0 )
{
throw new SoapFault("Server: ", "No SurveyId given");
exit;
}
// check if the Survey we want to populate with tokens already exists, else -> Fault
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey does not exists");
exit;
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", ckecks ueberstanden ");
// check if the Token table already exists, if not, create it...
if(!db_tables_exist("{$dbprefix}tokens_".$iVid))
{
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", TOken Table existiert nicht ");
$createtokentable=
"tid int I NOTNULL AUTO PRIMARY,\n "
. "firstname C(40) ,\n "
. "lastname C(40) ,\n ";
//MSSQL needs special treatment because of some strangeness in ADODB
if ($databasetype=='odbc_mssql')
{
$createtokentable.= "email C(320) ,\n "
."emailstatus C(300) DEFAULT 'OK',\n ";
}
else
{
$createtokentable.= "email X(320) ,\n "
."emailstatus X(300) DEFAULT 'OK',\n ";
}
$createtokentable.= "token C(36) ,\n "
. "language C(25) ,\n "
. "sent C(17) DEFAULT 'N',\n "
. "remindersent C(17) DEFAULT 'N',\n "
. "remindercount int I DEFAULT 0,\n "
. "completed C(17) DEFAULT 'N',\n "
. "attribute_1 C(100) ,\n"
. "attribute_2 C(100) ,\n"
. "mpid I ";
$tabname = "{$dbprefix}tokens_{$iVid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray);
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
$createtokentableindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token'));
$dict->ExecuteSQLArray($createtokentableindex, false);
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", Token tabelle sollte erstellt sein ");
#################
//if the lsrcSeperator is not set, set the default seperator, a comma...
if($sLsrcSeparator=='')
{
$sLsrcSeparator = ",";
}
// prepare to fill the table lime_tokens_*
// this is sensitiv, if the Seperator is not the defined one, almost everything could happen, BE AWARE OF YOUR SEPERATOR!...
$asTokens = explode($sLsrcSeparator, $sToken);
$givenTokenCount = count($asTokens);
// write the tokens in the token_table
$insertedTokenCount=0;
foreach($asTokens as $value)
{
if($value!='')
{
$sInsertToken = "INSERT INTO {$dbprefix}tokens_".$iVid."
(token,language) VALUES ('".$value."' , '".$_SESSION['lang']."'); ";
if(!$connect->Execute($sInsertToken))
{
throw new SoapFault("Server: ", "Token could not be inserted");
exit;
}
else
{
++$insertedTokenCount;
}
}
}
return "".$givenTokenCount." Token given, ".$insertedTokenCount." Token inserted.";
} //end of function sInsertToken
/**
* Function to insert Participants data while auto creating tokens for everyone...
* $iVid = Survey ID
* $sParticipantData = String of datasets in this pattern: FIRSTNAME;LASTNAME;EMAIL[;[ATTRIB1];[ATTRIB2]]::FIRSTNAME... and so on...
* $sUser = have to be an existing admin or superadmin in Limesurvey
* $sPass = password have to be the right one for the existing user in limesurvey
*/
function sInsertParticipants($sUser, $sPass, $iVid, $sParticipantData) //XXX
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
// check if there is a $iVid, else abort
if(!isset($iVid) || $iVid=='' || $iVid==0 )
{
throw new SoapFault("Server: ", "No SurveyId given");
exit;
}
// check if the Survey we want to populate with data and tokens already exists, else -> Fault
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey does not exists");
exit;
}
// check if the Token table already exists, if not, create it...
if(!db_tables_exist("{$dbprefix}tokens_".$iVid))
{
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", Token Table existiert nicht ");
$createtokentable=
"tid int I NOTNULL AUTO PRIMARY,\n "
. "firstname C(40) ,\n "
. "lastname C(40) ,\n ";
//MSSQL needs special treatment because of some strangeness in ADODB
if ($databasetype=='odbc_mssql')
{
$createtokentable.= "email C(320) ,\n "
."emailstatus C(300) DEFAULT 'OK',\n ";
}
else
{
$createtokentable.= "email X(320) ,\n "
."emailstatus X(300) DEFAULT 'OK',\n ";
}
$createtokentable.= "token C(36) ,\n "
. "language C(25) ,\n "
. "sent C(17) DEFAULT 'N',\n "
. "remindersent C(17) DEFAULT 'N',\n "
. "remindercount int I DEFAULT 0,\n "
. "completed C(17) DEFAULT 'N',\n "
. "attribute_1 C(100) ,\n"
. "attribute_2 C(100) ,\n"
. "mpid I ";
$tabname = "{$dbprefix}tokens_{$iVid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray);
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
$createtokentableindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token'));
$dict->ExecuteSQLArray($createtokentableindex, false);
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", Token tabelle sollte erstellt sein ");
//set the Seperators to default if nothing is set in the lsrc.config.php
if(!isset($sDatasetSeperator) || $sDatasetSeperator=='')
{$sDatasetSeperator = "::";}
if(!isset($sDatafieldSeperator) || $sDatafieldSeperator=='')
{$sDatafieldSeperator = ";";}
// prepare to fill the table lime_tokens_*
// this is sensitiv, if the Seperator is not the defined one, almost everything could happen, BE AWARE OF YOUR SEPERATOR!...
$asDataset = explode($sDatasetSeperator, $sParticipantData);
// write the tokens to the token_table
$iCountParticipants = count($asDataset);
$iInsertedParticipants=0;
foreach($asDataset as $sData)
{
if($sData!='')
{
$asDatafield = explode($sDatafieldSeperator, $sData);
$checkCnt=1;
while($checkCnt>0)
{
$value = randomkey(5); //change randomkey value for different tokenlength (up to 36 chars max.)
$cQuery= "select token from ".$dbprefix."tokens_".$iVid." where token = '".$value."'; ";
$result = db_execute_assoc($cQuery);
$checkCnt = $result->RecordCount();
}
$iDataLength = count($asDatafield);
for($n=0;$n>=$iDataLength;++$n)
{
if($asDatafield[$n]==''){$asDatafield[$n]=null;}
}
$sInsertParti = "INSERT INTO ".$dbprefix."tokens_".$iVid
."(firstname,lastname,email,emailstatus,token,"
."language,sent,completed,attribute_1,attribute_2,mpid)"
."VALUES ('".utf8_decode($asDatafield[0])."' ,
'".utf8_decode($asDatafield[1])."' , '".$asDatafield[2]."' , NULL , '".$value."',
'".$_SESSION['lang']."', 'N', 'N', '".utf8_decode($asDatafield[3])."' , '".utf8_decode($asDatafield[4])."' , NULL); ";
$connect->Execute($sInsertParti);
++$iInsertedParticipants;
}
}
return "".$iCountParticipants."Datasets given, ".$iInsertedParticipants." rows inserted. ";
//return $sParticipantData;
} //end of function sInsertParticipants
/**
* function to return unused Tokens as String, seperated by commas, to get the people who did not complete the Survey
*/
function sTokenReturn($sUser, $sPass, $iVid) //XXX
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
// check if there is a $iVid, else abort
if(!isset($iVid) || $iVid=='' || $iVid==0 )
{
throw new SoapFault("Server: ", "No SurveyId given");
exit;
}
// check if the Survey exists, else -> Fault
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey does not exists");
exit;
}
// check if the token table exists, else throw fault message
if(db_tables_exist($dbprefix."tokens_".$iVid))
{
// select all the tokens that did not complete the Survey
$query2select_token = "SELECT token from {$dbprefix}tokens_".$iVid." WHERE completed = 'N'; ";
$rs = db_execute_assoc($query2select_token);
if($rs->RecordCount()<1)
{
throw new SoapFault("Database: ", "No unused Tokens found");
exit;
}
$n=0;
while($row = $rs->FetchRow())
{
if($n == 0)
{
$sReturn = $row['token'];
}
else
{
$sReturn .= ",".$row['token'];
}
$n++;
}
// return Response: array([iVid],[return]) on the client side, you get this as an Array resp. list
// the keys in the array, containing the values, are named as defined in the wsdl under the response Message, in this case: array(iVid =>$iVid, return=>$sReturn)
return $sReturn;
exit;
}
else
{
throw new SoapFault("Database: ", "Token table for this Survey does not exists");
exit;
}
}//end of function sTokenReturn
/**
* function to import an exported group of questions into a survey
*
* @param unknown_type $iVid
* @param unknown_type $sMod
*/
function sImportGroup($sUser, $sPass, $iVid, $sMod, $gName='', $gDesc='')//XXX
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or Password wrong");
exit;
}
//check for Surveyowner
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Surveys from other people");
exit;
}
if(!is_file($modDir.$sMod.".csv"))
{
throw new SoapFault("Server: ", "Survey Module $sMod does not exist");
exit;
}
$checkImport = $lsrcHelper->importGroup($iVid, $sMod);
if(is_array($checkImport))
{
if($gName!='')
$lsrcHelper->changeTable("groups", "group_name", $gName, "gid='".$checkImport['gid']."'");
if($gDesc!='')
$lsrcHelper->changeTable("groups", "description", $gDesc, "gid='".$checkImport['gid']."'");
return "Import OK";
}
else
{
throw new SoapFault("Server: ", $checkImport);
exit;
}
}
/**
* function to import a fixed question
*
* @param String $sUser
* @param String $sPass
* @param Int $iVid
* @param String $sMod
* @param String $qTitle
* @param String $qText
* @param String $qHelp
* @return String
*/
function sImportQuestion($sUser, $sPass, $iVid, $sMod, $mandatory='N')
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
//check for Surveyowner
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Surveys from other people");
exit;
}
// Check if the file to import exists
if(!is_file($queDir.$sMod.".csv"))
{
throw new SoapFault("Server: ", "Survey Module $sMod does not exist");
exit;
}
//import the module
$lastId = $lsrcHelper->importQuestion($iVid,$sMod);
if(is_array($lastId))
{
// $lsrcHelper->changeTable("questions", "title", $qTitle, "qid='".$lastId['qid']."'");
// $lsrcHelper->changeTable("questions", "question", $qText, "qid='".$lastId['qid']."'");
// $lsrcHelper->changeTable("questions", "help", $qHelp, "qid='".$lastId['qid']."'");
$lsrcHelper->changeTable("questions", "mandatory", $mandatory, "qid='".$lastId['qid']."'");
return "OK";
}
else
{
throw new SoapFault("Server: ", $lastId);
exit;
}
}
/**
* function to import a questiongroup with one freetext question and change it
*
* @param String $sUser
* @param String $sPass
* @param Int $iVid
* @param String $sMod
* @param String $qTitle
* @param String $qText
* @param String $qHelp
* @return String
*/
function sImportFreetext($sUser, $sPass, $iVid, $qTitle, $qText, $qHelp, $sMod='Freitext', $mandatory='N')
{
/*
* this var maybe added later to constructor,
* to determine if a new group should be build for the question
* or if the question should be added to the last group in survey
*/
$newGroup=0;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
//check for Surveyowner
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Surveys from other people");
exit;
}
// Check if the file to import exists
if(!is_file($queDir.$sMod.".csv"))
{
throw new SoapFault("Server: ", "Survey Module $sMod does not exist");
exit;
}
//import the module
$lastId = $lsrcHelper->importQuestion($iVid,$sMod,0);
if(is_array($lastId))
{
$lsrcHelper->changeTable("questions", "title", $qTitle, "qid='".$lastId['qid']."'");
$lsrcHelper->changeTable("questions", "question", $qText, "qid='".$lastId['qid']."'");
$lsrcHelper->changeTable("questions", "help", $qHelp, "qid='".$lastId['qid']."'");
$lsrcHelper->changeTable("questions", "mandatory", $mandatory, "qid='".$lastId['qid']."'");
return "OK";
}
else
{
throw new SoapFault("Server: ", $lastId);
exit;
}
}
/**
* function to import a five scale Matrix question and set 1 to n items
*
* @param unknown_type $sUser
* @param unknown_type $sPass
* @param unknown_type $iVid
* @param unknown_type $sMod
* @param unknown_type $qTitle
* @param unknown_type $qHelp
* @param unknown_type $sItems comma seperated values
* @return unknown
*/
function sImportMatrix($sUser, $sPass, $iVid, $qText, $qHelp, $sItems, $sMod='Matrix5', $mandatory='N')
{
/*
* this var maybe added later to constructor,
* to determine if a new group should be build for the question
* or if the question should be added to the last group in survey
*/
$newGroup=0;
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK ");
// check for appropriate rights
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
//check for surveyOwner
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to change Surveys from other people");
exit;
}
// Check if the file to import exists
if(!is_file($queDir.$sMod.".csv"))
{
throw new SoapFault("Server: ", "Survey Module $sMod does not exist");
exit;
}
$lastId = $lsrcHelper->importQuestion($iVid,$sMod,$newGroup);
if(is_array($lastId))
{
$lsrcHelper->changeTable("questions", "question", $qText, "qid='".$lastId['qid']."'");
$lsrcHelper->changeTable("questions", "help", $qHelp, "qid='".$lastId['qid']."'");
if($mandatory==''){$mandatory='N';}
$lsrcHelper->changeTable("questions", "mandatory", $mandatory, "qid='".$lastId['qid']."'");
$aItems = explode(",", $sItems);
$n=0;
foreach($aItems as $item)
{
++$n;
$lsrcHelper->changeTable("answers", "qid,code,answer,default_value,sortorder,language", "'".$lastId['qid']."', '$n','$item','N','$n','".GetBaseLanguageFromSurveyID($iVid)."' " , "", 1);
}
return "OK";
}
else
{
throw new SoapFault("Server: ", $lastId);
exit;
}
}
/**
* function to collect all available Modules and send them comma seperated to the client
*
* @param String $sUser
* @param String $sPass
* String $mode ("mod" or "core")
* @return commma seperated list of available Modules (groups)
*/
function sAvailableModules($sUser, $sPass, $mode='mod')
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",mode=$mode START OK ");
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
switch($mode){
case ('mod'):
$mDir = opendir($modDir);
$n=0;
while(false !== ($file = readdir($mDir)))
{
if($file!='.' && $file!='..' && substr($file,-4,4)==".csv")
{
$file = basename ($file, ".csv");
//$file = str_replace("mod_", "", $file);
if($n == 0)
{
$return = $file;
$n=1;
}
else
{
$return .= ",".$file;
}
}
}
return $return;
break;
case ('core'):
$cDir = opendir($coreDir);
$n=0;
while(false !== ($file = readdir($cDir)))
{
if($file!='.' && $file!='..' && substr($file,-4,4)==".csv")
{
$file = basename ($file, ".csv");
//$file = str_replace("mod_", "", $file);
if($n == 0)
{
$return = $file;
$n=1;
}
else
{
$return .= ",".$file;
}
}
}
return $return;
break;
case ('que'):
$cDir = opendir($queDir);
$n=0;
while(false !== ($file = readdir($cDir)))
{
if($file!='.' && $file!='..' && substr($file,-4,4)==".csv")
{
$file = basename ($file, ".csv");
//$file = str_replace("mod_", "", $file);
if($n == 0)
{
$return = $file;
$n=1;
}
else
{
$return .= ",".$file;
}
}
}
return $return;
break;
}
}
/**
* function to delete a survey
*
* @param unknown_type $sUser
* @param unknown_type $sPass
* @param unknown_type $iVid
*/
function sDeleteSurvey($sUser, $sPass, $iVid)
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",mode=$mode START OK ");
if(!$lsrcHelper->checkUser($sUser, $sPass))
{
throw new SoapFault("Authentication: ", "User or password wrong");
exit;
}
if($lsrcHelper->getSurveyOwner($iVid)!=$_SESSION['loginID'] && !$_SESSION['USER_RIGHT_SUPERADMIN']=='1')
{
throw new SoapFault("Authentication: ", "You have no right to delete Surveys from other people");
exit;
}
// check if the Survey exists, else -> Fault
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey $iVid does not exists");
exit;
}
if($lsrcHelper->deleteSurvey($iVid))
{
return "Survey $iVid deleted";
}
else
{
throw new SoapFault("Server: ", "Survey $iVid was not deleted");
exit;
}
}
?>