Skip to content

Commit

Permalink
New feature: Multiple label sets can be exported now as one file.
Browse files Browse the repository at this point in the history
Dev Export labels exports to new .lsl XML format now
Dev Import is still pending

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8649 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Apr 28, 2010
1 parent b898fd1 commit ad077e3
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 40 deletions.
45 changes: 15 additions & 30 deletions admin/dumplabel.php
Expand Up @@ -22,23 +22,18 @@

//Ensure script is not run directly, avoid path disclosure
include_once("login_check.php");
require_once("export_data_functions.php");
$lids=returnglobal('lids');
if (!$lid) die('No LID has been provided. Cannot dump label set.');
$lid=returnglobal('lid');
if (!$lid && !$lids) die('No LID has been provided. Cannot dump label set.');

$fn = "limesurvey_question_$qid.lsq";
$xml = new XMLWriter();



//1: Questions Table
$qquery = "SELECT * FROM {$dbprefix}labelsets WHERE lid=$lid";
$qdump = BuildCSVFromQuery($qquery);

//2: Answers table
$aquery = "SELECT lid, code, title, sortorder, language, assessment_value FROM {$dbprefix}labels WHERE lid=$lid";
$adump = BuildCSVFromQuery($aquery);

$fn = "limesurvey_labelset_$lid.csv";
if ($lid)
{
$lids=array($lid);
}
$lids=array_map('sanitize_int',$lids);

$fn = "limesurvey_labelset_".implode('_',$lids).".lsl";
$xml = new XMLWriter();

header("Content-Type: text/html/force-download");
Expand All @@ -54,33 +49,23 @@
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('document');
$xml->writeElement('LimeSurveyDocType','Label');
$xml->writeElement('DBVersion',$dbversionnumber);
$xml->writeElement('DBVersion',$dbversionnumber);
getXMLStructure($xml,$lids);
$xml->endElement(); // close columns
$xml->endDocument();
exit;

function getXMLStructure($xml,$lid)
function getXMLStructure($xml,$lids)
{
global $dbprefix;

$xml->startElement('languages');
$lquery = "SELECT language
FROM {$dbprefix}questions
WHERE qid=$qid or parent_qid=$qid group by language";
$lresult=db_execute_assoc($lquery);
while ($row=$lresult->FetchRow())
{
$xml->writeElement('language',$row['language']);
}
$xml->endElement();


// Label sets table
$lsquery = "SELECT * FROM {$dbprefix}labelsets WHERE lid=$lid";
$lsquery = "SELECT * FROM {$dbprefix}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=$lid";
$lquery = "SELECT lid, code, title, sortorder, language, assessment_value FROM {$dbprefix}labels WHERE lid=".implode(' or lid=',$lids);
BuildXMLFromQuery($xml,$lquery,'labels');
}

