Skip to content

Commit

Permalink
Added Feature: lsrc can send statistics as pdf or xls attachment to a…
Browse files Browse the repository at this point in the history
…n email recipient. html Mail to come.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@7248 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Tim Wahrendorff committed Jul 8, 2009
1 parent 9df7274 commit 689b793
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 7 deletions.
14 changes: 14 additions & 0 deletions admin/remotecontrol/lsrc.helper.php
Expand Up @@ -3901,6 +3901,20 @@ function FieldMap2CSV($surveyid)
}
return $result;
}

function sendStatistic($surveyid, $to, $tempFile)
{
include("lsrc.config.php");
global $sitename;
global $clang;

$subject = $clang->gT("Statistics Survey #");
$message = $clang->gT("This is your personal statistic sheet for survey #");

MailTextMessage($message.$surveyid, $subject.$surveyid, $to , getBounceEmail($surveyid), $sitename, $ishtml, getBounceEmail($surveyid), $tempFile);

}

function removeBOM($str=""){
if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$str=substr($str, 3);
Expand Down
118 changes: 116 additions & 2 deletions admin/remotecontrol/lsrc.server.php
Expand Up @@ -24,6 +24,10 @@
require_once($rootdir.'/classes/core/language.php');
$clang = new limesurvey_lang($defaultlang);

// to generate statistics
include_once($rootdir."/classes/core/sanitize.php");
include_once($rootdir.'/admin/statistics_function.php');

/**
* if ?wsdl is set, generate wsdl with correct uri and send it back to whoever requesting
*/
Expand Down Expand Up @@ -87,6 +91,7 @@
$server->addFunction("sImportFreetext");
$server->addFunction("sSendEmail");
$server->addFunction("sGetFieldmap");
$server->addFunction("fSendStatistic");
// handle the soap request!
if($enableLsrc==true)
{
Expand Down Expand Up @@ -927,7 +932,7 @@ function sImportMatrix($sUser, $sPass, $iVid, $qTitle, $qText, $qHelp, $sItems,

global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
//$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");

$lsrcHelper = new lsrcHelper();
Expand Down Expand Up @@ -1116,7 +1121,115 @@ function sDeleteSurvey($sUser, $sPass, $iVid)


}

/**
*
* Enter description here...
* @param $sUser Limesurvey user
* @param $sPass Password
* @param $iVid surveyid
* @param $email e-mail adress of the recipient
* @param $docType pdf, xls or html
* @return "OK" or SoapFault
*/
function fSendStatistic($sUser, $sPass, $iVid, $email, $docType='pdf', $graph=0)
{
global $connect ;
global $dbprefix ;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include("lsrc.config.php");
$lsrcHelper = new lsrcHelper();

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 get fieldmaps from other peoples Surveys");
exit;
}
if(!$lsrcHelper->surveyExists($iVid))
{
throw new SoapFault("Database: ", "Survey $iVid does not exists");
exit;
}
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",sid=$iVid START OK ");

/**
* Build up the fields to generate statistics from
*/
$summarySql=" SELECT gid, lid, qid, type "
." FROM {$dbprefix}questions "
." WHERE sid=$surveyid ";

$summaryRs = $connect->Execute($summarySql);
$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",sid=$iVid OK ");
foreach($summaryRs as $field)
{
$myField = $surveyid."X".$field['gid']."X".$field['qid'];

// Multiple Options get special treatment
if ($field['type'] == "M" || $field['type'] == "P") {$myField = "M$myField";}
//numerical input will get special treatment (arihtmetic mean, standard derivation, ...)
if ($field['type'] == "N") {$myField = "N$myField";}

if ($field['type'] == "Q") {$myField = "Q$myField";}
// textfields get special treatment
if ($field['type'] == "S" || $field['type'] == "T" || $field['type'] == "U"){$myField = "T$myField";}
//statistics for Date questions are not implemented yet.
if ($field['type'] == "D") {$myField = "D$myField";}
if ($field['type'] == "F" || $field['type'] == "H")
{
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
//Get answers. We always use the answer code because the label might be too long elsewise
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='".$field['qid']."' AND language='{$language}' ORDER BY sortorder, answer";
$result = $connect->Execute($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;

//check all the answers
while ($row=$result->FetchRow())
{
$myField = "$myField{$row[0]}";
}
//$myField = "{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]";


}
$summary[]=$myField;

}

$lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",".print_r($summary)." ");
switch ($docType)
{
case 'pdf':
$tempFile = generate_statistics($iVid,$summary,'all',$graph,$docType,'F');

$lsrcHelper->sendStatistic($iVid, $email, $tempFile);
unlink($tempFile);
return "PDF send";
break;
case 'xls':
$tempFile = generate_statistics($iVid,$summary,'all',0,$docType, 'F');

$lsrcHelper->sendStatistic($iVid, $email, $tempFile);
unlink($tempFile);
return 'XLS send';

break;
case 'html':
generate_statistics($iVid,$summary,'all',$graph,$docType, 'F');


return 'HTML send';
break;
}




}
/**
*
* This function pulls a CSV representation of the Field map
Expand Down Expand Up @@ -1150,4 +1263,5 @@ function sGetFieldmap($sUser, $sPass, $iVid)
return $returnCSV;

}

?>
48 changes: 43 additions & 5 deletions admin/remotecontrol/lsrc.testclient.php
Expand Up @@ -196,6 +196,27 @@ function soapCheck ($path2wsdl)
reset($_REQUEST);
while(list($key, $value) = each($_REQUEST))
{
if(substr($key,0,13)=="sendStatistic")
{
$iVid = $_REQUEST['sid'];
$type = $_REQUEST['type'];
$email = $_REQUEST['email'];
$graph = $_REQUEST['graph'];

try
{
$sReturn = $client->fSendStatistic($user, $pass, $iVid, $email, $type, $graph);
}
catch (SoapFault $fault)
{
$sOutput .= " <br/><br/><b>SOAP Error: ".$fault->faultcode." : ".$fault->faultstring."</b>";
}
//these are just outputs for testing
$sOutput .= "<br/><br/><b>Return</b>: ". $sReturn;



}
if(substr($key,0,8)=="sendMail")
{
$iVid = $_REQUEST['sid'];
Expand Down Expand Up @@ -643,7 +664,7 @@ function soapCheck ($path2wsdl)
<br />--> <input type='submit' name='change' value='Change Survey!' /></form>

</div>
<div style='float:left;margin-bottom:5px'>
<div style='float:left;margin-bottom:5px;margin-left:5px;'>
<?php
echo "<h3>sInsertToken function</h3>";
echo "<p>Makes the Survey closed.<br/> Means: It's only available to people who have an unused token</p>";
Expand All @@ -660,7 +681,7 @@ function soapCheck ($path2wsdl)
echo "</div>";


echo "<div style='float:right; margin-bottom:5px'>";
echo "<div style='float:left; margin-bottom:5px;margin-left:5px;'>";
echo "<h3>sTokenReturn function</h3>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
echo "<b><font color='red'>* </font>VeranstaltungsID / SurveyID (have to be Integer):</b> <br />";
Expand All @@ -669,7 +690,7 @@ function soapCheck ($path2wsdl)
echo "<input type='hidden' name='wsdl' size='97' value='".$wsdl."' />";
echo "</form></div>";

echo "<div style='clear:both;margin-bottom:5px'>";
echo "<div style='float:left;margin-bottom:5px;margin-left:5px;'>";
echo "<h3>sInsertParticipants function</h3>";
echo "<p>Makes the Survey closed. Means: It's only available to people who have an unused token</p>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
Expand All @@ -685,7 +706,7 @@ function soapCheck ($path2wsdl)
echo "</form>";
echo "</div>";

echo "<div style='clear:both;margin-bottom:5px'>";
echo "<div style='float:left;margin-bottom:5px;margin-left:5px;'>";
echo "<h3>sSendEmail function</h3>";
echo "<p>Sends an Email to users of a specific survey. Invite, Remind and custom emails are possible</p>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
Expand All @@ -711,7 +732,7 @@ function soapCheck ($path2wsdl)
echo "</form>";
echo "</div>";

echo "<div style='float:right; margin-bottom:5px'>";
echo "<div style='float:left; margin-bottom:5px;margin-left:5px;'>";
echo "<h3>sGetFieldmap function</h3>";
echo "<p>Gets you the fieldmap from a survey as csv</p>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
Expand All @@ -720,6 +741,23 @@ function soapCheck ($path2wsdl)
echo "<input type='submit' name='getField' value='Get me the Fieldmap as CSV!'/>";
echo "<input type='hidden' name='wsdl' size='97' value='".$wsdl."' />";
echo "</form></div>";

echo "<div style='float:left; margin-bottom:5px;margin-left:5px;'>";
echo "<h3>fSendStatistic function</h3>";
echo "<p>Gets statistic from a survey and sends it to an E-Mail recipient</p>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
echo "<b><font color='red'>* </font>VeranstaltungsID / SurveyID (have to be Integer):</b> <br />";
echo "<input type='text' name='sid' value='".$iVid."' maxlength='5'/><br />";
echo "<b><font color='red'>* </font>E-Mail Adress:</b> <br />";
echo "<input type='text' name='email' value='' maxlength='50' size='50'/><br />";
echo "<input type='checkbox' name='graph' value='1' />Include graphs (only with pdf generation) <br />";
echo "<input type='radio' name='type' value='pdf' checked='checked' />PDF attachement";
echo "<input type='radio' name='type' value='xls' />Excel attachement";
echo "<input type='radio' name='type' value='html' />HTML Mail<br/>";

echo "<input type='submit' name='sendStatistic' value='Send a Statistic'/>";
echo "<input type='hidden' name='wsdl' size='97' value='".$wsdl."' />";
echo "</form></div>";
//phpinfo();

?>
Expand Down
35 changes: 35 additions & 0 deletions admin/remotecontrol/lsrc_orig.wsdl
Expand Up @@ -286,6 +286,20 @@
<message name="sGetFieldmapFault">
<part name="fault" element="xsd:string"></part>
</message>
<message name="fSendStatisticRequest">
<part name="sUser" type="xsd:string"></part>
<part name="sPass" type="xsd:string"></part>
<part name="iVid" type="xsd:string"></part>
<part name="email" type="xsd:string"></part>
<part name="doctype" type="xsd:string"></part>
<part name="graph" type="xsd:string"></part>
</message>
<message name="fSendStatisticResponse">
<part name="return" type="xsd:string"></part>
</message>
<message name="fSendStatisticFault">
<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 @@ -360,12 +374,33 @@
<input message="tns:sGetFieldmapRequest" name="sGetFieldmapRequest"></input>
<output message="tns:sGetFieldmapResponse" name="sGetFieldmapResponse"></output>
<fault name="sGetFieldmapFault" message="tns:sGetFieldmapFault"></fault>
</operation>
<operation name="fSendStatistic">
<input message="tns:fSendStatisticRequest" name="fSendStatistic"></input>
<output message="tns:fSendStatisticResponse" name="fSendStatistic"></output>
<fault name="fSendStatisticsFault" message="tns:fSendStatisticFault"></fault>
</operation>
</portType>

<binding name="LsrcBinding" type="tns:LsrcPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />

<operation name="fSendStatistic">
<soap:operation soapAction="urn:lsrcNamespaceAction" style="rpc" />
<input name="fSendStatisticRequest">
<soap:body namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output name="fSendStatisticResponse">
<soap:body namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
<fault name="fSendStatisticFault">
<soap:fault name="fSendStatisticFault" namespace="urn:lsrcNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</fault>
</operation>

<operation name="sGetFieldmap">
<soap:operation soapAction="urn:lsrcNamespaceAction" style="rpc" />
<input name="sGetFieldmapRequest">
Expand Down

0 comments on commit 689b793

Please sign in to comment.