Skip to content

Commit

Permalink
New Feature #05044: Allowing selection of token valid from/until datea(
Browse files Browse the repository at this point in the history
…#1)

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11291 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Oct 27, 2011
1 parent 140b76f commit c75b7cf
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 18 deletions.
52 changes: 47 additions & 5 deletions application/controllers/register.php
Expand Up @@ -33,6 +33,34 @@ function __construct()
{
parent::__construct();
}

function ajaxregisterform($surveyid)
{
$this->load->helper('database');
$this->load->helper('replacements');
$redata = compact(array_keys(get_defined_vars()));
$thistpl = $this->config->item("standardtemplaterootdir").'/default';
$surveyid = sanitize_int($surveyid);
$squery = "SELECT a.expires, a.startdate
FROM ".$this->db->dbprefix('surveys')." AS a
WHERE a.sid = $surveyid ";


$sresult = db_execute_assoc($squery) or show_error("Couldn't execute $squery");


$row = $sresult->row_array();

$data['sid'] = $surveyid;
$data['startdate'] = $row['startdate'];
$data['enddate'] = $row['expires'];

$baselang = GetBaseLanguageFromSurveyID($surveyid);
$this->load->library('Limesurvey_lang',array($baselang));
$data['clang'] = $this->limesurvey_lang;
echo templatereplace(file_get_contents("$thistpl/register.pstpl"),array(),$redata,'register.php',false,NULL,$data);

}

/**
* register::index()
Expand All @@ -44,6 +72,7 @@ function index()

$surveyid=$this->input->post('sid');
$postlang=$this->input->post('lang');

if (!$surveyid)
{
redirect();
Expand All @@ -63,7 +92,7 @@ function index()
session_name("LimeSurveyRuntime-$surveyid");
}

session_set_cookie_params(0,$relativeurl.'/');
session_set_cookie_params(0,$this->config->item('relativeurl').'/');
session_start();

// Get passed language from form, so that we dont loose this!
Expand Down Expand Up @@ -101,8 +130,9 @@ function index()

if ($register_errormsg != "")
{
redirect();
redirect($surveyid);
}

$dbprefix = $this->db->dbprefix;
//Check if this email already exists in token database
$query = "SELECT email FROM {$dbprefix}tokens_$surveyid\n"
Expand All @@ -111,7 +141,7 @@ function index()
if (($result->num_rows()) > 0)
{
$register_errormsg=$clang->gT("The email you used has already been registered.");
redirect();
redirect($surveyid);
//include "index.php";
//exit;
}
Expand Down Expand Up @@ -139,13 +169,25 @@ function index()

$postfirstname=sanitize_xss_string(strip_tags($_POST['register_firstname']));
$postlastname=sanitize_xss_string(strip_tags($_POST['register_lastname']));
$starttime = sanitize_xss_string($this->input->post('startdate'));
$endtime = sanitize_xss_string($this->input->post('enddate'));
/*$postattribute1=sanitize_xss_string(strip_tags(returnglobal('register_attribute1')));
$postattribute2=sanitize_xss_string(strip_tags(returnglobal('register_attribute2'))); */

//Insert new entry into tokens db
$query = "INSERT INTO {$dbprefix}tokens_$surveyid\n"
. "(firstname, lastname, email, emailstatus, token)\n"
. "VALUES ('$postfirstname', '$postlastname', '".$_POST['register_email']."', 'OK', '$newtoken')";
. "(firstname, lastname, email, emailstatus, token";

if ($starttime && $endtime)
$query .= ", validfrom, validuntil";

$query .=")\n"
. "VALUES ('$postfirstname', '$postlastname', '".$_POST['register_email']."', 'OK', '$newtoken'";

if ($starttime && $endtime)
$query .= ",$starttime,$endtime";

