Exemplo n.º 1
0
 private function _array_filter_help($qidattributes, $surveyprintlang, $surveyid)
 {
     $clang = $this->getController()->lang;
     $output = "";
     if (!empty($qidattributes['array_filter'])) {
         $newquestiontext = Questions::model()->findByAttributes(array('title' => $qidattributes['array_filter'], 'language' => $surveyprintlang, 'sid' => $surveyid))->getAttribute('question');
         $output .= "\n<p class='extrahelp'>\n            " . sprintf($clang->gT("Only answer this question for the items you selected in question %s ('%s')"), $qidattributes['array_filter'], flattenText(breakToNewline($newquestiontext['question']))) . "\n            </p>\n";
     }
     if (!empty($qidattributes['array_filter_exclude'])) {
         $newquestiontext = Questions::model()->findByAttributes(array('title' => $qidattributes['array_filter_exclude'], 'language' => $surveyprintlang, 'sid' => $surveyid))->getAttribute('question');
         $output .= "\n    <p class='extrahelp'>\n            " . sprintf($clang->gT("Only answer this question for the items you did not select in question %s ('%s')"), $qidattributes['array_filter_exclude'], breakToNewline($newquestiontext['question'])) . "\n            </p>\n";
     }
     return $output;
 }
/**
* Marks a tokens as completed and sends a confirmation email to the participiant.
* If $quotaexit is set to true then the user exited the survey due to a quota
* restriction and the according token is only marked as 'Q'
*
* @param mixed $quotaexit
*/
function submittokens($quotaexit = false)
{
    $surveyid = Yii::app()->getConfig('surveyID');
    if (isset($_SESSION['survey_' . $surveyid]['s_lang'])) {
        $thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
    } else {
        $thissurvey = getSurveyInfo($surveyid);
    }
    $clienttoken = $_SESSION['survey_' . $surveyid]['token'];
    $sitename = Yii::app()->getConfig("sitename");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    // Shift the date due to global timeadjust setting
    $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
    // check how many uses the token has left
    $token = Token::model($surveyid)->findByAttributes(array('token' => $clienttoken));
    if ($quotaexit == true) {
        $token->completed = 'Q';
        $token->usesleft--;
    } else {
        if ($token->usesleft <= 1) {
            // Finish the token
            if (isTokenCompletedDatestamped($thissurvey)) {
                $token->completed = $today;
            } else {
                $token->completed = 'Y';
            }
            if (isset($token->participant_id)) {
                $slquery = SurveyLink::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid', array(':pid' => $token->participant_id, ':sid' => $surveyid, ':tid' => $token->tid));
                if ($slquery) {
                    if (isTokenCompletedDatestamped($thissurvey)) {
                        $slquery->date_completed = $today;
                    } else {
                        // Update the survey_links table if necessary, to protect anonymity, use the date_created field date
                        $slquery->date_completed = $slquery->date_created;
                    }
                    $slquery->save();
                }
            }
        }
        $token->usesleft--;
    }
    $token->save();
    if ($quotaexit == false) {
        if ($token && trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") {
            //   if($token->completed == "Y" || $token->completed == $today)
            //            {
            $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
            $subject = $thissurvey['email_confirm_subj'];
            $aReplacementVars = array();
            $aReplacementVars["ADMINNAME"] = $thissurvey['admin'];
            $aReplacementVars["ADMINEMAIL"] = $thissurvey['adminemail'];
            $aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
            //Fill with token info, because user can have his information with anonimity control
            $aReplacementVars["FIRSTNAME"] = $token->firstname;
            $aReplacementVars["LASTNAME"] = $token->lastname;
            $aReplacementVars["TOKEN"] = $token->token;
            // added survey url in replacement vars
            $surveylink = Yii::app()->createAbsoluteUrl("/survey/index/sid/{$surveyid}", array('lang' => $_SESSION['survey_' . $surveyid]['s_lang'], 'token' => $token->token));
            $aReplacementVars['SURVEYURL'] = $surveylink;
            $attrfieldnames = getAttributeFieldNames($surveyid);
            foreach ($attrfieldnames as $attr_name) {
                $aReplacementVars[strtoupper($attr_name)] = $token->{$attr_name};
            }
            $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']);
            $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']);
            $redata = array('thissurvey' => $thissurvey);
            $subject = templatereplace($subject, $aReplacementVars, $redata, '', false, null, array(), true);
            $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset);
            if (getEmailFormat($surveyid) == 'html') {
                $ishtml = true;
            } else {
                $ishtml = false;
            }
            $message = $thissurvey['email_confirm'];
            //$message=ReplaceFields($message, $fieldsarray, true);
            $message = templatereplace($message, $aReplacementVars, $redata, '', false, null, array(), true);
            if (!$ishtml) {
                $message = strip_tags(breakToNewline(html_entity_decode($message, ENT_QUOTES, $emailcharset)));
            } else {
                $message = html_entity_decode($message, ENT_QUOTES, $emailcharset);
            }
            //Only send confirmation email if there is a valid email address
            $sToAddress = validateEmailAddresses($token->email);
            if ($sToAddress) {
                $aAttachments = unserialize($thissurvey['attachments']);
                $aRelevantAttachments = array();
                /*
                 * Iterate through attachments and check them for relevance.
                 */
                if (isset($aAttachments['confirmation'])) {
                    foreach ($aAttachments['confirmation'] as $aAttachment) {
                        $relevance = $aAttachment['relevance'];
                        // If the attachment is relevant it will be added to the mail.
                        if (LimeExpressionManager::ProcessRelevance($relevance) && file_exists($aAttachment['url'])) {
                            $aRelevantAttachments[] = $aAttachment['url'];
                        }
                    }
                }
                SendEmailMessage($message, $subject, $sToAddress, $from, $sitename, $ishtml, null, $aRelevantAttachments);
            }
            //   } else {
            // Leave it to send optional confirmation at closed token
            //          }
        }
    }
}
Exemplo n.º 3
0
/**
* This function mails a text $body to the recipient $to.
* You can use more than one recipient when using a semikolon separated string with recipients.
*
* @param string $body Body text of the email in plain text or HTML
* @param mixed $subject Email subject
* @param mixed $to Array with several email addresses or single string with one email address
* @param mixed $from
* @param mixed $sitename
* @param mixed $ishtml
* @param mixed $bouncemail
* @param mixed $attachment
* @return bool If successful returns true
*/
function SendEmailMessage($body, $subject, $to, $from, $sitename, $ishtml = false, $bouncemail = null, $attachment = null, $customheaders = "")
{
    global $maildebug, $maildebugbody;
    $clang = Yii::app()->lang;
    $emailmethod = Yii::app()->getConfig('emailmethod');
    $emailsmtphost = Yii::app()->getConfig("emailsmtphost");
    $emailsmtpuser = Yii::app()->getConfig("emailsmtpuser");
    $emailsmtppassword = Yii::app()->getConfig("emailsmtppassword");
    $emailsmtpdebug = Yii::app()->getConfig("emailsmtpdebug");
    $emailsmtpssl = Yii::app()->getConfig("emailsmtpssl");
    $defaultlang = Yii::app()->getConfig("defaultlang");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    if ($emailcharset != 'utf-8') {
        $body = mb_convert_encoding($body, $emailcharset, 'utf-8');
        $subject = mb_convert_encoding($subject, $emailcharset, 'utf-8');
        $sitename = mb_convert_encoding($sitename, $emailcharset, 'utf-8');
    }
    if (!is_array($to)) {
        $to = array($to);
    }
    if (!is_array($customheaders) && $customheaders == '') {
        $customheaders = array();
    }
    if (Yii::app()->getConfig('demoMode')) {
        $maildebug = $clang->gT('Email was not sent because demo-mode is activated.');
        $maildebugbody = '';
        return false;
    }
    if (is_null($bouncemail)) {
        $sender = $from;
    } else {
        $sender = $bouncemail;
    }
    require_once APPPATH . '/third_party/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    if (!$mail->SetLanguage($defaultlang, APPPATH . '/third_party/phpmailer/language/')) {
        $mail->SetLanguage('en', APPPATH . '/third_party/phpmailer/language/');
    }
    $mail->CharSet = $emailcharset;
    if (isset($emailsmtpssl) && trim($emailsmtpssl) !== '' && $emailsmtpssl !== 0) {
        if ($emailsmtpssl === 1) {
            $mail->SMTPSecure = "ssl";
        } else {
            $mail->SMTPSecure = $emailsmtpssl;
        }
    }
    $fromname = '';
    $fromemail = $from;
    if (strpos($from, '<')) {
        $fromemail = substr($from, strpos($from, '<') + 1, strpos($from, '>') - 1 - strpos($from, '<'));
        $fromname = trim(substr($from, 0, strpos($from, '<') - 1));
    }
    $sendername = '';
    $senderemail = $sender;
    if (strpos($sender, '<')) {
        $senderemail = substr($sender, strpos($sender, '<') + 1, strpos($sender, '>') - 1 - strpos($sender, '<'));
        $sendername = trim(substr($sender, 0, strpos($sender, '<') - 1));
    }
    switch ($emailmethod) {
        case "qmail":
            $mail->IsQmail();
            break;
        case "smtp":
            $mail->IsSMTP();
            if ($emailsmtpdebug > 0) {
                $mail->SMTPDebug = $emailsmtpdebug;
            }
            if (strpos($emailsmtphost, ':') > 0) {
                $mail->Host = substr($emailsmtphost, 0, strpos($emailsmtphost, ':'));
                $mail->Port = substr($emailsmtphost, strpos($emailsmtphost, ':') + 1);
            } else {
                $mail->Host = $emailsmtphost;
            }
            $mail->Username = $emailsmtpuser;
            $mail->Password = $emailsmtppassword;
            if (trim($emailsmtpuser) != "") {
                $mail->SMTPAuth = true;
            }
            break;
        case "sendmail":
            $mail->IsSendmail();
            break;
        default:
            //Set to the default value to rule out incorrect settings.
            $emailmethod = "mail";
            $mail->IsMail();
    }
    $mail->SetFrom($fromemail, $fromname);
    $mail->Sender = $senderemail;
    // Sets Return-Path for error notifications
    foreach ($to as $singletoemail) {
        if (strpos($singletoemail, '<')) {
            $toemail = substr($singletoemail, strpos($singletoemail, '<') + 1, strpos($singletoemail, '>') - 1 - strpos($singletoemail, '<'));
            $toname = trim(substr($singletoemail, 0, strpos($singletoemail, '<') - 1));
            $mail->AddAddress($toemail, $toname);
        } else {
            $mail->AddAddress($singletoemail);
        }
    }
    if (is_array($customheaders)) {
        foreach ($customheaders as $key => $val) {
            $mail->AddCustomHeader($val);
        }
    }
    $mail->AddCustomHeader("X-Surveymailer: {$sitename} Emailer (LimeSurvey.sourceforge.net)");
    if (get_magic_quotes_gpc() != "0") {
        $body = stripcslashes($body);
    }
    if ($ishtml) {
        $mail->IsHTML(true);
        $mail->Body = $body;
        $mail->AltBody = strip_tags(breakToNewline(html_entity_decode($body, ENT_QUOTES, $emailcharset)));
    } else {
        $mail->IsHTML(false);
        $mail->Body = $body;
    }
    // add the attachment if there is one
    if (!is_null($attachment)) {
        $mail->AddAttachment($attachment);
    }
    if (trim($subject) != '') {
        $mail->Subject = "=?{$emailcharset}?B?" . base64_encode($subject) . "?=";
    }
    if ($emailsmtpdebug > 0) {
        ob_start();
    }
    $sent = $mail->Send();
    $maildebug = $mail->ErrorInfo;
    if ($emailsmtpdebug > 0) {
        $maildebug .= '<li>' . $clang->gT('SMTP debug output:') . '</li><pre>' . strip_tags(ob_get_contents()) . '</pre>';
        ob_end_clean();
    }
    $maildebugbody = $mail->Body;
    //if(!$sent) var_dump($maildebug);
    return $sent;
}
Exemplo n.º 4
0
 private function _array_filter_help($qidattributes, $sLanguageCode, $surveyid)
 {
     $output = "";
     if (!empty($qidattributes['array_filter'])) {
         $aFilter = explode(';', $qidattributes['array_filter']);
         $output .= "\n<p class='extrahelp'>";
         foreach ($aFilter as $sFilter) {
             $oQuestion = Question::model()->findByAttributes(array('title' => $sFilter, 'language' => $sLanguageCode, 'sid' => $surveyid));
             if ($oQuestion) {
                 $sNewQuestionText = flattenText(breakToNewline($oQuestion->getAttribute('question')));
                 $output .= sprintf(gT("Only answer this question for the items you selected in question %s ('%s')"), $qidattributes['array_filter'], $sNewQuestionText);
             }
         }
         $output .= "</p>\n";
     }
     if (!empty($qidattributes['array_filter'])) {
         $aFilter = explode(';', $qidattributes['array_filter']);
         $output .= "\n<p class='extrahelp'>";
         foreach ($aFilter as $sFilter) {
             $oQuestion = Question::model()->findByAttributes(array('title' => $sFilter, 'language' => $sLanguageCode, 'sid' => $surveyid));
             if ($oQuestion) {
                 $sNewQuestionText = flattenText(breakToNewline($oQuestion->getAttribute('question')));
                 $output .= sprintf(gT("Only answer this question for the items you did not select in question %s ('%s')"), $qidattributes['array_filter'], $sNewQuestionText);
             }
         }
         $output .= "</p>\n";
     }
     return $output;
 }
