Skip to content

Commit

Permalink
New feature: Export survey ZIP archive function with includes the sur…
Browse files Browse the repository at this point in the history
…vey structure, responses, tokens and timings - can be used for archival purposes or to move a survey from one server to another.

Dev Still working on import - just fixing up survey timings in general

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11116 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Oct 6, 2011
1 parent d802508 commit d7656cf
Show file tree
Hide file tree
Showing 20 changed files with 968 additions and 684 deletions.
82 changes: 41 additions & 41 deletions application/config/database.php
@@ -1,54 +1,54 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql. Currently supported:
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql. Currently supported:
| mysql, mysqli, postgre, odbc, mssql
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = '';
$db['default']['database'] = 'lsusr_13746';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/browse.php
Expand Up @@ -996,7 +996,6 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null,
function zipFiles($responseIds, $zipfilename) {
global $surveyid, $surveytable;

require_once('classes/pclzip/pclzip.lib.php');
$tmpdir = $CI->config->item('uploaddir'). "/surveys/" . $surveyid . "/files/";

$filelist = array();
Expand Down Expand Up @@ -1045,6 +1044,7 @@ function zipFiles($responseIds, $zipfilename) {
}

if (count($filelist)>0) {
$this->load->library("admin/pclzip/pclzip",array('p_zipname' => $tempdir.$zipfilename));
$zip = new PclZip($tmpdir . $zipfilename);
if ($zip->create($filelist)===0) {
//Oops something has gone wrong!
Expand Down
19 changes: 15 additions & 4 deletions application/controllers/admin/checkintegrity.php
Expand Up @@ -226,6 +226,9 @@ function _checkintegrity()
$this->db->query("delete FROM {$this->db->dbprefix('survey_permissions')} where sid not in (select sid from {$this->db->dbprefix('surveys')})");
$this->db->query("delete FROM {$this->db->dbprefix('survey_permissions')} where uid not in (select uid from {$this->db->dbprefix('users')})");

// Fix subquestions
fixSubquestions();

/*** Check for active survey tables with missing survey entry and rename them ***/
$sDBPrefix=$this->db->dbprefix;
$sQuery = db_select_tables_like("{$sDBPrefix}survey\_%");
Expand Down Expand Up @@ -535,14 +538,14 @@ function _checkintegrity()
$iDay=substr($sDateTime, 6, 2);
$iHour=substr($sDateTime, 8, 2);
$iMinute=substr($sDateTime, 10, 2);
$sDate=date("D, d M Y h:i a", mktime($iHour, $iMinute, 0, $iMonth, $iDay, $iYear));
$sDate=date("d M Y H:i", mktime($iHour, $iMinute, 0, $iMonth, $iDay, $iYear));
$sQuery="SELECT * FROM ".$sTableName;
$oQRresult=db_execute_assoc($sQuery) or safe_die('Failed: '.$sQuery);
$iRecordcount=$oQRresult->num_rows();
if($iRecordcount == 0) { // empty table - so add it to immediate deletion
$aDelete['orphansurveytables'][]=$sTableName;
} else {
$aOldSurveyTableAsk[]=array('table'=>$sTableName, 'details'=>sprintf($clang->gT("Survey ID %d saved at %s containing %d record(s) (%s)"), $sid, $date, $jqcount, $type));
$aOldSurveyTableAsk[]=array('table'=>$sTableName, 'details'=>sprintf($clang->gT("Survey ID %d saved at %s containing %d record(s) (%s)"), $iSurveyID, $sDate, $iRecordcount, $sType));
}
}
}
Expand Down Expand Up @@ -624,8 +627,16 @@ function _checkintegrity()
$aDelete['redundancyok']=true;
} else {
$aDelete['redundancyok']=false;
$aDelete['redundanttokentables']=$aOldTokenTableAsk;
$aDelete['redundantsurveytables']=$aOldSurveyTableAsk;
$aDelete['redundanttokentables']=array();
$aDelete['redundantsurveytables']=array();
if (isset($aOldTokenTableAsk))
{
$aDelete['redundanttokentables']=$aOldTokenTableAsk;
}
if (isset($aOldSurveyTableAsk))
{
$aDelete['redundantsurveytables']=$aOldSurveyTableAsk;
}
}

return $aDelete;
Expand Down
22 changes: 7 additions & 15 deletions application/controllers/admin/database.php
Expand Up @@ -586,7 +586,7 @@ function index($action=null)
if (!is_null($cond2rel)) {
$_POST['relevance'] = $cond2rel;
}

