Skip to content

Commit

Permalink
Updated Feature: the logic to import surveys and groups expanded to o…
Browse files Browse the repository at this point in the history
…mport of surveys, groups and questions.

Dev: this is like an Limesurvey API lite. You can build a survey with the testclient and some exported .csv only...

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey181@6564 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Tim Wahrendorff committed Mar 19, 2009
1 parent 84e2f6e commit ea9c1f7
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 521 deletions.
633 changes: 230 additions & 403 deletions admin/remotecontrol/lsrc.helper.php

Large diffs are not rendered by default.

36 changes: 28 additions & 8 deletions admin/remotecontrol/lsrc.server.php
Expand Up @@ -621,7 +621,7 @@ function sTokenReturn($sUser, $sPass, $iVid) //XXX
* @param unknown_type $iVid
* @param unknown_type $sMod
*/
function sImportGroup($sUser, $sPass, $iVid, $sMod)//XXX
function sImportGroup($sUser, $sPass, $iVid, $sMod, $gName='', $gDesc='')//XXX
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
Expand All @@ -646,9 +646,14 @@ function sImportGroup($sUser, $sPass, $iVid, $sMod)//XXX
exit;
}

$checkImport = $lsrcHelper->importGroup($iVid,"mod_".$sMod);
$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
Expand All @@ -671,7 +676,7 @@ function sImportGroup($sUser, $sPass, $iVid, $sMod)//XXX
* @param String $qHelp
* @return String
*/
function sImportQuestion($sUser, $sPass, $iVid, $sMod, $qTitle, $qText, $qHelp, $mandatory='N')
function sImportQuestion($sUser, $sPass, $iVid, $sMod, $mandatory='N')
{
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();
Expand Down Expand Up @@ -704,7 +709,7 @@ function sImportQuestion($sUser, $sPass, $iVid, $sMod, $qTitle, $qText, $qHelp,
// $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']."'");
$lsrcHelper->changeTable("questions", "mandatory", $mandatory, "qid='".$lastId['qid']."'");
return "OK";
}
else
Expand All @@ -728,6 +733,13 @@ function sImportQuestion($sUser, $sPass, $iVid, $sMod, $qTitle, $qText, $qHelp,
*/
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 ");
Expand All @@ -753,7 +765,7 @@ function sImportFreetext($sUser, $sPass, $iVid, $qTitle, $qText, $qHelp, $sMod='
}

//import the module
$lastId = $lsrcHelper->importQuestion($iVid,$sMod);
$lastId = $lsrcHelper->importQuestion($iVid,$sMod,0);
if(is_array($lastId))
{
$lsrcHelper->changeTable("questions", "title", $qTitle, "qid='".$lastId['qid']."'");
Expand Down Expand Up @@ -781,8 +793,15 @@ function sImportFreetext($sUser, $sPass, $iVid, $qTitle, $qText, $qHelp, $sMod='
* @param unknown_type $sItems comma seperated values
* @return unknown
*/
function sImportMatrix($sUser, $sPass, $iVid, $qText, $qHelp, $sItems, $sMod='Matrix', $mandatory='N' )
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;
Expand All @@ -809,9 +828,10 @@ function sImportMatrix($sUser, $sPass, $iVid, $qText, $qHelp, $sItems, $sMod='Ma
throw new SoapFault("Server: ", "Survey Module $sMod does not exist");
exit;
}
$lastId = $lsrcHelper->importGroup($iVid,$sMod);
$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';}
Expand All @@ -822,7 +842,7 @@ function sImportMatrix($sUser, $sPass, $iVid, $qText, $qHelp, $sItems, $sMod='Ma
foreach($aItems as $item)
{
++$n;
$lsrcHelper->changeTable("answers", "qid,code,answer,default_value,sortorder,language", "'".$lastId['qid']."', '$n','$item','N','$n','".$_SESSION['lang']."' " , "", 1);
$lsrcHelper->changeTable("answers", "qid,code,answer,default_value,sortorder,language", "'".$lastId['qid']."', '$n','$item','N','$n','".GetBaseLanguageFromSurveyID($iVid)."' " , "", 1);
}
return "OK";
}
Expand Down
20 changes: 11 additions & 9 deletions admin/remotecontrol/lsrc.testclient.php
Expand Up @@ -14,8 +14,15 @@
*
*/
$wsdl = $_REQUEST['wsdl'];

#####################################################################
## Configuration Parameters
//set this to your limesurvey installation path for the "test survey" link to work
$limeUrl='https://localhost/limesource/limesurvey181';

//We need authentication for every function, so just write the logindata once for all
$user ="admin";
$pass ="password";

//we don't like caching while testing, so we disable it
ini_set("soap.wsdl_cache_enabled", 0);
Expand All @@ -28,14 +35,9 @@
// give full uri of the wsdl from the webservice you want to connect to...
// THIS NEEDS TO BE CHANGED to the webservice you want to connect, localhost is just for testing on one machine...
// change http to https if you want to use ssl connection to the wsdl...
$wsdl='https://localhost/limesource/limesurvey/admin/remotecontrol/lsrc.server.php?wsdl';
$wsdl="$limeUrl/admin/remotecontrol/lsrc.server.php?wsdl";
}
//set this to your limesurvey installation path for the "test survey" link to work
$limeUrl='https://localhost/limesource/limesurvey';

//We need authentication for every function, so just write the logindata once for all
$user ="admin";
$pass ="password";

// fixed certificate, if U use some... you need this if you have an own trusted certificate.
// If you dont know what I am taking about, just leave this option untouched.
Expand Down Expand Up @@ -251,7 +253,7 @@ function soapCheck ($path2wsdl)
try
{

$sReturn = $client->sImportMatrix($user, $pass, $iVid, "Matrix", $qText, $qHelp, $items,$mandatory);
$sReturn = $client->sImportMatrix($user, $pass, $iVid, $qText, $qHelp, $items, "Matrix5", $mandatory,0);
}
catch (SoapFault $fault)
{
Expand All @@ -273,7 +275,7 @@ function soapCheck ($path2wsdl)
try
{

$sReturn = $client->sImportQuestion($user, $pass, $iVid, "Freitext", $qTitle, $qText, $qHelp,$mandatory);
$sReturn = $client->sImportFreetext($user, $pass, $iVid, $qTitle, $qText, $qHelp, "Freitext", $mandatory,0);
}
catch (SoapFault $fault)
{
Expand Down Expand Up @@ -665,7 +667,7 @@ function soapCheck ($path2wsdl)
echo "<br />";
//echo "<b><font color='red'>* </font>Data in this Format [params in square brackets are optional]:<br/> \"FIRSTNAME;LASTNAME;EMAIL[;[ATTRIB1];[ATTRIB2]]::FIRSTNAME;LASTNAME;EMAIL[;[ATTRIB1];[ATTRIB2]]\" and so on :</b> <br />";
echo "<b>Subject for custom cails</b> <br />";
echo "<input type='text' name='subject' size=50' maxlength='255' value=''/><br/>";
echo "<input type='text' name='subject' size='50' maxlength='255' value=''/><br/>";
echo "<b>Mailtext for custom cails</b> <br />";
echo "<textarea name='mailText' cols='50' rows='3'>";
echo "</textarea> ";
Expand Down
133 changes: 86 additions & 47 deletions admin/remotecontrol/lsrc_orig.wsdl
@@ -1,27 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<definitions name="LsrcService"
targetNamespace="urn:lsrcNamespace"
xmlns:tns="urn:lsrcNamespace"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:typens="lsrcSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

<types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:lsrcNamespace"><xsd:element name="string" type="xsd:string"></xsd:element></xsd:schema></types>
<message name="sCreateSurveyRequest">
<documentation>Function to start Surveys in LimeSurvey...</documentation>
<part name="sUser" type="xsd:string">
<documentation>Admin or Superadmin Account in Limesurvey needed
</documentation>
</part>
<part name="sPass" type="xsd:string">
<documentation>Correct password for the Superadmin in Limesurvey
</documentation>
</part>
<part name="iVid" type="xsd:int" >
<documentation>This is the &quot;VeranstaltungsID&quot; similar to the SurveyID...
Integer expected...
<definitions name="LsrcService" targetNamespace="urn:lsrcNamespace"
xmlns:tns="urn:lsrcNamespace" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:typens="lsrcSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:lsrcNamespace">
<xsd:element name="string" type="xsd:string"></xsd:element>
</xsd:schema>
</types>
<message name="sCreateSurveyRequest">
<documentation>Function to start Surveys in LimeSurvey...
</documentation>
<part name="sUser" type="xsd:string">
<documentation>Admin or Superadmin Account in Limesurvey needed
</documentation>
</part>
<part name="sPass" type="xsd:string">
<documentation>Correct password for the Superadmin in
Limesurvey
</documentation>
</part>
<part name="iVid" type="xsd:int">
<documentation>This is the &quot;VeranstaltungsID&quot; similar to the SurveyID... Integer expected... </documentation>
</part>
<part name="sVtit" type="xsd:string">
<documentation>titel of the event, put together from NR and NAME from LSF. veranstaltung</documentation></part>
Expand Down Expand Up @@ -173,18 +175,34 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
</message>
<message name="sImportGroupRequest">


<part name="sUser" type="xsd:string"></part>
<part name="sPass" type="xsd:string"></part>
<part name="iVid" type="xsd:int"></part>
<part name="sMod" type="xsd:string"></part>
<part name="sGroupName" type="xsd:string"></part>
<part name="sGroupDescription" type="xsd:string"></part>
</message>
<message name="sImportGroupResponse">
<part name="return" type="xsd:string"></part>
</message>
<message name="sImportGroupFault">
<part name="fault" element="xsd:string"></part>
</message>

<message name="sImportQuestionRequest">
<part name="sUser" type="xsd:string"></part>
<part name="sPass" type="xsd:string"></part>
<part name="iVid" type="xsd:int"></part>
<part name="sMod" type="xsd:string"></part>
<part name="sMandatory" type="xsd:string"></part>
</message>
<message name="sImportQuestionResponse">
<part name="return" type="xsd:string"></part>
</message>
<message name="sImportQuestionFault">
<part name="fault" element="xsd:string"></part>
</message>

<message name="sAvailableModulesRequest">
<part name="sUser" type="xsd:string"></part>
<part name="sPass" type="xsd:string"></part>
Expand All @@ -196,20 +214,19 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<message name="sAvailableModulesFault">
<part name="fault" element="xsd:string"></part>
</message>
<message name="sImportQuestionRequest">
<message name="sImportFreetextRequest">
<part name="sUser" type="xsd:string"></part>
<part name="sPass" type="xsd:string"></part>
<part name="iVid" type="xsd:int"></part>
<part name="sMod" type="xsd:string"></part>
<part name="sTitle" type="xsd:string"></part>
<part name="iVid" type="xsd:int"></part><part name="sTitle" type="xsd:string"></part>
<part name="sQuestion" type="xsd:string"></part>
<part name="sHelp" type="xsd:string"></part>
<part name="sMandatory" type="xsd:string"></part>
</message>
<message name="sImportQuestionResponse">
<part name="sHelp" type="xsd:string"></part>
<part name="sMod" type="xsd:string"></part>
<part name="sMandatory" type="xsd:string"></part>
</message>
<message name="sImportFreetextResponse">
<part name="return" type="xsd:string"></part>
</message>
<message name="sImportQuestionFault">
<message name="sImportFreetextFault">
<part name="fault" element="xsd:string"></part>
</message>
<message name="sImportMatrixRequest">
Expand Down Expand Up @@ -252,8 +269,9 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<part name="return" type="xsd:string"></part>
</message>
<message name="sSendEmailFault">
<part name="fault" element="tns:string"></part>
<part name="fault" element="xsd:string"></part>
</message>

<portType name="LsrcPortType">
<operation name="sCreateSurvey" >
<documentation>Creates (Import and activate) a Survey in LimeSurvey</documentation>
Expand Down Expand Up @@ -294,15 +312,20 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<output name="sImportGroupResponse" message="tns:sImportGroupResponse"></output>
<fault name="sImportGroupFault" message="tns:sImportGroupFault"></fault>
</operation>
<operation name="sImportQuestion">
<input name="sImportQuestionRequest" message="tns:sImportQuestionRequest"></input>
<output name="sImportQuestionResponse" message="tns:sImportQuestionResponse"></output>
<fault name="sImportQuestionFault" message="tns:sImportQuestionFault"></fault>
</operation>
<operation name="sAvailableModules">
<input name="sAvailableModulesRequest" message="tns:sAvailableModulesRequest"></input>
<output name="sAvailableModulesResponse" message="tns:sAvailableModulesResponse"></output>
<fault name="sAvailableModulesFault" message="tns:sAvailableModulesFault"></fault>
</operation>
<operation name="sImportQuestion">
<input name="sImportQuestionRequest" message="tns:sImportQuestionRequest"></input>
<output name="sImportQuestionResponse" message="tns:sImportQuestionResponse"></output>
<fault name="sImportQuestionFault" message="tns:sImportQuestionFault"></fault>
<operation name="sImportFreetext">
<input name="sImportFreetextRequest" message="tns:sImportFreetextRequest"></input>
<output name="sImportFreetextResponse" message="tns:sImportFreetextResponse"></output>
<fault name="sImportFreetextFault" message="tns:sImportFreetextFault"></fault>
</operation>
<operation name="sImportMatrix">
<input name="sImportMatrixRequest" message="tns:sImportMatrixRequest"></input>
Expand Down Expand Up @@ -372,6 +395,22 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
</fault>
</operation>

<operation name="sImportFreetext">
<soap:operation soapAction="urn:lsrcNamespaceAction" style="rpc" />
<input name="sImportFreetextRequest">
<soap:body namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output name="sImportFreetextResponse">
<soap:body namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
<fault name="sImportFreetextFault">
<soap:fault name="sImportFreetextFault" namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</fault>
</operation>

<operation name="sImportQuestion">
<soap:operation soapAction="urn:lsrcNamespaceAction" style="rpc" />
<input name="sImportQuestionRequest">
Expand Down Expand Up @@ -517,16 +556,16 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
</operation>
</binding>

<service name="LsrcService">
<documentation>This is the LsrcService
for remote starting surveys and registering tokens in LimeSurvey.
Make sure to modify the soap:address to the current Location of the lsrcserver.php
It has to be like this: 'http://servername/[limesurveydir]/lsrcservice/lsrcserver.php'
NOTE: http for normal mode, begin the url with https for a SSL Webservice, it's just that easy.
</documentation>
<port name="LsrcPort" binding="tns:LsrcBinding">
<soap:address location="{lsrclocation}" />
</port>
<service name="LsrcService">
<documentation>This is the LsrcService
for remote starting surveys and registering tokens in LimeSurvey.
Make sure to modify the soap:address to the current Location of the lsrcserver.php
It has to be like this: 'http://servername/[limesurveydir]/lsrcservice/lsrcserver.php'
NOTE: http for normal mode, begin the url with https for a SSL Webservice, it's just that easy.
</documentation>
<port name="LsrcPort" binding="tns:LsrcBinding">
<soap:address location="{lsrclocation}" />
</port>
</service>

</definitions>
Expand Down

0 comments on commit ea9c1f7

Please sign in to comment.