Skip to content

Commit

Permalink
Survey import/copy action basic code and import_helper.
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10725 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Aug 14, 2011
1 parent cd05bb2 commit a17ef6d
Show file tree
Hide file tree
Showing 3 changed files with 1,927 additions and 139 deletions.
332 changes: 194 additions & 138 deletions application/controllers/admin/survey.php
Expand Up @@ -888,164 +888,220 @@ function editlocalsettings($surveyid)

function copy()
{

if ( $this->input->post('copysurveytranslinksfields') == "on" || $this->input->post('translinksfields') == "on")
{
$sTransLinks = true;
}

//$importsurvey = "<div class='header ui-widget-header'>".$clang->gT("Copy survey")."</div>\n";
$copyfunction= true;
//$importsurvey .= "<div class='messagebox ui-corner-all'>\n";
$importerror=false; // Put a var for continue
$surveyid = sanitize_int($this->input->post('copysurveylist'));

$exclude = array();
if (get_magic_quotes_gpc()) {$sNewSurveyName = stripslashes($this->input->post('copysurveyname'));}
else{
$sNewSurveyName=$this->input->post('copysurveyname');
}

/*require_once("../classes/inputfilter/class.inputfilter_clean.php");
$myFilter = new InputFilter('','',1,1,1);
if ($filterxsshtml)
{
$sNewSurveyName = $myFilter->process($sNewSurveyName);
} else {
$sNewSurveyName = html_entity_decode($sNewSurveyName, ENT_QUOTES, "UTF-8");
} */
if ($this->input->post('copysurveyexcludequotas') == "on")
{
$exclude['quotas'] = true;
}
if ($this->input->post('copysurveyexcludeanswers') == "on")
{
$exclude['answers'] = true;
}
if ($this->input->post('copysurveyresetconditions') == "on")
{
$exclude['conditions'] = true;
}

//include("export_structure_xml.php");
$this->load->helper('admin/export_structure_xml');

if (!isset($surveyid))
{
$surveyid=returnglobal('sid');
}

$clang = $this->limesurvey_lang;
if (!$surveyid)
{

self::_getAdminHeader();
self::_showadminmenu($surveyid);;
$data['clang'] = $clang;
$this->load->view('admin/Survey/exportSurveyError_view',$data);

exit;
}

if (!isset($copyfunction))
{
$fn = "limesurvey_survey_$surveyid.lss";
header("Content-Type: text/xml");
header("Content-Disposition: attachment; filename=$fn");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public"); // HTTP/1.0
echo getXMLData('',$surveyid);
exit;
}

$copysurveydata = getXMLData($exclude,$surveyid);
// $this->load->helper('import');
//require_once('import_functions.php');
if (!$importerror)
{
$aImportResults=XMLImportSurvey('',$copysurveydata,$sNewSurveyName);
}
else
$importsurvey = "";
$action = $this->input->post('action');
if ($action == "importsurvey" || $action == "copysurvey")
{
$importerror=true;
}

/**
if (isset($aImportResults['error']) && $aImportResults['error']!=false)
{
$importsurvey .= "<div class='warningheader'>".$clang->gT("Error")."</div><br />\n";
$importsurvey .= $aImportResults['error']."<br /><br />\n";
$importsurvey .= "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\" />\n";
$importerror = true;
}
if (!$importerror)
{
$importsurvey .= "<br />\n<div class='successheader'>".$clang->gT("Success")."</div><br /><br />\n";
$importsurvey .= "<strong>".$clang->gT("Survey import summary")."</strong><br />\n";
$importsurvey .= "<ul style=\"text-align:left;\">\n\t<li>".$clang->gT("Surveys").": {$aImportResults['surveys']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Languages").": {$aImportResults['languages']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Question groups").": {$aImportResults['groups']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Questions").": {$aImportResults['questions']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Answers").": {$aImportResults['answers']}</li>\n";
if (isset($aImportResults['subquestions']))
if ( $this->input->post('copysurveytranslinksfields') == "on" || $this->input->post('translinksfields') == "on")
{
$importsurvey .= "\t<li>".$clang->gT("Subquestions").": {$aImportResults['subquestions']}</li>\n";
$sTransLinks = true;
}
if (isset($aImportResults['defaultvalues']))
$clang = $this->limesurvey_lang;

// Start the HTML
if ($action == 'importsurvey')
{
$importsurvey .= "\t<li>".$clang->gT("Default answers").": {$aImportResults['defaultvalues']}</li>\n";
$importsurvey .= "<div class='header ui-widget-header'>".$clang->gT("Import survey")."</div>\n";
$importingfrom = "http";
}
if (isset($aImportResults['conditions']))
elseif($action == 'copysurvey')
{
$importsurvey .= "\t<li>".$clang->gT("Conditions").": {$aImportResults['conditions']}</li>\n";
$importsurvey .= "<div class='header ui-widget-header'>".$clang->gT("Copy survey")."</div>\n";
$copyfunction= true;
}
if (isset($aImportResults['labelsets']))
// Start traitment and messagebox
$importsurvey .= "<div class='messagebox ui-corner-all'>\n";
$importerror=false; // Put a var for continue

if ($action == 'importsurvey')
{
$importsurvey .= "\t<li>".$clang->gT("Label sets").": {$aImportResults['labelsets']}</li>\n";
$the_full_file_path = $this->config->item('tempdir') . "/" . $_FILES['the_file']['name'];
if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $the_full_file_path))
{
$importsurvey .= "<div class='errorheader'>".$clang->gT("Error")."</div>\n";
$importsurvey .= sprintf ($clang->gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."),$this->config->item('tempdir'))."<br /><br />\n";
$importsurvey .= "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\"><br /><br />\n";
$importerror=true;
}
else
{
$importsurvey .= "<div class='successheader'>".$clang->gT("Success")."</div>&nbsp;<br />\n";
$importsurvey .= $clang->gT("File upload succeeded.")."<br /><br />\n";
$importsurvey .= $clang->gT("Reading file..")."<br />\n";
$sFullFilepath=$the_full_file_path;
$aPathInfo = pathinfo($sFullFilepath);
if (isset($aPathInfo['extension']))
{
$sExtension = $aPathInfo['extension'];
}
else
{
$sExtension = "";
}

}

if (!$importerror && (strtolower($sExtension)!='csv' && strtolower($sExtension)!='lss'))
{
$importsurvey .= "<div class='errorheader'>".$clang->gT("Error")."</div>\n";
$importsurvey .= $clang->gT("Import failed. You specified an invalid file type.")."\n";
$importerror=true;
}
}
if (isset($aImportResults['deniedcountls']) && $aImportResults['deniedcountls']>0)
elseif ($action == 'copysurvey')
{
$importsurvey .= "\t<li>".$clang->gT("Not imported label sets").": {$aImportResults['deniedcountls']} ".$clang->gT("(Label sets were not imported since you do not have the permission to create new label sets.)")."</li>\n";
$surveyid = sanitize_int($this->input->post('copysurveylist'));
$exclude = array();
if (get_magic_quotes_gpc()) {$sNewSurveyName = stripslashes($this->input->post('copysurveyname'));}
else{
$sNewSurveyName=$this->input->post('copysurveyname');
}
/**
require_once("../classes/inputfilter/class.inputfilter_clean.php");
$myFilter = new InputFilter('','',1,1,1);
if ($filterxsshtml)
{
$sNewSurveyName = $myFilter->process($sNewSurveyName);
} else {
$sNewSurveyName = html_entity_decode($sNewSurveyName, ENT_QUOTES, "UTF-8");
}
*/
if ($this->input->post('copysurveyexcludequotas') == "on")
{
$exclude['quotas'] = true;
}
if ($this->input->post('copysurveyexcludeanswers') == "on")
{
$exclude['answers'] = true;
}
if ($this->input->post('copysurveyresetconditions') == "on")
{
$exclude['conditions'] = true;
}
//include("export_structure_xml.php");
$this->load->helper('admin/export_structure_xml');
$copysurveydata = getXMLData($exclude);
}
$importsurvey .= "\t<li>".$clang->gT("Question attributes").": {$aImportResults['question_attributes']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Assessments").": {$aImportResults['assessments']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Quotas").": {$aImportResults['quota']} ({$aImportResults['quotamembers']} ".$clang->gT("quota members")." ".$clang->gT("and")." {$aImportResults['quotals']} ".$clang->gT("quota language settings").")</li>\n</ul><br />\n";

