View Issue Details

IDProjectCategoryView StatusLast Update
04942User patchesOtherpublic2012-06-21 14:18
ReporterIngrimmsch Assigned To 
PrioritynormalSeverityminor 
Status confirmedResolutionopen 
Product Version1.90 
Target VersionFixed in Version 
Summary04942: Send Message after X Answers
Description

Hi,

i made a new function that sends an email all X answers.

I modified the admin/html.php for the options,
the database.php to save the options,
the group.php for the mailfunction
the de.po, de.mo, en.po, en.mo for language
and (i have to look which file it is) the install file for the database.

if implemented you can choice a number and a emailadress.

if (answer % x == 0) a email will send with a static message with the info of how many ansers are complete and if expire date is set when the survey expires in days

like "The survey expires in 5 days"

i create a patch and attach it to the ticket.

TagsNo tags attached.
Complete LimeSurvey version number (& build)9561

Activities

Ingrimmsch

Ingrimmsch

2011-02-09 16:12

reporter   ~14114

Ok i begun with the patch and i found out i dont have to modify the html.php because in the dev version it is the editsurveysettings.php

Ingrimmsch

Ingrimmsch

2011-02-11 11:01

reporter   ~14144

can somebody tell me is there a bug in the function

SendEmailMessage() in the developer version??

i use the function and i get no email..
in my stable version it works....

Ingrimmsch

Ingrimmsch

2011-02-11 11:06

reporter  

SendMessageAfterAnswers.patch (12,038 bytes)
Index: admin/database.php
===================================================================
--- admin/database.php	(revision 9754)
+++ admin/database.php	(working copy)
@@ -1074,7 +1074,9 @@
                             'usecaptcha'=>$_POST['usecaptcha'],
                             'emailresponseto'=>trim($_POST['emailresponseto']),
                             'emailnotificationto'=>trim($_POST['emailnotificationto']),
-                            'tokenlength'=>$_POST['tokenlength']
+                            'tokenlength'=>$_POST['tokenlength'],
+                            'emailsend'=>$_POST['answercounter'],
+                            'infomail'=>$_POST['infomail']
         );
 
         $usquery=$connect->GetUpdateSQL($rs, $updatearray, false, get_magic_quotes_gpc());
@@ -1378,7 +1380,9 @@
                             'publicgraphs'=>$_POST['publicgraphs'],
                             'assessments'=>$_POST['assessments'],
                             'emailresponseto'=>$_POST['emailresponseto'],
-                            'tokenlength'=>$_POST['tokenlength']
+                            'tokenlength'=>$_POST['tokenlength'],
+                            'emailsend'=>$_POST['answercounter'],
+                            'infomail'=>$_POST['infomail']
         );
         $dbtablename=db_table_name_nq('surveys');
         $isquery = $connect->GetInsertSQL($dbtablename, $insertarray);
Index: admin/editsurveysettings.php
===================================================================
--- admin/editsurveysettings.php	(revision 9754)
+++ admin/editsurveysettings.php	(working copy)
@@ -866,7 +866,9 @@
         }
         $editsurvey .= ">".$clang->gT("No")."</option>\n"
         . "</select></li>\n";
+        
 
+        
             // Allow editing answers after completion 
             $editsurvey .= "<li><label for=''>".$clang->gT("Allow editing answers after completion?")."</label>\n"
             . "<select id='alloweditaftercompletion' name='alloweditaftercompletion' onchange=\"javascript: if (document.getElementById('private').value == 'Y') {alert('".$clang->gT("This option can't be set if Anonymous answers are used","js")."'); this.value='N';}\">\n"
@@ -915,8 +917,26 @@
         }
         $editsurvey .= ">".$clang->gT("No")."</option>\n"
         . "</select></li>\n";