51 changes: 43 additions & 8 deletions admin/labels.php
Expand Up @@ -31,7 +31,7 @@
if($_SESSION['USER_RIGHT_SUPERADMIN'] == 1 || $_SESSION['USER_RIGHT_MANAGE_LABEL'] == 1)
{


$js_admin_includes[]='scripts/labels.js';
if (isset($_POST['sortorder'])) {$postsortorder=sanitize_int($_POST['sortorder']);}

if (!isset($action)) {$action=returnglobal('action');}
Expand Down Expand Up @@ -64,9 +64,13 @@
."\t<div class='menubar-main'>\n"
."\t<div class='menubar-left'>\n"
."\t<a href='$scriptname' title=\"".$clang->gTview("Return to survey administration")."\" >"
."<img name='Administration' src='$imagefiles/home.png' alt='".$clang->gT("Return to survey administration")."' /></a>"
."<img name='Administration' src='$imagefiles/home.png' align='left' alt='".$clang->gT("Return to survey administration")."' /></a>"
."\t<img src='$imagefiles/blank.gif' width='11' height='20' alt='' />\n"
."\t<img src='$imagefiles/seperator.gif' alt='' />\n"
."\t<img src='$imagefiles/seperator.gif' align='left' alt='' />\n"
."\t<img src='$imagefiles/blank.gif' width='76' align='left' height='20' alt='' />\n"
."\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t<a href='admin.php?action=labels&amp;subaction=exportmulti' title=\"".$clang->gTview("Export Label Set")."\" >"
."<img src='$imagefiles/dumplabelmulti.png' alt='".$clang->gT("Export multiple label sets")."' align='left' /></a>"
."\t</div>\n"
."\t<div class='menubar-right'>\n"
."\t<img src='$imagefiles/blank.gif' width='5' height='20' alt='' />\n"
Expand Down Expand Up @@ -103,7 +107,38 @@
."\t\t</div>\n"
."\t</div>\n"
."</div>\n";


if ($subaction == "exportmulti")
{

$labelsoutput.="<script type='text/javascript'>\n"
."<!--\n"
."var strSelectLabelset='".$clang->gT('You have to select at least one label set.','js')."';\n"
."//-->\n"
."</script>\n";

$labelsoutput .="<div class='header'>".$clang->gT('Export multiple label sets')."</div>"
."<form method='post' id='exportlabelset' class='form30' action='admin.php'><ul>"
."<li><label for='labelsets'>".$clang->gT('Please choose the label sets you want to export:')."<br />".$clang->gT('(Select multiple label sets by using the Ctrl key)')."</label>"
."<select id='labelsets' multiple='multiple' name='lids[]' size='20'>\n";
$labelsets=getlabelsets();
if (count($labelsets)>0)
{
foreach ($labelsets as $lb)
{
$labelsoutput.="<option value='{$lb[0]}'>{$lb[0]}: {$lb[1]}</option>\n";
}
}

$labelsoutput.= "\t</select></li>\n"
."</ul><p><input type='submit' id='btnDumpLabelSets' value='".$clang->gT('Export selected labelsets')."' />"
."<input type='hidden' name='action' value='dumplabel' />"
."</form>";


}


//NEW SET
if ($action == "newlabelset" || $action == "editlabelset")
{
Expand All @@ -129,7 +164,7 @@
$labelsoutput.= "<ul'>\n"
."<li><label for='languageids'>".$clang->gT("Set name:")."</label>\n"
."\t<input type='hidden' name='languageids' id='languageids' value='$langids' />"
."\t<input type='text' id='label_name' name='label_name' value='";
."\t<input type='text' id='label_name' name='label_name' maxlength='100' size='50' value='";
if (isset($lbname)) {$labelsoutput.= $lbname;}
$labelsoutput.= "' />\n"
."</li>\n"
Expand Down Expand Up @@ -212,15 +247,15 @@
."</div>\n"
."<div class='menubar-main'>\n"
."\t<div class='menubar-left'>\n"
."\t<img src='$imagefiles/blank.gif' width='60' height='20' border='0' hspace='0' align='left' alt='' />\n"
."\t<img src='$imagefiles/blank.gif' width='40' height='20' border='0' hspace='0' align='left' alt='' />\n"
."\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t<a href='admin.php?action=editlabelset&amp;lid=$lid' title=\"".$clang->gTview("Edit label set")."\" >" .
"<img name='EditLabelsetButton' src='$imagefiles/edit.png' alt='".$clang->gT("Edit label set")."' align='left' /></a>"
."\t<a href='#' title='".$clang->gTview("Delete label set")."' onclick=\"if (confirm('".$clang->gT("Do you really want to delete this label set?","js")."')) {".get2post("admin.php?action=deletelabelset&amp;lid=$lid")."}\" >"
."<img src='$imagefiles/delete.png' border='0' alt='".$clang->gT("Delete label set")."' align='left' /></a>\n"
."\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t<a href='admin.php?action=dumplabel&amp;lid=$lid' title=\"".$clang->gTview("Export Label Set")."\" >" .
"<img src='$imagefiles/exportcsv.png' alt='".$clang->gT("Export Label Set")."' align='left' /></a>"
."\t<a href='admin.php?action=dumplabel&amp;lid=$lid' title=\"".$clang->gTview("Export this label set")."\" >" .
"<img src='$imagefiles/dumplabel.png' alt='".$clang->gT("Export this label set")."' align='left' /></a>"
."\t</div>\n"
."\t<div class='menubar-right'>\n"
."\t<input type='image' src='$imagefiles/close.gif' title='".$clang->gT("Close Window")."'"
Expand Down
15 changes: 15 additions & 0 deletions admin/scripts/labels.js
@@ -0,0 +1,15 @@
// $Id$

$(document).ready(function(){
$('#btnDumpLabelSets').click(function(){
if ($('#labelsets > option:selected').size()==0)
{
alert(strSelectLabelset);
return false;
}
else
{
return true;
}
});
});
7 changes: 7 additions & 0 deletions classes/core/language.php
Expand Up @@ -57,6 +57,13 @@ function gTview($string, $escapemode = 'html')
}
}

/**
* This function translates strings to their according language
*
* @param string $string The string to translate
* @param mixed $escapemode Different uses require the string to be escaped accordinlgy. Possible values are 'html'(default),'js' and 'unescaped'
* @return string Translated string
*/
function gT($string, $escapemode = 'html')
{
if ($this->gettextclass)
Expand Down
4 changes: 2 additions & 2 deletions classes/core/sanitize.php
Expand Up @@ -279,8 +279,8 @@ function sanitize_userfullname($string)

function sanitize_labelname($string)
{
$username_length=100;
$string=mb_substr($string,0,$username_length);
$labelname_length=100;
$string=mb_substr($string,0,$labelname_length);
return $string;
}

Expand Down
Binary file added images/dumplabel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dumplabelmulti.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad077e3

Please sign in to comment.