Skip to content

Commit

Permalink
Commit for GCI Task #7130286
Browse files Browse the repository at this point in the history
Ported tokens import/export csv

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11519 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shitiz Garg committed Nov 27, 2011
1 parent ff5dca8 commit f28cdae
Show file tree
Hide file tree
Showing 14 changed files with 1,198 additions and 524 deletions.
2 changes: 1 addition & 1 deletion application/config/lsconfig.php
Expand Up @@ -528,7 +528,7 @@


$config['publicdir'] = $config['rootdir']; // The directory path of the public scripts
$config['homedir'] = $config['rootdir'].DIRECTORY_SEPARATOR."admin"; // The directory path of the admin scripts
$config['homedir'] = $config['rootdir']; // The directory path of the admin scripts
$config['tempdir'] = $config['rootdir'].DIRECTORY_SEPARATOR."tmp"; // The directory path where LimeSurvey can store temporary files
$config['imagedir'] = $config['rootdir'].DIRECTORY_SEPARATOR."images"; // The directory path of the image directory
$config['uploaddir'] = $config['rootdir'].DIRECTORY_SEPARATOR."upload";
Expand Down
283 changes: 133 additions & 150 deletions application/controllers/admin/database.php

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions application/controllers/admin/export.php
Expand Up @@ -48,6 +48,8 @@ public function run($sa)
$this->route('showquexmlsurvey', array('surveyid', 'lang'));
elseif ($sa == 'exportspss')
$this->route('exportspss', array('sid', 'lang'));
elseif ($sa == 'dumplabel')
$this->route('dumplabel', array('lid'));
elseif ($sa == 'exportr')
$this->route('exportr', array('sid', 'subaction'));
}
Expand Down Expand Up @@ -1264,13 +1266,12 @@ function dumplabel($lid=null)
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('document');
$xml->writeElement('LimeSurveyDocType','Label set');
$xml->writeElement('DBVersion',$this->config->item("dbversionnumber"));
$xml->writeElement('DBVersion',getGlobalSetting("DBVersion"));
// Label sets table
$dbprefix = $this->db->dbprefix;
$lsquery = "SELECT * FROM {$dbprefix}labelsets WHERE lid=".implode(' or lid=',$lids);
$lsquery = "SELECT * FROM {{labelsets}} WHERE lid=".implode(' or lid=',$lids);
BuildXMLFromQuery($xml,$lsquery,'labelsets');
// Labels
$lquery = "SELECT lid, code, title, sortorder, language, assessment_value FROM {$dbprefix}labels WHERE lid=".implode(' or lid=',$lids);
$lquery = "SELECT lid, code, title, sortorder, language, assessment_value FROM {{labels}} WHERE lid=".implode(' or lid=',$lids);
BuildXMLFromQuery($xml,$lquery,'labels');
$xml->endElement(); // close columns
$xml->endDocument();
Expand Down
148 changes: 75 additions & 73 deletions application/controllers/admin/question.php

Large diffs are not rendered by default.

927 changes: 812 additions & 115 deletions application/controllers/admin/tokens.php

Large diffs are not rendered by default.

168 changes: 82 additions & 86 deletions application/helpers/admin/import_helper.php

Large diffs are not rendered by default.

