Skip to content

Commit

Permalink
Added token controller; ported addnew, adddummys, managetokenattribut…
Browse files Browse the repository at this point in the history
…es, email and remind views.

Updated tokens_dynamic_model and common_helper

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10366 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
dionet committed Jun 28, 2011
1 parent 43eb775 commit 76cc230
Show file tree
Hide file tree
Showing 14 changed files with 2,166 additions and 9 deletions.
997 changes: 997 additions & 0 deletions application/controllers/admin/tokens.php

Large diffs are not rendered by default.

70 changes: 66 additions & 4 deletions application/helpers/common_helper.php
Expand Up @@ -1475,8 +1475,8 @@ function getSurveyInfo($surveyid, $languagecode='')

//$query="SELECT * FROM ".db_table_name('surveys').",".db_table_name('surveys_languagesettings')." WHERE sid=$surveyid and surveyls_survey_id=$surveyid and surveyls_language='$languagecode'";
$CI->load->model('surveys_languagesettings_model');
$result=$CI->surveys_languagesettings_model->getAllData($surveyid,$languagecode) or safe_die ("Couldn't access survey settings<br />"); //Checked

$result=$CI->surveys_languagesettings_model->getAllData($surveyid,$languagecode); //or safe_die ("Couldn't access survey settings<br />"); //Checked
foreach ($result->result_array() as $row)
{
$thissurvey=$row;
Expand All @@ -1487,7 +1487,7 @@ function getSurveyInfo($surveyid, $languagecode='')
$thissurvey['welcome']=$thissurvey['surveyls_welcometext'];
$thissurvey['templatedir']=$thissurvey['template'];
$thissurvey['adminname']=$thissurvey['admin'];
$thissurvey['tablename']=$dbprefix.'survey_'.$thissurvey['sid'];
$thissurvey['tablename']=$CI->db->dbprefix.'survey_'.$thissurvey['sid'];
$thissurvey['urldescrip']=$thissurvey['surveyls_urldescription'];
$thissurvey['url']=$thissurvey['surveyls_url'];
$thissurvey['expiry']=$thissurvey['expires'];
Expand All @@ -1512,6 +1512,66 @@ function getSurveyInfo($surveyid, $languagecode='')
return $thissurvey;
}

/**
* Returns the default email template texts as array
*
* @param mixed $oLanguage Required language translationb object
* @param string $mode Escape mode for the translation function
* @return array
*/
function aTemplateDefaultTexts($oLanguage, $mode='html'){
return array(
'admin_detailed_notification_subject'=>$oLanguage->gT("Response submission for survey {SURVEYNAME} with results",$mode),
'admin_detailed_notification'=>$oLanguage->gT("Hello,\n\nA new response was submitted for your survey '{SURVEYNAME}'.\n\nClick the following link to reload the survey:\n{RELOADURL}\n\nClick the following link to see the individual response:\n{VIEWRESPONSEURL}\n\nClick the following link to edit the individual response:\n{EDITRESPONSEURL}\n\nView statistics by clicking here:\n{STATISTICSURL}\n\n\nThe following answers were given by the participant:\n{ANSWERTABLE}",$mode),
'admin_detailed_notification_css'=>'<style type="text/css">
.printouttable {
margin:1em auto;
}
.printouttable th {
text-align: center;
}
.printouttable td {
border-color: #ddf #ddf #ddf #ddf;
border-style: solid;
border-width: 1px;
padding:0.1em 1em 0.1em 0.5em;
}
.printouttable td:first-child {
font-weight: 700;
text-align: right;
padding-right: 5px;
padding-left: 5px;
}
.printouttable .printanswersquestion td{
background-color:#F7F8FF;
}
.printouttable .printanswersquestionhead td{
text-align: left;
background-color:#ddf;
}
.printouttable .printanswersgroup td{
text-align: center;
font-weight:bold;
padding-top:1em;
}
</style>',
'admin_notification_subject'=>$oLanguage->gT("Response submission for survey {SURVEYNAME}",$mode),
'admin_notification'=>$oLanguage->gT("Hello,\n\nA new response was submitted for your survey '{SURVEYNAME}'.\n\nClick the following link to reload the survey:\n{RELOADURL}\n\nClick the following link to see the individual response:\n{VIEWRESPONSEURL}\n\nClick the following link to edit the individual response:\n{EDITRESPONSEURL}\n\nView statistics by clicking here:\n{STATISTICSURL}",$mode),
'confirmation_subject'=>$oLanguage->gT("Confirmation of your participation in our survey"),
'confirmation'=>$oLanguage->gT("Dear {FIRSTNAME},\n\nthis email is to confirm that you have completed the survey titled {SURVEYNAME} and your response has been saved. Thank you for participating.\n\nIf you have any further questions about this email, please contact {ADMINNAME} on {ADMINEMAIL}.\n\nSincerely,\n\n{ADMINNAME}",$mode),
'invitation_subject'=>$oLanguage->gT("Invitation to participate in a survey",$mode),
'invitation'=>$oLanguage->gT("Dear {FIRSTNAME},\n\nyou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",$mode)."\n\n".$oLanguage->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link:\n{OPTOUTURL}",$mode),
'reminder_subject'=>$oLanguage->gT("Reminder to participate in a survey",$mode),
'reminder'=>$oLanguage->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",$mode)."\n\n".$oLanguage->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link:\n{OPTOUTURL}",$mode),
'registration_subject'=>$oLanguage->gT("Survey registration confirmation",$mode),
'registration'=>$oLanguage->gT("Dear {FIRSTNAME},\n\nYou, or someone using your email address, have registered to participate in an online survey titled {SURVEYNAME}.\n\nTo complete this survey, click on the following URL:\n\n{SURVEYURL}\n\nIf you have any questions about this survey, or if you did not register to participate and believe this email is in error, please contact {ADMINNAME} at {ADMINEMAIL}.",$mode)
);
}