-
-
+        
+        $editsurvey .= "<li><label for='answercounter'>".$clang->gT("send message after answer")."</label>\n"
+	    ."<input type='text' id='answercounter' name='answercounter' value='";
+            if (isset($esrow['emailsend'])) {
+                $editsurvey .= $esrow['emailsend'];
+            }
+            else {
+                $editsurvey .= "0";
+            }
+                $editsurvey .= "'/>\n"
+	    ."<input type='text' id='infomail' name='infomail' style='width:300px' value='";
+            if (isset($esrow['infomail'])) {
+                $editsurvey .= $esrow['infomail'];
+            }
+            else {
+                $editsurvey .= "mail";
+            }
+                $editsurvey .= "'/>\n"
+	    ."</li>\n";
+      
         // End Notification and Data management TAB
         $editsurvey .= "</ul></div>\n";
 
Index: admin/install/create-mssql.sql
===================================================================
--- admin/install/create-mssql.sql	(revision 9754)
+++ admin/install/create-mssql.sql	(working copy)
@@ -293,6 +293,8 @@
   [navigationdelay] tinyint default '0',
   [nokeyboard] char(1) default 'N',
   [alloweditaftercompletion] char(1) default 'N',
+  [emailsend] INT default 0,
+  [infomail] varchar(250) default 'mail',
   
   PRIMARY KEY  ([sid])
 ) 
Index: admin/install/create-mssqlnative.sql
===================================================================
--- admin/install/create-mssqlnative.sql	(revision 9754)
+++ admin/install/create-mssqlnative.sql	(working copy)
@@ -302,6 +302,8 @@
   [navigationdelay] tinyint default '0',
   [nokeyboard] char(1) default 'N',
   [alloweditaftercompletion] char(1) default 'N',
+  [emailsend] INT default 0,
+  [infomail] varchar(250) default 'mail',
   
   PRIMARY KEY  ([sid])
 ) 
Index: admin/install/create-mysql.sql
===================================================================
--- admin/install/create-mysql.sql	(revision 9754)
+++ admin/install/create-mysql.sql	(working copy)
@@ -282,6 +282,8 @@
   `navigationdelay` tinyint(2) default '0',
   `nokeyboard` char(1) default 'N',
   `alloweditaftercompletion` char(1) default 'N',
+  `emailsend` INT default 0,
+  `infomail` varchar(250) default 'mail',
    PRIMARY KEY(`sid`)
 ) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 
Index: admin/install/create-postgres.sql
===================================================================
--- admin/install/create-postgres.sql	(revision 9754)
+++ admin/install/create-postgres.sql	(working copy)
@@ -306,7 +306,9 @@
     allowjumps character(1) DEFAULT 'N'::bpchar,
     navigationdelay smallint DEFAULT '0',
     nokeyboard character(1) DEFAULT 'N'::bpchar,
-    alloweditaftercompletion character(1) DEFAULT 'N'::bpchar
+    alloweditaftercompletion character(1) DEFAULT 'N'::bpchar,
+    emailsend INT default 0,
+    infomail varchar(250) default 'mail',
 );
 
 ALTER TABLE ONLY prefix_surveys ADD CONSTRAINT prefix_surveys_pkey PRIMARY KEY (sid);