51 changes: 37 additions & 14 deletions application/helpers/common_helper.php
Expand Up @@ -2992,7 +2992,10 @@ function GetBaseLanguageFromSurveyID($surveyid)
if (!isset($cache[$surveyid])) {

$condition = array('sid' => $surveyid);//"sid=$surveyid";

$surveylanguage = Survey::model()->findByPk($surveyid);//("SELECT language FROM ".db_table_name('surveys')." WHERE sid=$surveyid";)
if (is_null($surveylanguage))
die(var_dump(debug_backtrace()));
$surveylanguage = $surveylanguage->attributes; //Checked)

if (!isset($surveylanguage['language']) || is_null($surveylanguage))
Expand Down Expand Up @@ -5853,8 +5856,6 @@ function getTokenData($surveyid, $token)
*/
function sGetTemplatePath($sTemplateName)
{
$CI = &get_instance();

if (isStandardTemplate($sTemplateName))
{
return Yii::app()->getConfig("standardtemplaterootdir").'/'.$sTemplateName;
Expand Down Expand Up @@ -7918,14 +7919,12 @@ function getlabelsets($languages=null)
// Returns a list with label sets
// if the $languages paramter is provided then only labelset containing all of the languages in the paramter are provided
{
$CI =& get_instance();
$CI->load->helper('database');
$clang = $CI->limesurvey_lang;
$clang = Yii::app()->lang;
if ($languages){
$languages=sanitize_languagecodeS($languages);
$languagesarray=explode(' ',trim($languages));
}
$query = "SELECT ".$CI->db->dbprefix."labelsets.lid as lid, label_name FROM ".$CI->db->dbprefix."labelsets";
$query = "SELECT {{labelsets}}.lid as lid, label_name FROM {{labelsets}}";
if ($languages){
$query .=" where ";
foreach ($languagesarray as $item)
Expand All @@ -7935,9 +7934,9 @@ function getlabelsets($languages=null)
$query .=" 1=1 ";
}
$query .=" order by label_name";
$result = db_execute_assoc($query) or safe_die ("Couldn't get list of label sets<br />$query<br />"); //Checked
$result = Yii::app()->db->createCommand($query)->query(); //Checked
$labelsets=array();
foreach ($result->result_array() as $row)
foreach ($result->readAll() as $row)
{
$labelsets[] = array($row['lid'], $row['label_name']);
}
Expand All @@ -7948,14 +7947,13 @@ function getHeader($meta = false)
{
global $embedded;

$CI =& get_instance();
$surveyid = Yii::app()->getConfig('sid');
$CI->load->helper('surveytranslator');
Yii::app()->loadHelper('surveytranslator');
$clang = $CI->limesurvey_lang;

if ($CI->session->userdata('s_lang'))
if (!empty(Yii::app()->session['s_lang']))
{
$surveylanguage= $CI->session->userdata('s_lang');
$surveylanguage= Yii::app()->session['s_lang'];
}
elseif (isset($surveyid) && $surveyid)
{
Expand All @@ -7974,14 +7972,14 @@ function getHeader($meta = false)
if (substr($jsinclude,0,4) == 'http')
$js_header .= "<script type=\"text/javascript\" src=\"$jsinclude\"></script>\n";
else
$js_header .= "<script type=\"text/javascript\" src=\"".base_url()."$jsinclude\"></script>\n";
$js_header .= "<script type=\"text/javascript\" src=\"".Yii::app()->baseUrl."$jsinclude\"></script>\n";
}
}
if(Yii::app()->getConfig("css_admin_includes"))
{
foreach (Yii::app()->getConfig("css_admin_includes") as $cssinclude)
{
$css_header .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"".base_url().$cssinclude."\" />\n";
$css_header .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"".Yii::app()->baseUrl.$cssinclude."\" />\n";
}
}

Expand Down Expand Up @@ -8531,4 +8529,29 @@ function checkgroupfordisplay($gid,$anonymized,$surveyid)
}
}

function db_quote_id($id)
{
// WE DONT HAVE nor USE other thing that alfanumeric characters in the field names
// $quote = $connect->nameQuote;
// return $quote.str_replace($quote,$quote.$quote,$id).$quote;

switch (Yii::app()->db->createCommand($id))
{
case "mysqli" :
case "mysql" :
return "`".$id."`";
break;
case "mssql_n" :
case "mssql" :
case "mssqlnative" :
case "odbc_mssql" :
return "[".$id."]";
break;
case "postgre":
return "\"".$id."\"";
break;
default:
return "`".$id."`";
}
}
// Closing PHP tag intentionally omitted - yes, it is okay
26 changes: 0 additions & 26 deletions application/helpers/database_helper.php
Expand Up @@ -117,32 +117,6 @@ function &db_select_column($sql)
* @param mixed $id Fieldname to be quoted
*/

function db_quote_id($id)
{
// WE DONT HAVE nor USE other thing that alfanumeric characters in the field names
// $quote = $connect->nameQuote;
// return $quote.str_replace($quote,$quote.$quote,$id).$quote;

switch (get_instance()->db->platform())
{
case "mysqli" :
case "mysql" :
return "`".$id."`";
break;
case "mssql_n" :
case "mssql" :
case "mssqlnative" :
case "odbc_mssql" :
return "[".$id."]";
break;
case "postgre":
return "\"".$id."\"";
break;
default:
return "`".$id."`";
}
}

function db_random()
{
$CI = &get_instance();
Expand Down
20 changes: 10 additions & 10 deletions application/helpers/export_helper.php
Expand Up @@ -1830,11 +1830,8 @@ function tokens_export($surveyid)
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: cache");

$CI =& get_instance();
$dbprefix = $CI->db->dbprefix;
$_POST = $CI->input->post();

$bquery = "SELECT * FROM ".$CI->db->dbprefix("tokens_$surveyid").' where 1=1';
$bquery = "SELECT * FROM {{tokens_$surveyid}} where 1=1";
$databasetype = Yii::app()->db->getDriverName();
if (trim($_POST['filteremail'])!='')
{
if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $connect->databaseType == 'mssqlnative')
Expand All @@ -1855,12 +1852,12 @@ function tokens_export($surveyid)
$bquery .= " and completed='N'";
if ($thissurvey['anonymized']=='N')
{
$bquery .=" and token not in (select token from ".db_table_name("survey_$surveyid")." group by token)";
$bquery .=" and token not in (select token from {{survey_$surveyid}} group by token)";
}
}
if ($_POST['tokenstatus']==3 && $thissurvey['anonymized']=='N')
{
$bquery .= " and completed='N' and token in (select token from ".db_table_name("survey_$surveyid")." group by token)";
$bquery .= " and completed='N' and token in (select token from {{survey_$surveyid}} group by token)";
}

if ($_POST['invitationstatus']==1)
Expand All @@ -1887,8 +1884,8 @@ function tokens_export($surveyid)
}
$bquery .= " ORDER BY tid";

$bresult = db_execute_assoc($bquery) or die ("$bquery<br />".htmlspecialchars($connect->ErrorMsg()));
$bfieldcount=$bresult->num_rows();
$bresult = Yii::app()->db->createCommand($bquery)->query();
$bfieldcount=$bresult->getRowCount();
// Export UTF8 WITH BOM
$tokenoutput = chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'));
$tokenoutput .= "tid,firstname,lastname,email,emailstatus,token,language,validfrom,validuntil,invited,reminded,remindercount,completed,usesleft";
Expand All @@ -1901,7 +1898,10 @@ function tokens_export($surveyid)
$tokenoutput .=" <".str_replace(","," ",$attrfielddescr[$attr_name]).">";
}
$tokenoutput .="\n";
foreach($bresult->result_array() as $brow)

Yii::import('application.libraries.Date_Time_Converter', true);

foreach($bresult->readAll() as $brow)
{

if (trim($brow['validfrom']!=''))
Expand Down

0 comments on commit f28cdae

Please sign in to comment.