if (count($aImportResults['importwarnings'])>0)
// Now, we have the survey : start importing
//require_once('import_functions.php');
$this->load->helper('admin/import');
$_POST = $this->input->post();
if ($action == 'importsurvey' && !$importerror)
{
$importsurvey .= "<div class='warningheader'>".$clang->gT("Warnings").":</div><ul style=\"text-align:left;\">";
foreach ($aImportResults['importwarnings'] as $warning)

if (isset($sExtension) && strtolower($sExtension)=='csv')
{
$importsurvey .='<li>'.$warning.'</li>';
$aImportResults=CSVImportSurvey($sFullFilepath);
}
$importsurvey .= "</ul><br />\n";
elseif (isset($sExtension) && strtolower($sExtension)=='lss')
{
$aImportResults=XMLImportSurvey($sFullFilepath,null,null, null,(isset($_POST['translinksfields'])));
}
else
{
$importerror = true;
}


}
elseif ($action == 'copysurvey' && !$importerror)
{
$aImportResults=XMLImportSurvey('',$copysurveydata,$sNewSurveyName);
}
else
{
$importerror=true;
}

$importsurvey .= "<strong>".$clang->gT("Copy of survey is completed.")."</strong><br />\n"
. "<a href='$scriptname?sid={$aImportResults['newsid']}'>".$clang->gT("Go to survey")."</a><br />\n";
if (isset($aImportResults['error']) && $aImportResults['error']!=false)
{
$link = site_url('admin');
$importsurvey .= "<div class='warningheader'>".$clang->gT("Error")."</div><br />\n";
$importsurvey .= $aImportResults['error']."<br /><br />\n";
$importsurvey .= "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick=\"window.open('$link', '_top')\" />\n";
$importerror = true;
}

