2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Merging the updated Limesurvey 1.92+ branch of queXS to trunk

This commit is contained in:
azammitdcarf
2012-11-21 04:04:39 +00:00
parent 153fc8ca0d
commit c569559964
856 changed files with 254260 additions and 819988 deletions

View File

@@ -10,7 +10,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: importlabel.php 10925 2011-09-02 14:12:02Z c_schmitz $
* $Id: importlabel.php 11607 2011-12-06 23:19:52Z tmswhite $
*/
//Ensure script is not run directly, avoid path disclosure
@@ -57,39 +57,38 @@ elseif (strtolower($sExtension)=='lsl')
$importlabeloutput .= "<input type='submit' value='".$clang->gT("Return to label set administration")."' onclick=\"window.open('$scriptname?action=labels', '_self')\" />\n";
$importlabeloutput .= "</div><br />\n";
}
unlink($sFullFilepath);
unlink($sFullFilepath);
if (isset($aImportResults))
{
if (count($aImportResults['warnings'])>0)
{
$importlabeloutput .= "<br />\n<div class='warningheader'>".$clang->gT("Warnings")."</div><ul>\n";
foreach ($aImportResults['warnings'] as $warning)
if (isset($aImportResults['fatalerror']))
{
$importlabeloutput .= '<li>'.$warning.'</li>';
}
$importlabeloutput .= "</ul>\n";
$importlabeloutput .= "<br />\n<div class='warningheader'>".$clang->gT("Error")."</div>
<p>{$aImportResults['fatalerror']}<br>";
}
else
{
if (count($aImportResults['warnings'])>0)
{
$importlabeloutput .= "<br />\n<div class='warningheader'>".$clang->gT("Warnings")."</div><ul>\n";
foreach ($aImportResults['warnings'] as $warning)
{
$importlabeloutput .= '<li>'.$warning.'</li>';
}
$importlabeloutput .= "</ul>\n";
}
$importlabeloutput .= "<br />\n<div class='successheader'>".$clang->gT("Success")."</div><br />\n";
$importlabeloutput .= "<strong><u>".$clang->gT("Label set import summary")."</u></strong><br />\n";
$importlabeloutput .= "<ul style=\"text-align:left;\">\n\t<li>".$clang->gT("Label sets").": {$aImportResults['labelsets']}</li>\n";
$importlabeloutput .= "\t<li>".$clang->gT("Labels").": {$aImportResults['labels']}</li></ul>\n";
$importlabeloutput .= "<p><strong>".$clang->gT("Import of label set(s) is completed.")."</strong><br /><br />\n";
}
$importlabeloutput .= "<input type='submit' value='".$clang->gT("Return to label set administration")."' onclick=\"window.open('$scriptname?action=labels', '_self')\" />\n";
$importlabeloutput .= "</p></div><br />\n";
}
$importlabeloutput .= "<br />\n<div class='successheader'>".$clang->gT("Success")."</div><br />\n";
$importlabeloutput .= "<strong><u>".$clang->gT("Label set import summary")."</u></strong><br />\n";
$importlabeloutput .= "<ul style=\"text-align:left;\">\n\t<li>".$clang->gT("Label sets").": {$aImportResults['labelsets']}</li>\n";
$importlabeloutput .= "\t<li>".$clang->gT("Labels").": {$aImportResults['labels']}</li></ul>\n";
$importlabeloutput .= "<p><strong>".$clang->gT("Import of label set(s) is completed.")."</strong><br /><br />\n";
$importlabeloutput .= "<input type='submit' value='".$clang->gT("Return to label set administration")."' onclick=\"window.open('$scriptname?action=labels', '_self')\" />\n";
$importlabeloutput .= "</div><br />\n";
}
$importlabeloutput .= "<br />\n<div class='successheader'>".$clang->gT("Success")."</div><br />\n";
$importlabeloutput .= "<strong><u>".$clang->gT("Label set import summary")."</u></strong><br />\n";
$importlabeloutput .= "<ul style=\"text-align:left;\">\n\t<li>".$clang->gT("Label sets").": {$aImportResults['labelsets']}</li>\n";
$importlabeloutput .= "\t<li>".$clang->gT("Labels").": {$aImportResults['labels']}</li></ul>\n";
$importlabeloutput .= "<p><strong>".$clang->gT("Import of label set(s) is completed.")."</strong><br /><br />\n";
$importlabeloutput .= "<input type='submit' value='".$clang->gT("Return to label set administration")."' onclick=\"window.open('$scriptname?action=labels', '_self')\" />\n";
$importlabeloutput .= "</div><br />\n";
// IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
function CSVImportLabelset($sFullFilepath, $options)
@@ -110,7 +109,8 @@ function CSVImportLabelset($sFullFilepath, $options)
fclose($handle);
if (substr($bigarray[0], 0, 27) != "# LimeSurvey Label Set Dump" && substr($bigarray[0], 0, 28) != "# PHPSurveyor Label Set Dump")
{
return $results['fatalerror']=$clang->gT("This file is not a LimeSurvey label set file. Import failed.");
$results['fatalerror']=$clang->gT("This file is not a LimeSurvey label set file. Import failed.");
return $results;
}
for ($i=0; $i<9; $i++) //skipping the first lines that are not needed
@@ -178,7 +178,7 @@ function CSVImportLabelset($sFullFilepath, $options)
$newvalues=array_map(array(&$connect, "qstr"),$newvalues); // quote everything accordingly
$lsainsert = "insert INTO {$dbprefix}labelsets (".implode(',',array_keys($labelsetrowdata)).") VALUES (".implode(',',$newvalues).")"; //handle db prefix
$lsiresult=$connect->Execute($lsainsert);
$results['labelsets']++;
$results['labelsets']++;
// Get the new insert id for the labels inside this labelset
$newlid=$connect->Insert_ID("{$dbprefix}labelsets",'lid');
@@ -193,7 +193,7 @@ function CSVImportLabelset($sFullFilepath, $options)
// Combine into one array with keys and values since its easier to handle
$labelrowdata=array_combine($lfieldorders,$lfieldcontents);
$labellid=$labelrowdata['lid'];
if ($labellid == $oldlid) {
$labelrowdata['lid']=$newlid;
@@ -251,7 +251,7 @@ function CSVImportLabelset($sFullFilepath, $options)
$result=$connect->Execute($query) or safe_die("Couldn't delete labelset<br />$query<br />".$connect->ErrorMsg());
$newlid=$lsmatch;
$results['warnings'][]=$clang->gT("Label set was not imported because the same label set already exists.")." ".sprintf($clang->gT("Existing LID: %s"),$newlid);
}
//END CHECK FOR DUPLICATES
}
@@ -265,23 +265,23 @@ function CSVImportLabelset($sFullFilepath, $options)
function XMLImportLabelsets($sFullFilepath, $options)
{
global $connect, $dbprefix, $clang;
$xml = simplexml_load_file($sFullFilepath);
$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType!='Label set') safe_die('This is not a valid LimeSurvey label set structure XML file.');
$dbversion = (int) $xml->DBVersion;
$dbversion = (float) $xml->DBVersion;
$csarray=buildLabelSetCheckSumArray();
$aLSIDReplacements=array();
$aLSIDReplacements=array();
$results['labelsets']=0;
$results['labels']=0;
$results['warnings']=array();
// Import labels table ===================================================================================
$tablename=$dbprefix.'labelsets';
foreach ($xml->labelsets->rows->row as $row)
{
$insertdata=array();
$insertdata=array();
foreach ($row as $key=>$value)
{
$insertdata[(string)$key]=(string)$value;
@@ -289,32 +289,33 @@ function XMLImportLabelsets($sFullFilepath, $options)
$oldlsid=$insertdata['lid'];
unset($insertdata['lid']); // save the old qid
// Insert the new question
$query=$connect->GetInsertSQL($tablename,$insertdata);
// Insert the new question
$query=$connect->GetInsertSQL($tablename,$insertdata);
$result = $connect->Execute($query) or safe_die ($clang->gT("Error").": Failed to insert data<br />{$query}<br />\n".$connect->ErrorMsg());
$results['labelsets']++;
$newlsid=$connect->Insert_ID($tablename,"lid"); // save this for later
$aLSIDReplacements[$oldlsid]=$newlsid; // add old and new lsid to the mapping array
}
// Import labels table ===================================================================================
$tablename=$dbprefix.'labels';
if (isset($xml->labels->rows->row))
foreach ($xml->labels->rows->row as $row)
{
$insertdata=array();
$insertdata=array();
foreach ($row as $key=>$value)
{
$insertdata[(string)$key]=(string)$value;
}
$insertdata['lid']=$aLSIDReplacements[$insertdata['lid']];
$query=$connect->GetInsertSQL($tablename,$insertdata);
$query=$connect->GetInsertSQL($tablename,$insertdata);
$result = $connect->Execute($query) or safe_die ($clang->gT("Error").": Failed to insert data<br />{$query}<br />\n".$connect->ErrorMsg());
$results['labels']++;
}
//CHECK FOR DUPLICATE LABELSETS
if (isset($_POST['checkforduplicates']))
@@ -356,12 +357,12 @@ function XMLImportLabelsets($sFullFilepath, $options)
$results['labelsets']--;
$newlid=$lsmatch;
$results['warnings'][]=$clang->gT("Label set was not imported because the same label set already exists.")." ".sprintf($clang->gT("Existing LID: %s"),$newlid);
}
}
//END CHECK FOR DUPLICATES
}
}
return $results;
}
// Closing PHP tag intentionall left out
// Closing PHP tag intentionall left out