Exemplo n.º 1
0
 public function dumplabel()
 {
     $lid = sanitize_int(Yii::app()->request->getParam('lid'));
     // DUMP THE RELATED DATA FOR A SINGLE QUESTION INTO A SQL FILE FOR IMPORTING LATER ON OR
     // ON ANOTHER SURVEY SETUP DUMP ALL DATA WITH RELATED QID FROM THE FOLLOWING TABLES
     // 1. questions
     // 2. answers
     $lids = returnGlobal('lids');
     if (!$lid && !$lids) {
         die('No LID has been provided. Cannot dump label set.');
     }
     if ($lid) {
         $lids = array($lid);
     }
     $lids = array_map('sanitize_int', $lids);
     $fn = "limesurvey_labelset_" . implode('_', $lids) . ".lsl";
     $xml = getXMLWriter();
     $this->_addHeaders($fn, "text/html/force-download", "Mon, 26 Jul 1997 05:00:00 GMT", "cache");
     $xml->openURI('php://output');
     $xml->setIndent(TRUE);
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('document');
     $xml->writeElement('LimeSurveyDocType', 'Label set');
     $xml->writeElement('DBVersion', getGlobalSetting("DBVersion"));
     // Label sets table
     $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 {{labels}} WHERE lid=" . implode(' or lid=', $lids);
     buildXMLFromQuery($xml, $lquery, 'labels');
     $xml->endElement();
     // close columns
     $xml->endDocument();
     exit;
 }
Exemplo n.º 2
0
function questionGetXMLStructure($xml, $gid, $qid)
{
    // Questions table
    $qquery = "SELECT *\n    FROM {{questions}}\n    WHERE qid={$qid} and parent_qid=0 order by language, scale_id, question_order";
    buildXMLFromQuery($xml, $qquery);
    // Questions table - Subquestions
    $qquery = "SELECT *\n    FROM {{questions}}\n    WHERE parent_qid={$qid} order by language, scale_id, question_order";
    buildXMLFromQuery($xml, $qquery, 'subquestions');
    // Answer table
    $aquery = "SELECT *\n    FROM {{answers}}\n    WHERE qid = {$qid} order by language, scale_id, sortorder";
    buildXMLFromQuery($xml, $aquery);
    // Question attributes
    $iSurveyID = Yii::app()->db->createCommand("select sid from {{groups}} where gid={$gid}")->query();
    $iSurveyID = $iSurveyID->read();
    $iSurveyID = $iSurveyID['sid'];
    $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
    $platform = Yii::app()->db->getDriverName();
    if ($platform == 'mssql' || $platform == 'sqlsrv' || $platform == 'dblib') {
        $query = "SELECT qa.qid, qa.attribute, cast(qa.value as varchar(4000)) as value, qa.language\n        FROM {{question_attributes}} qa JOIN {{questions}}  q ON q.qid = qa.qid AND q.sid={$iSurveyID} and q.qid={$qid}\n        where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute,  cast(qa.value as varchar(4000)), qa.language";
    } else {
        $query = "SELECT qa.qid, qa.attribute, qa.value, qa.language\n        FROM {{question_attributes}} qa JOIN {{questions}}  q ON q.qid = qa.qid AND q.sid={$iSurveyID} and q.qid={$qid}\n        where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, qa.value, qa.language";
    }
    buildXMLFromQuery($xml, $query);
    // Default values
    $query = "SELECT *\n    FROM {{defaultvalues}}\n    WHERE qid={$qid}  order by language, scale_id";
    buildXMLFromQuery($xml, $query);
}