foreach ($validAttributes as $validAttribute)
{
if ($validAttribute['i18n'])
Expand Down Expand Up @@ -740,12 +740,7 @@ function index($action=null)
'mandatory' => $_POST['mandatory']

);
/*
$uqquery = "UPDATE ".$this->db->dbprefix."questions SET type='".$_POST['type']."', title='".$_POST['title']."', "
. "question='".$_POST['question_'.$qlang]."', preg='".$_POST['preg']."', help='".$_POST['help_'.$qlang]."', "
. "gid='".$gid."', other='".$_POST['other']."', "
. "mandatory='".$_POST['mandatory']."'";
*/

if ($oldgid!=$gid)
{

Expand All @@ -756,26 +751,21 @@ function index($action=null)
// this prevent breaking conditions if the target qid is in the dest group
$insertorder = getMaxquestionorder($gid) + 1;
$udata = array_merge($udata,array('question_order' => $insertorder));
//$uqquery .=', question_order='.$insertorder.' ';
}
else
{
// Moving question to a 'lower' group
// insert question at the beginning of the destination group
shiftorderQuestions($surveyid,$gid,1); // makes 1 spare room for new question at top of dest group
$udata = array_merge($udata,array('question_order' => 0));
$uqquery .=', question_order=0 ';
}
}
//$uqquery.= "WHERE sid='".$surveyid."' AND qid='".$qid."' AND language='{$qlang}'";
$condn = array('sid' => $surveyid, 'qid' => $qid, 'language' => $qlang);
$uqresult = $this->questions_model->update($udata,$condn); //($uqquery); // or safe_die ("Error Update Question: ".$uqquery."<br />".$connect->ErrorMsg()); // Checked)
if (!$uqresult)
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Question could not be updated","js")."\n\")\n //-->\n</script>\n";
}


}
}

Expand All @@ -785,17 +775,19 @@ function index($action=null)
{
$sQuery="UPDATE ".$this->db->dbprefix."questions set gid={$gid} where gid={$oldgid} and parent_qid>0";
$oResult = db_execute_assoc($sQuery); // or safe_die ("Error updating question group ID: ".$uqquery."<br />".$connect->ErrorMsg()); // Checked
}
// if the group has changed then fix the sortorder of old and new group
if ($oldgid!=$gid)
{
fixsortorderQuestions($oldgid, $surveyid);
fixsortorderQuestions($gid, $surveyid);
// If some questions have conditions set on this question's answers
// then change the cfieldname accordingly
fixmovedquestionConditions($qid, $oldgid, $gid);
}
if ($oldtype != $_POST['type'])
{
$sQuery="UPDATE ".$this->db->dbprefix."questions set type=".$this->db->escape($_POST['type'])." where parent_qid={$qid}";
$oResult = db_execute_assoc($sQuery); // or safe_die ("Error updating question group ID: ".$uqquery."<br />".$connect->ErrorMsg()); // Checked

}
$query = "DELETE FROM ".$this->db->dbprefix."answers WHERE qid= {$qid} and scale_id>={$iAnswerScales}";
$result = db_execute_assoc($query); // or safe_die("Error: ".$connect->ErrorMsg()); // Checked

Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/export.php
Expand Up @@ -87,14 +87,14 @@ function _surveyexport($action, $surveyid)
$this->load->library('zip');
$oZIP = $this->zip;
$this->zip->add_data('survey_'.$surveyid.'.lss',survey_getXMLData($surveyid));
$this->zip->add_data('survey_'.$surveyid.'_responses.lsr',getXMLDataSingleTable($surveyid,'survey_'.$surveyid,'Responses'));
$this->zip->add_data('survey_'.$surveyid.'_responses.lsr',getXMLDataSingleTable($surveyid,'survey_'.$surveyid,'Responses','responses'));
if ($this->db->table_exists('tokens_'.$surveyid))
{
$this->zip->add_data('survey_'.$surveyid.'_tokens.lst',getXMLDataSingleTable($surveyid,'tokens_'.$surveyid,'Tokens'));
$this->zip->add_data('survey_'.$surveyid.'_tokens.lst',getXMLDataSingleTable($surveyid,'tokens_'.$surveyid,'Tokens','tokens'));
}
if ($this->db->table_exists('survey_'.$surveyid.'_timings'))
{
$this->zip->add_data('survey_'.$surveyid.'_timings.lsi',getXMLDataSingleTable($surveyid,'survey_'.$surveyid.'_timings','Timings'));
$this->zip->add_data('survey_'.$surveyid.'_timings.lsi',getXMLDataSingleTable($surveyid,'survey_'.$surveyid.'_timings','Timings','timings'));
}
$this->zip->download("limesurvey_archive_{$surveyid}.zip");
}
Expand Down

0 comments on commit d7656cf

Please sign in to comment.