Exemplo n.º 5
0
/**
 * Marks a tokens as completed and sends a confirmation email to the participiant.
 * If $quotaexit is set to true then the user exited the survey due to a quota
 * restriction and the according token is only marked as 'Q'
 *
 * @param mixed $quotaexit
 */
function submittokens($quotaexit = false)
{
    global $thissurvey;
    global $surveyid;
    global $clienttoken;
    $clang = Yii::app()->lang;
    $sitename = Yii::app()->getConfig("sitename");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    // Shift the date due to global timeadjust setting
    $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
    // check how many uses the token has left
    $usesquery = "SELECT usesleft, participant_id, tid FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "'";
    $usesresult = dbExecuteAssoc($usesquery);
    $usesrow = $usesresult->read();
    if (isset($usesrow)) {
        $usesleft = $usesrow['usesleft'];
        $participant_id = $usesrow['participant_id'];
        $token_id = $usesrow['tid'];
    }
    $utquery = "UPDATE {{tokens_{$surveyid}}}\n";
    if ($quotaexit == true) {
        $utquery .= "SET completed='Q', usesleft=usesleft-1\n";
    } elseif (isTokenCompletedDatestamped($thissurvey)) {
        if (isset($usesleft) && $usesleft <= 1) {
            $utquery .= "SET usesleft=usesleft-1, completed='{$today}'\n";
            if (!empty($participant_id)) {
                //Update the survey_links table if necessary
                $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id);
                $slquery->date_completed = $today;
                $slquery->save();
            }
        } else {
            $utquery .= "SET usesleft=usesleft-1\n";
        }
    } else {
        if (isset($usesleft) && $usesleft <= 1) {
            $utquery .= "SET usesleft=usesleft-1, completed='Y'\n";
            if (!empty($participant_id)) {
                //Update the survey_links table if necessary, to protect anonymity, use the date_created field date
                $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id);
                $slquery->date_completed = $slquery->date_created;
                $slquery->save();
            }
        } else {
            $utquery .= "SET usesleft=usesleft-1\n";
        }
    }
    $utquery .= "WHERE token='" . $clienttoken . "'";
    $utresult = dbExecuteAssoc($utquery) or safeDie("Couldn't update tokens table!<br />\n{$utquery}<br />\n");
    //Checked
    if ($quotaexit == false) {
        // TLR change to put date into sent and completed
        $cnfquery = "SELECT * FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "' AND completed!='N' AND completed!=''";
        $cnfresult = dbExecuteAssoc($cnfquery);
        //Checked
        $cnfrow = $cnfresult->read();
        if (isset($cnfrow)) {
            $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
            $to = $cnfrow['email'];
            $subject = $thissurvey['email_confirm_subj'];
            $fieldsarray["{ADMINNAME}"] = $thissurvey['adminname'];
            $fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail'];
            $fieldsarray["{SURVEYNAME}"] = $thissurvey['name'];
            $fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description'];
            $fieldsarray["{FIRSTNAME}"] = $cnfrow['firstname'];
            $fieldsarray["{LASTNAME}"] = $cnfrow['lastname'];
            $fieldsarray["{TOKEN}"] = $clienttoken;
            $attrfieldnames = getAttributeFieldNames($surveyid);
            foreach ($attrfieldnames as $attr_name) {
                $fieldsarray["{" . strtoupper($attr_name) . "}"] = $cnfrow[$attr_name];
            }
            $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']);
            $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']);
            $fieldsarray["{EXPIRY}"] = convertDateTimeFormat($thissurvey["expiry"], 'Y-m-d H:i:s', $dateformatdatat['phpdate']);
            $subject = ReplaceFields($subject, $fieldsarray, true);
            $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset);
            if (getEmailFormat($surveyid) == 'html') {
                $ishtml = true;
            } else {
                $ishtml = false;
            }
            if (trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") {
                $message = $thissurvey['email_confirm'];
                $message = ReplaceFields($message, $fieldsarray, true);
                if (!$ishtml) {
                    $message = strip_tags(breakToNewline(html_entity_decode($message, ENT_QUOTES, $emailcharset)));
                } else {
                    $message = html_entity_decode($message, ENT_QUOTES, $emailcharset);
                }
                //Only send confirmation email if there is a valid email address
                if (validateEmailAddress($cnfrow['email'])) {
                    SendEmailMessage($message, $subject, $to, $from, $sitename, $ishtml);
                }
            } else {
                //There is nothing in the message or "Send confirmation emails" is set to "No" , so don't send a confirmation email
                //This section only here as placeholder to indicate new feature :-)
            }
        }
    }
}