Skip to content

Commit

Permalink
Commit for GCI task #7232222 Port the frontend optin and optout contr…
Browse files Browse the repository at this point in the history
…ollers to the Yii framework by Gaurav Narula

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11712 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Gaurav Narula committed Dec 21, 2011
1 parent 94ca53f commit 2e0dc94
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 168 deletions.
155 changes: 68 additions & 87 deletions application/controllers/optin.php
@@ -1,7 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* 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
Expand All @@ -10,98 +10,88 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: Admin_Controller.php 11256 2011-10-25 13:52:18Z c_schmitz $
*
*
*/
/**
* optout
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class optin extends LSCI_Controller {

/**
* optout::__construct()
* Constructor
* @return
*/
/* function __construct()
{
parent::__construct();
}
*/
function local()
{
$this->load->helper('database');
$this->load->helper('sanitize');
$sLanguageCode=$this->uri->segment(3);
$iSurveyID=$this->uri->segment(4);
$sToken=$this->uri->segment(5);
$sToken=sanitize_token($sToken);
/**
* optin
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class optin extends LSYii_Controller {

function __construct()
{
parent::__construct();
}

function local($langcode, $surveyid, $token)
{
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
$sLanguageCode = $langcode;
$iSurveyID = $urveyid
$sToken = $token;
$sToken = sanitize_token($sToken);

if (!$iSurveyID)
{
//You must have an SID to use this
redirect(); //include "index.php";
//exit;
}
$iSurveyID = (int)$iSurveyID;
//Check that there is a SID
if (!$iSurveyID)
{
$this->redirect($this->getController()->createUrl('/'));
}
$iSurveyID = (int)$iSurveyID;

//Check that there is a SID
// Get passed language from form, so that we dont loose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode)
{
$baselang = GetBaseLanguageFromSurveyID($iSurveyID);
$this->load->library('Limesurvey_lang',array($baselang));
$clang = $this->limesurvey_lang;

//$baselang = GetBaseLanguageFromSurveyID($iSurveyID);
//$clang = new limesurvey_lang($baselang);
} else {
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang(array('langcode' => $baselang));
}
else
{
$sLanguageCode = sanitize_languagecode($sLanguageCode);
$this->load->library('Limesurvey_lang',array($sLanguageCode));
$clang = $this->limesurvey_lang;
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang(array('langcode' => $sLanguageCode));
$baselang = $sLanguageCode;



//$clang = new limesurvey_lang($sLanguageCode);
//$baselang = $sLanguageCode;
}

$thissurvey=getSurveyInfo($iSurveyID,$baselang);

$html='<div id="wrapper"><p id="optoutmessage">';
if ($thissurvey==false || !tableExists("tokens_{$iSurveyID}")){
$html .= $clang->gT('This survey does not seem to exist.');
if ($thissurvey == false || Yii::app()->db->schema->getTable("tokens_{$iSurveyID}") == null)
{
$html = $clang->gT('This survey does not seem to exist.');
}
else
{
$usquery = "SELECT emailstatus from ".$this->db->dbprefix."tokens_{$iSurveyID} where token='".$sToken."'";
$res=db_execute_assoc($usquery);
$row=$res->row_array();
$usresult = $row['emailstatus']; //'$connect->GetOne($usquery);
$row = Tokens_dynamic::getEmailStatus($iSurveyID, $sToken);

if ($usresult==false)
if ($row == false)
{
$html .= $clang->gT('You are not a participant in this survey.');
}
elseif ($usresult=='OptOut')
{
$usquery = "Update ".$this->db->dbprefix."tokens_{$iSurveyID} set emailstatus='OK' where token='".$sToken."'";
$usresult = db_execute_assoc($usquery);
$html .= $clang->gT('You have been successfully added back to this survey.');
}
elseif ($usresult=='OK')
{
$html .= $clang->gT('You are already a part of this survey.');
$html = $clang->gT('You are not a participant in this survey.');
}
else
{
$html .= $clang->gT('You have been already removed from this survey.');
$usresult = $row['emailstatus'];
if ($usresult=='OptOut')
{
$usresult = Tokens_dynamic::updateEmailStatus($iSurveyID, $sToken, 'OK');
$html = $clang->gT('You have been successfully added back to this survey.');
}
else if ($usresult=='OK')
{
$html = $clang->gT('You are already a part of this survey.');
}
else
{
$html = $clang->gT('You have been already removed from this survey.');
}
}
}
$html .= '</p></div>';

//PRINT COMPLETED PAGE
if (!$thissurvey['templatedir'])
Expand All @@ -112,25 +102,16 @@ function local()
{
$thistpl=sGetTemplatePath($thissurvey['templatedir']);
}
$this->_renderHtml($html,$thistpl);
}

private function _renderHtml($html,$thistpl)
{
sendcacheheaders();
doHeader();

echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
echo templatereplace(file_get_contents("$thistpl/survey.pstpl"));
echo $html;
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));

$data['html'] = $html;
$data['thistpl'] = $thistpl;
$this->getController()->render('/opt_view',$data);
doFooter();
}

/**
* optout::index()
* Function responsible to process opting out from a survey and display appropriate message.
* @param mixed $iSurveyID
* @param mixed $sLanguageCode
* @param mixed $sToken
* @return
*/

}
140 changes: 59 additions & 81 deletions application/controllers/optout.php
Expand Up @@ -13,92 +13,77 @@
* $Id: Admin_Controller.php 11256 2011-10-25 13:52:18Z c_schmitz $
*/