$query .=")";
$result = db_execute_assoc($query);
/**
$result = $connect->Execute($query, array($postfirstname,
Expand Down
53 changes: 51 additions & 2 deletions application/controllers/survey.php
Expand Up @@ -301,8 +301,9 @@ function action()
AND ((a.expires >= '".date("Y-m-d H:i")."') OR (a.expires is null))
AND ((a.startdate <= '".date("Y-m-d H:i")."') OR (a.startdate is null))
ORDER BY surveyls_title";
$result = db_execute_assoc($query,false,true) or die("Could not connect to database. If you try to install LimeSurvey please refer to the <a href='http://docs.limesurvey.org'>installation docs</a> and/or contact the system administrator of this webpage."); //Checked
$result = db_execute_assoc($query,false,true) or show_error("Could not connect to database. If you try to install LimeSurvey please refer to the <a href='http://docs.limesurvey.org'>installation docs</a> and/or contact the system administrator of this webpage."); //Checked
$list=array();

if($result->num_rows() > 0)
{
foreach($result->result_array() as $rows)
Expand All @@ -318,6 +319,38 @@ function action()
$list[]=$link;
}
}
//Check for inactive surveys which allow public registration.
$squery = "SELECT a.sid, b.surveyls_title, a.publicstatistics
FROM ".$this->db->dbprefix('surveys')." AS a
INNER JOIN ".$this->db->dbprefix('surveys_languagesettings')." AS b
ON ( surveyls_survey_id = a.sid AND surveyls_language = a.language )
WHERE surveyls_survey_id=a.sid
AND surveyls_language=a.language
AND surveyls_language='$baselang'
AND a.allowregister='Y'
AND a.active='N'
AND a.listpublic='Y'
AND a.expires is not null
AND a.startdate is not null
ORDER BY surveyls_title";

$sresult = db_execute_assoc($squery) or show_error("Couldn't execute $squery");


if($sresult->num_rows() > 0)
{
$list[] = "<br/>".$clang->gT("Following survey(s) are not yet active but you can register for them.");
foreach($sresult->result_array() as $rows)
{
$link = "<li><a href=\"#\" id='inactivesurvey' onclick = 'sendreq(".$rows['sid'].");' ";
//$link = "<li><a href=\"#\" id='inactivesurvey' onclick = 'get2post(".site_url('survey/send/')."?sid={$rows['sid']}&amp;)sendreq(".$rows['sid'].",".$rows['startdate'].",".$rows['expires'].");' ";
$link .= " class='surveytitle'>".$rows['surveyls_title']."</a>\n";
if ($rows['publicstatistics'] == 'Y') $link .= "<a href='".site_url("statistics_user/".$rows['sid'])."'>(".$clang->gT('View statistics').")</a>";
$link .= "</li><div id='regform'></div>\n";
$list[]=$link;
}
}

if(count($list) < 1)
{
$list[]="<li class='surveytitle'>".$clang->gT("No available surveys")."</li>";
Expand Down Expand Up @@ -348,6 +381,22 @@ function action()
$this->_printTemplateContent(sGetTemplatePath($defaulttemplate)."/startpage.pstpl", $data, __LINE__);

$this->_printTemplateContent(sGetTemplatePath($defaulttemplate)."/surveylist.pstpl", $data, __LINE__);

echo '<script type="text/javascript" >
function sendreq(surveyid)
{
$.ajax({
type: "GET",
url: "'.site_url("register/ajaxregisterform").'/" + surveyid,
}).done(function(msg) {
document.getElementById("regform").innerHTML = msg;
});
}
</script>';




$this->_killPage($redata, __LINE__);
}
Expand Down Expand Up @@ -493,7 +542,7 @@ function action()
$_POST['loadall']="reload";
}
}

//LOAD SAVED SURVEY
if (isset($_POST['loadall']) && $_POST['loadall'] == "reload")
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/frontend_helper.php
@@ -1,4 +1,4 @@
<?php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function loadanswers()
{
Expand Down
37 changes: 27 additions & 10 deletions application/helpers/replacements_helper.php
Expand Up @@ -13,7 +13,7 @@
* @param questionNum - needed to support dynamic JavaScript-based tailoring within questions
* @return string Text with replaced strings
*/
function templatereplace($line, $replacements=array(),&$redata=array(), $debugSrc='Unspecified', $anonymized=false, $questionNum=NULL)
function templatereplace($line, $replacements=array(),&$redata=array(), $debugSrc='Unspecified', $anonymized=false, $questionNum=NULL, $registerdata=array())
{
$CI =& get_instance();

Expand Down Expand Up @@ -80,6 +80,7 @@ function templatereplace($line, $replacements=array(),&$redata=array(), $debugSr
if (!isset($showgroupinfo)) { $showgroupinfo = 'Y'; }
if (!isset($showqnumcode)) { $showqnumcode = ''; }
$_surveyid = (isset($surveyid) ? $surveyid : 0);

if (!isset($totalBoilerplatequestions)) { $totalBoilerplatequestions = 0; }
if (!isset($showXquestions)) { $showXquestions = 'choose'; }
if (!isset($relativeurl)) { $relativeurl = $CI->config->item("relativeurl"); }
Expand All @@ -90,9 +91,10 @@ function templatereplace($line, $replacements=array(),&$redata=array(), $debugSr
{
$line = file_get_contents($line);
}



$clang = $CI->limesurvey_lang;
$clang = ($CI->limesurvey_lang) ? $CI->limesurvey_lang : $registerdata['clang'];

$CI->load->helper('surveytranslator');
$questiondetails = array('sid' => 0, 'gid' => 0, 'qid' => 0, 'aid' =>0);
if(isset($question) && isset($question['sgq'])) $questiondetails=getsidgidqidaidtype($question['sgq']); //Gets an array containing SID, GID, QID, AID and Question Type)
Expand Down Expand Up @@ -527,19 +529,25 @@ function templatereplace($line, $replacements=array(),&$redata=array(), $debugSr
. "<tr><td></td><td><input type='submit' id='loadbutton' value='" . $clang->gT("Load Now") . "' /></td></tr></table>\n";

// Registration Form
if (isset($surveyid))
if (isset($surveyid) || (isset($registerdata) && $debugSrc == 'register.php'))
{
$_registerform = "<form method='post' action='".$CI->config->item('publicurl')."/register.php'>\n";
if (isset($surveyid))
$tokensid = $surveyid;
else
$tokensid = $registerdata['sid'];

$_registerform = "<form method='post' action='".site_url('register/index')."'>\n";
if (!isset($_REQUEST['lang']))
{
$_reglang = GetBaseLanguageFromSurveyID($surveyid);
$_reglang = GetBaseLanguageFromSurveyID($tokensid);
}
else
{
$_reglang = returnglobal('lang');
}

$_registerform .= "<input type='hidden' name='lang' value='" . $_reglang . "' />\n";
$_registerform .= "<input type='hidden' name='sid' value='$surveyid' id='sid' />\n";
$_registerform .= "<input type='hidden' name='sid' value='$tokensid' id='sid' />\n";

$_registerform.="<table class='register' summary='Registrationform'>\n"
. "<tr><td align='right'>"
Expand All @@ -564,14 +572,23 @@ function templatereplace($line, $replacements=array(),&$redata=array(), $debugSr
$_registerform .= " value='" . htmlentities(returnglobal('register_email'), ENT_QUOTES, 'UTF-8') . "'";
}
$_registerform .= " /></td></tr>\n";
if (isset($thissurvey['usecaptcha']) && function_exists("ImageCreate") && captcha_enabled('registrationscreen', $thissurvey['usecaptcha']))

if ((count($registerdata) > 1 || isset($thissurvey['usecaptcha'])) && function_exists("ImageCreate") && captcha_enabled('registrationscreen', $thissurvey['usecaptcha']))
{
$_registerform .="<tr><td align='right'>" . $clang->gT("Security Question") . ":</td><td><table><tr><td valign='middle'><img src='".site_url('/verification/image')."' alt='' /></td><td valign='middle'><input type='text' size='5' maxlength='3' name='loadsecurity' value='' /></td></tr></table></td></tr>\n";
}
$_registerform .= "<tr><td></td><td><input id='registercontinue' class='submit' type='submit' value='" . $clang->gT("Continue") . "' />"
. "</td></tr>\n"
. "</table>\n"
. "</form>\n";
. "</table>\n";

if (count($registerdata) > 1 && $registerdata['sid'] != NULL && $debugSrc == 'register.php')
{
$_registerform .= "<input name='startdate' type ='hidden' value='".$registerdata['startdate']."' />";
$_registerform .= "<input name='enddate' type ='hidden' value='".$registerdata['enddate']."' />";
}


$_registerform .= "</form>\n";
}
else
{
Expand Down

0 comments on commit c75b7cf

Please sign in to comment.