/**
function getlabelsets($languages=null)
// Returns a list with label sets
Expand Down Expand Up @@ -5966,7 +6026,9 @@ function GetTokenConditionsFieldNames($surveyid)
*/
function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
{
global $CI, $clang; //global $dbprefix, $connect, $clang;
//global $CI, $clang; //global $dbprefix, $connect, $clang;
$CI= &get_instance();
$clang=$CI->limesurvey_lang;
if (tableExists('tokens_'.$surveyid) === false)
{
return Array();
Expand Down
4 changes: 2 additions & 2 deletions application/models/surveys_languagesettings_model.php
Expand Up @@ -67,8 +67,8 @@ function update($data, $condition=FALSE)

function getAllData($sid,$lcode)
{
$this->db->query('SELECT * FROM '. $this->db->prefix('surveys') .' , '. $this->db->prefix('surveys_languagesettings') .' WHERE sid='.$sid.' AND surveyls_survey_id='.$sid.' AND surveyls_language='.$lcode);
return $this->db->get();
$query = 'SELECT * FROM '. $this->db->dbprefix('surveys') .', '. $this->db->dbprefix('surveys_languagesettings') .' WHERE sid=? AND surveyls_survey_id=? AND surveyls_language=?';
return $this->db->query($query, array($sid, $sid, $lcode));
}

function insertNewSurvey($data)
Expand Down
92 changes: 91 additions & 1 deletion application/models/tokens_dynamic_model.php
Expand Up @@ -2,13 +2,18 @@

class Tokens_dynamic_model extends CI_Model {

function getAllRecords($sid,$condition=FALSE)
function getAllRecords($sid,$condition=FALSE,$limit=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}

if ($limit != FALSE)
{
$this->db->limit($limit);
}

$data = $this->db->get('tokens_'.$sid);

return $data;
Expand All @@ -30,4 +35,89 @@ function getSomeRecords($fields,$sid,$condition=FALSE)
return $data;
}

function newTokensTable()
{
$createtokentable=
"tid int I NOTNULL AUTO PRIMARY,\n "
. "firstname C(40),\n "
. "lastname C(40),\n ";
//MSSQL needs special treatment because of some strangeness in ADODB
if ($connect->databaseType == 'odbc_mssql' || $connect->databaseType == 'odbtp' || $connect->databaseType == 'mssql_n' || $connect->databaseType == 'mssqlnative')
{
$createtokentable.= "email C(320),\n "
."emailstatus C(300) DEFAULT 'OK',\n ";
}
else
{
$createtokentable.= "email X(320),\n "
."emailstatus X(300) DEFAULT 'OK',\n ";
}

$createtokentable.= "token C(36) ,\n "
. "language C(25) ,\n "
. "sent C(17) DEFAULT 'N',\n "
. "remindersent C(17) DEFAULT 'N',\n "
. "remindercount int I DEFAULT 0,\n "
. "completed C(17) DEFAULT 'N',\n "
. "usesleft I DEFAULT 1,\n"
. "validfrom T ,\n "
. "validuntil T ,\n "
. "mpid I ";


$tabname = "{$dbprefix}tokens_{$surveyid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci',
'mysqli' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray);
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
}

function totalTokens($surveyid)
{
$tksq = "SELECT count(tid) FROM ".$this->db->dbprefix("tokens_$surveyid");
$tksr = $this->db->query($tksq);
$tkr = $tksr->row_array();
return $tkr["count(tid)"];
//return $tkcount;
}

function tokensSummary($surveyid)
{

// SEE HOW MANY RECORDS ARE IN THE TOKEN TABLE
$tksq = "SELECT count(tid) FROM ".$this->db->dbprefix("tokens_$surveyid");
$tksr = $this->db->query($tksq);
$tkr = $tksr->row_array();
$tkcount = $tkr["count(tid)"];
$data['tkcount']=$tkcount;

$tksq = "SELECT count(*) FROM ".$this->db->dbprefix("tokens_$surveyid")." WHERE token IS NULL OR token=''";
$tksr = $this->db->query($tksq);
//$tkr = $tksr->result_array();
//var_dump($tkr);
$tkr = $tksr->row_array();
$data['query1'] = $tkr["count(*)"]." / $tkcount";

$tksq = "SELECT count(*) FROM ".$this->db->dbprefix("tokens_$surveyid")." WHERE (sent!='N' and sent<>'')";
$tksr = $this->db->query($tksq);
$tkr = $tksr->row_array();
$data['query2'] = $tkr["count(*)"]." / $tkcount";

$tksq = "SELECT count(*) FROM ".$this->db->dbprefix("tokens_$surveyid")." WHERE emailstatus = 'optOut'";
$tksr = $this->db->query($tksq);
$tkr = $tksr->row_array();
$data['query3'] = $tkr["count(*)"]." / $tkcount";

$tksq = "SELECT count(*) FROM ".$this->db->dbprefix("tokens_$surveyid")." WHERE (completed!='N' and completed<>'')";
$tksr = $this->db->query($tksq);
$tkr = $tksr->row_array();
$data['query4'] = $tkr["count(*)"]." / $tkcount";
return $data;
}

function insertTokens($surveyid,$data)
{
return $this->db->insert("tokens_".$surveyid, $data);
}
}
4 changes: 2 additions & 2 deletions application/views/admin/Survey/surveybar.php
Expand Up @@ -8,7 +8,7 @@
<?php if(!$activated) { ?>
<img src='<?php echo $imageurl;?>/inactive.png' alt='<?php echo $clang->gT("This survey is currently not active");?>' />
<?php if($canactivate) { ?>
<a href="#" onclick="window.open('<?php echo site_url("admin/activate/index/$surveyid");?>', '_top')
<a href="#" onclick="window.open('<?php echo site_url("admin/activate/index/$surveyid");?>', '_top')"
title="<?php echo $clang->gTview("Activate this Survey");?>" >
<img src='<?php echo $imageurl;?>/activate.png' name='ActivateSurvey' alt='<?php echo $clang->gT("Activate this Survey");?>'/></a>
<?php } else { ?>
Expand Down Expand Up @@ -178,7 +178,7 @@
} ?>
</ul></li>
<?php if($tokenmanagement) { ?>
<li><a href="#" onclick="window.open('<?php echo site_url("admin/tokens/index/$surveyid");?>', '_top')
<li><a href="#" onclick="window.open('<?php echo site_url("admin/tokens/index/$surveyid");?>', '_top')"
title="<?php echo $clang->gTview("Token management");?>" >
<img src='<?php echo $imageurl;?>/tokens.png' name='TokensControl' alt='<?php echo $clang->gT("Token management");?>'/></a></li>
<?php } ?>
Expand Down
14 changes: 14 additions & 0 deletions application/views/admin/Token/addtokenpost.php
@@ -0,0 +1,14 @@
<div class='header ui-widget-header'><?php echo $clang->gT("Add token entry");?></div>
<div class='messagebox ui-corner-all'>
<?php if ($success) { ?>
<div class='successheader'><?php echo $clang->gT("Success");?></div>
<br /><?php echo $clang->gT("New token was added.");?><br /><br />
<input type='button' value='<?php echo $clang->gT("Display tokens");?>' onclick="window.open('<?php echo site_url("admin/tokens/browse/$surveyid");?>', '_top')" /><br />
<input type='button' value='<?php echo $clang->gT("Add another token entry");?>' onclick="window.open('<?php echo site_url("admin/tokens/addnew/$surveyid");?>', '_top')" /><br />
<?php } else { ?>
<div class='warningheader'><?php echo $clang->gT("Failed");?></div>
<br /><?php echo $clang->gT("There is already an entry with that exact token in the table. The same token cannot be used in multiple entries.");?><br /><br />
<input type='button' value='<?php echo $clang->gT("Display tokens");?>' onclick="window.open('<?php echo site_url("admin/tokens/browse/$surveyid");?>', '_top')" /><br />
<input type='button' value='<?php echo $clang->gT("Add new token entry");?>' onclick="window.open('<?php echo site_url("admin/tokens/addnew/$surveyid");?>', '_top')" /><br />
<?php } ?>
</div>

0 comments on commit 76cc230

Please sign in to comment.