/**
* optout
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class optout extends LSCI_Controller {
/**
* optout
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class optout extends LSYii_Controller {

function __construct()
{
parent::__construct();
}

function local($langcode, $surveyid, $token)
{
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
$sLanguageCode = $langcode;
$iSurveyID = $urveyid
$sToken = $token;
$sToken = sanitize_token($sToken);

/**
* optout::__construct()
* Constructor
* @return
*/
/* function __construct()
{
parent::__construct();
}
*/
function local()
{
$this->load->helper('database');
$this->load->helper('sanitize');
$sLanguageCode=$this->uri->segment(3);
$iSurveyID=$this->uri->segment(4);
$sToken=$this->uri->segment(5);
$sToken=sanitize_token($sToken);

if (!$iSurveyID)
{
//You must have an SID to use this
redirect(); //include "index.php";
//exit;
}
$iSurveyID = (int)$iSurveyID;
//Check that there is a SID
if (!$iSurveyID)
{
$this->redirect($this->getController()->createUrl('/'));
}
$iSurveyID = (int)$iSurveyID;
//Check that there is a SID
// Get passed language from form, so that we dont loose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode)
{
$baselang = GetBaseLanguageFromSurveyID($iSurveyID);
$this->load->library('Limesurvey_lang',array($baselang));
$clang = $this->limesurvey_lang;

//$baselang = GetBaseLanguageFromSurveyID($iSurveyID);
//$clang = new limesurvey_lang($baselang);
} else {
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang(array('langcode' => $baselang));
}
else
{
$sLanguageCode = sanitize_languagecode($sLanguageCode);
$this->load->library('Limesurvey_lang',array($sLanguageCode));
$clang = $this->limesurvey_lang;
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang(array('langcode' => $sLanguageCode));
$baselang = $sLanguageCode;



//$clang = new limesurvey_lang($sLanguageCode);
//$baselang = $sLanguageCode;
}
$thissurvey=getSurveyInfo($iSurveyID,$baselang);

$html='<div id="wrapper"><p id="optoutmessage">';
if ($thissurvey==false || !tableExists("tokens_{$iSurveyID}")){
$html .= $clang->gT('This survey does not seem to exist.');
$html = $clang->gT('This survey does not seem to exist.');
}
else
{
$usquery = "SELECT emailstatus from ".$this->db->dbprefix."tokens_{$iSurveyID} where token='".$sToken."'";
$res=db_execute_assoc($usquery);
$row=$res->row_array();
$usresult = $row['emailstatus']; //'$connect->GetOne($usquery);
$row = Tokens_dynamic::getEmailStatus($iSurveyID, $sToken);

if ($usresult==false)
{
$html .= $clang->gT('You are not a participant in this survey.');
}
elseif ($usresult=='OK')
if ($row == false)
{
$usquery = "Update ".$this->db->dbprefix."tokens_{$iSurveyID} set emailstatus='OptOut' where token='".$sToken."'";
$usresult = db_execute_assoc($usquery);
$html .= $clang->gT('You have been successfully removed from this survey.');
$html = $clang->gT('You are not a participant in this survey.');
}
else
{
$html .= $clang->gT('You have been already removed from this survey.');
}
$usresult = $row['emailstatus'];
if ($usresult == 'OK')
{
$usresult = Tokens_dynamic::updateEmailStatus($iSurveyID, $sToken, 'OptOut');
$html = $clang->gT('You have been successfully removed from this survey.');
}
else
{
$html = clang->gT('You have been already removed from this survey.');
}
}
}
$html .= '</p></div>';

//PRINT COMPLETED PAGE
if (!$thissurvey['templatedir'])
Expand All @@ -110,24 +95,17 @@ function local()
$thistpl=sGetTemplatePath($thissurvey['templatedir']);
}

$this->_renderHtml($html,$thistpl);
}

private function _renderHtml($html,$thistpl)
{
sendcacheheaders();
doHeader();

echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
echo templatereplace(file_get_contents("$thistpl/survey.pstpl"));
echo $html;
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));

$data['html'] = $html;
$data['thistpl'] = $thistpl;
$this->getController()->render('/opt_view',$data);
doFooter();
}

/**
* optout::index()
* Function responsible to process opting out from a survey and display appropriate message.
* @param mixed $iSurveyID
* @param mixed $sLanguageCode
* @param mixed $sToken
* @return
*/

}
11 changes: 11 additions & 0 deletions application/models/Tokens_dynamic.php
Expand Up @@ -463,5 +463,16 @@ function deleteRecords($tokenids)
$dlquery = "DELETE FROM ".Tokens_dynamic::tableName()." WHERE tid IN (".implode(", ", $tokenids).")";
return Yii::app()->db->createCommand($dlquery)->query();
}

function getEmailStatus($sid,$token)
{
$usquery = 'SELECT emailstatus from {{tokens_'.$sid.'}} where token="'.$token.'"';
return Yii::app()->db->createCommand($usquery)->queryRow();
}

function updateEmailStatus($sid,$token,$status)
{
return Yii::app()->db->createCommand()-update('{{tokens_'.$sid'}}',array('emailastatus' => $status),'token = :token',array(':token' => $token ));
}
}
?>

0 comments on commit 2e0dc94

Please sign in to comment.