Index: group.php
===================================================================
--- group.php	(revision 9754)
+++ group.php	(working copy)
@@ -178,7 +178,37 @@
         }
         else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
         {
-            if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used
+            //Send Email after x answers
+            
+            //Look for restdays if expiredate is set
+            if (isset($thissurvey['expires'])) {
+                $endtimestamp = strtotime($thissurvey['expires']);
+                $nowtimestamp = date("U");
+                $restdays = ($endtimestamp-$nowtimestamp)/86400;
+                $pos = strpos($restdays,'.');
+                $restdays = substr($restdays,0,$pos);
+                $restdays = $clang->gT("survey expires in")." ".$restdays." ".$clang->gT("days");
+            }
+            else {
+                $restdays = '';
+            }
+            //find X 
+         //   $mysid = str_replace({$dbprefix}.'survey_','',$thissurvey['tablename']);
+            $checkemailvalue = "SELECT emailsend, infomail FROM {$dbprefix}surveys WHERE sid = '".$surveyid."'";
+	    $myresult = mysql_query($checkemailvalue);
+            $row = mysql_fetch_assoc($myresult);
+	    if ($row['emailsend'] != 0) {
+                //find number of answers out
+                $countanswers = "SELECT COUNT(*) AS counter FROM {$thissurvey['tablename']} WHERE submitdate IS NOT NULL";
+		$myresult = mysql_query($countanswers);
+                $row2 = mysql_fetch_assoc($myresult);
+                //if x is reached send email
+                if (($row2['counter']) % $row['emailsend'] == 0) {
+		    $message = $clang->gT("survey:")." ".$thissurvey['surveyls_title']."<br/>".$clang->gT("the survey contains")." ".($row2['counter'])." ".$clang->gT("complete answers")."<br/>".$restdays;
+                    SendEmailMessage($message, $clang->gT("current state")." ".$thissurvey['surveyls_title'], $row['infomail'], $thissurvey['adminemail'], 'Limesurvey', true);
+                }
+            }
+	    if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used
             {
                 $cookiename="PHPSID".returnglobal('sid')."STATUS";
                 setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
Index: locale/de/LC_MESSAGES/de.mo
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: locale/de/LC_MESSAGES/de.po
===================================================================
--- locale/de/LC_MESSAGES/de.po	(revision 9754)
+++ locale/de/LC_MESSAGES/de.po	(working copy)
@@ -3,8 +3,8 @@
 "Project-Id-Version: LimeSurvey German language file\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2011-01-08 15:59+0100\n"
-"PO-Revision-Date: 2011-01-08 16:01+0100\n"
-"Last-Translator: Carsten Schmitz <info@limesurvey.org>\n"
+"PO-Revision-Date: 2011-02-09 16:26+0100\n"
+"Last-Translator: dsf <sdf>\n"
 "Language-Team: LimeSurvey <c_schmitz@users.sourceforge.net>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
@@ -437,6 +437,30 @@
 msgid "Did Not Save"
 msgstr "Wurde nicht gespeichert"
 
+#: D:\web\xampp\htdocs\limesurvey/group.php:146
+msgid "survey expires in"
+msgstr "Die Umfrage l&auml;uft noch"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:146
+msgid "days"
+msgstr "Tage"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "survey:"
+msgstr "Umfrage:"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "the survey contains"
+msgstr "Die Umfrage enthält aktuell"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "complete answers"
+msgstr "komplette Antwortsätze"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:167
+msgid "current state"
+msgstr "Aktueller Stand der Umfrage:"
+
 #: D:\web\xampp\htdocs\limesurvey/common_functions.php:4317
 msgid "Disable only"
 msgstr "Nur deaktivieren"
@@ -5154,6 +5178,10 @@
 msgid "Create/Edit Users"
 msgstr "Erzeuge/Bearbeite Benutzer"
 
+#: D:\web\xampp\htdocs\limesurvey/admin/html.php:3468
+msgid "send message after answer"
+msgstr "Sende Benachrichtung nach Antworten (Anzahl)"
+
 #: D:\web\xampp\htdocs\limesurvey/admin/html.php:336
 msgid "Currently there are no additional languages configured for this survey."
 msgstr "Es sind momentan keine zusätzlichen Sprachen für diese Umfrage konfiguriert."
Index: locale/en/LC_MESSAGES/en.mo
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: locale/en/LC_MESSAGES/en.po
===================================================================
--- locale/en/LC_MESSAGES/en.po	(revision 9754)
+++ locale/en/LC_MESSAGES/en.po	(working copy)
@@ -8,8 +8,8 @@
 "Project-Id-Version: LimeSurvey\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2010-11-11 18:00+0100\n"
-"PO-Revision-Date: 2010-12-02 00:59+0100\n"
-"Last-Translator: Carsten Schmitz <info@limesurvey.org>\n"
+"PO-Revision-Date: 2011-02-09 16:25+0100\n"
+"Last-Translator: dsf <sdf>\n"
 "Language-Team: LimeSurvey <c_schmitz@users.sourceforge.net>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
@@ -570,6 +570,10 @@
 msgid "Base Language"
 msgstr "Base language"
 
+#: D:\web\xampp\htdocs\limesurvey/admin/editsurveysettings.php:921
+msgid "send message after answer"
+msgstr "Send Message after answer(number)"
+
 #: /var/lib/limesurvey-svn/subversion1x/admin/quota.php:465
 #: /var/lib/limesurvey-svn/subversion1x/admin/quota.php:895
 #, fuzzy
@@ -691,6 +695,30 @@
 msgid "Answers"
 msgstr ""
 
+#: D:\web\xampp\htdocs\limesurvey/group.php:146
+msgid "survey expires in"
+msgstr "The Survey expires in"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:146
+msgid "days"
+msgstr "days"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "survey:"
+msgstr "Survey:"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "the survey contains"
+msgstr "The survey contains"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:165
+msgid "complete answers"
+msgstr "complete answers"
+
+#: D:\web\xampp\htdocs\limesurvey/group.php:167
+msgid "current state"
+msgstr "Current state of survey:"
+
 #: /var/lib/limesurvey-svn/subversion1x/admin/quota.php:607
 #: /var/lib/limesurvey-svn/subversion1x/admin/quota.php:708
 #: /var/lib/limesurvey-svn/subversion1x/admin/quota.php:715
Ingrimmsch

Ingrimmsch

2011-02-11 11:07

reporter   ~14145

Ok i tried to use the invite function and there comes no email either..

so i would say the patch is working...

to test it you can make an echo in the group.php in:

if (($row2['counter']) % $row['emailsend'] == 0) {
$message = $clang->gT("survey:")." ".$thissurvey['surveyls_title']."<br />".$clang->gT("the survey contains")." ".($row2['counter'])." ".$clang->gT("complete answers")."<br />".$restdays;
SendEmailMessage($message, $clang->gT("current state")." ".$thissurvey['surveyls_title'], $row['infomail'], $thissurvey['adminemail'], 'Limesurvey', true);
}

The other files i editet was the sqlscripts in the installfolder.

If you have questions feel free to ask

c_schmitz

c_schmitz

2011-02-11 22:02

administrator   ~14164

Can you explain the purpose of this patch? What kind of email is sent?

Ingrimmsch

Ingrimmsch

2011-02-16 11:34

reporter   ~14197

Situation:

A User want to make a survey. You as the Admin create the survey for the user. The User has no idea of "using a Pc ;-)" and it would be to complicated to him to look himself at the results.

But the User want informations about the survey.

So you can configure this fucntion in the backend to send a email at the user all 20 results.

So the User get an email after 20, 40, 60.... results with the message.

The survey [surveyname] has 20 results.

if expire date is set the next line is

The survey expires in XX days.

So its only to inform an user without looking to the backend.

Its very useful if you make many surveys for other people and dont want to get a call every few days with the question "what is the actual state of my survey?"

c_schmitz

c_schmitz

2011-03-28 02:21

administrator   ~14577

Thank you for sharing this patch, but currently this functionality is too specific to be included in the core. We will keep thi issue open ofr reference though so other can pick up on it.

Issue History

Date Modified Username Field Change
2011-02-09 15:07 Ingrimmsch New Issue
2011-02-09 16:12 Ingrimmsch Note Added: 14114
2011-02-11 11:01 Ingrimmsch Note Added: 14144
2011-02-11 11:06 Ingrimmsch File Added: SendMessageAfterAnswers.patch
2011-02-11 11:07 Ingrimmsch Note Added: 14145
2011-02-11 22:02 c_schmitz Note Added: 14164
2011-02-16 11:34 Ingrimmsch Note Added: 14197
2011-03-28 02:21 c_schmitz Note Added: 14577
2011-03-28 02:21 c_schmitz Assigned To => c_schmitz
2011-03-28 02:21 c_schmitz Status new => confirmed
2012-06-21 14:18 c_schmitz Assigned To c_schmitz =>