if (!$importerror)
{
$importsurvey .= "<br />\n<div class='successheader'>".$clang->gT("Success")."</div><br /><br />\n";
if ($action == 'importsurvey')
{
$importsurvey .= "<strong>".$clang->gT("Survey copy summary")."</strong><br />\n";
}
elseif($action == 'copysurvey')
{
$importsurvey .= "<strong>".$clang->gT("Survey import summary")."</strong><br />\n";
}

$importsurvey .= "<ul style=\"text-align:left;\">\n\t<li>".$clang->gT("Surveys").": {$aImportResults['surveys']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Languages").": {$aImportResults['languages']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Question groups").": {$aImportResults['groups']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Questions").": {$aImportResults['questions']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Answers").": {$aImportResults['answers']}</li>\n";
if (isset($aImportResults['subquestions']))
{
$importsurvey .= "\t<li>".$clang->gT("Subquestions").": {$aImportResults['subquestions']}</li>\n";
}
if (isset($aImportResults['defaultvalues']))
{
$importsurvey .= "\t<li>".$clang->gT("Default answers").": {$aImportResults['defaultvalues']}</li>\n";
}
if (isset($aImportResults['conditions']))
{
$importsurvey .= "\t<li>".$clang->gT("Conditions").": {$aImportResults['conditions']}</li>\n";
}
if (isset($aImportResults['labelsets']))
{
$importsurvey .= "\t<li>".$clang->gT("Label sets").": {$aImportResults['labelsets']}</li>\n";
}
if (isset($aImportResults['deniedcountls']) && $aImportResults['deniedcountls']>0)
{
$importsurvey .= "\t<li>".$clang->gT("Not imported label sets").": {$aImportResults['deniedcountls']} ".$clang->gT("(Label sets were not imported since you do not have the permission to create new label sets.)")."</li>\n";
}
$importsurvey .= "\t<li>".$clang->gT("Question attributes").": {$aImportResults['question_attributes']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Assessments").": {$aImportResults['assessments']}</li>\n";
$importsurvey .= "\t<li>".$clang->gT("Quotas").": {$aImportResults['quota']} ({$aImportResults['quotamembers']} ".$clang->gT("quota members")." ".$clang->gT("and")." {$aImportResults['quotals']} ".$clang->gT("quota language settings").")</li>\n</ul><br />\n";

if (count($aImportResults['importwarnings'])>0)
{
$importsurvey .= "<div class='warningheader'>".$clang->gT("Warnings").":</div><ul style=\"text-align:left;\">";
foreach ($aImportResults['importwarnings'] as $warning)
{
$importsurvey .='<li>'.$warning.'</li>';
}
$importsurvey .= "</ul><br />\n";
}
$link = site_url('admin/survey/view/'.$aImportResults['newsid']);
if ($action == 'importsurvey')
{
$importsurvey .= "<strong>".$clang->gT("Import of Survey is completed.")."</strong><br />\n"
. "<a href='$link'>".$clang->gT("Go to survey")."</a><br />\n";
}
elseif($action == 'copysurvey')
{
$importsurvey .= "<strong>".$clang->gT("Copy of survey is completed.")."</strong><br />\n"
. "<a href='$link'>".$clang->gT("Go to survey")."</a><br />\n";
}

}
if ($action == 'importsurvey')
{
unlink($sFullFilepath);
}

}
// end of traitment an close message box
$importsurvey .= "</div><br />\n"; */

$data['clang'] = $clang;
$data['aImportResults'] = $aImportResults;
$data['importerror'] = $importerror;
self::_getAdminHeader();
self::_showadminmenu($surveyid);;
self::_surveybar($surveyid);
//self::_surveysummary($surveyid);
$this->load->view('admin/Survey/copySurvey_view',$data);
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
$importsurvey .= "</div><br />\n";
}
self::_getAdminHeader();
self::_showadminmenu();;
//self::_surveybar($surveyid);

$data['display'] = $importsurvey;
$this->load->view('survey_view',$data);

self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));

}

Expand Down

0 comments on commit a17ef6d

Please sign in to comment.