diff --git a/application/controllers/admin/export.php b/application/controllers/admin/export.php new file mode 100644 index 00000000000..1d1a46d8d5b --- /dev/null +++ b/application/controllers/admin/export.php @@ -0,0 +1,146 @@ +load->helper("export"); + $this->load->helper("database"); + } + + function survey($surveyid) + { + if(bHasSurveyPermission($surveyid,'surveycontent','export')) { + if($this->input->post("action")) + { + self::_surveyexport($this->input->post("action"), $surveyid); + return; + } + $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; + $this->config->set_item("css_admin_includes", $css_admin_includes); + self::_getAdminHeader(); + self::_showadminmenu($surveyid); + self::_surveybar($surveyid); + $this->load->view("admin/Export/survey_view"); + self::_loadEndScripts(); + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + } + } + + function _surveyexport($action, $surveyid) + { + if($action == "exportstructurexml") + { + $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 survey_getXMLData($surveyid); + exit; + } + elseif($action == "exportstructurequexml") + { + if (isset($surveyprintlang) && !empty($surveyprintlang)) + $quexmllang = $surveyprintlang; + else + $quexmllang=GetBaseLanguageFromSurveyID($surveyid); + if (!(isset($noheader) && $noheader == true)) + { + $fn = "survey_{$surveyid}_{$quexmllang}.xml"; + 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 quexml_export($surveyid, $quexmllang); + exit; + } + elseif($action == "exportstructureLsrcCsv") + { + lsrccsv_export($surveyid); + } + } + } + + function group($surveyid, $gid) + { + if($this->config->item("export4lsrc") === true && bHasSurveyPermission($surveyid,'survey','export')) { + if($this->input->post("action")) + { + group_export($this->input->post("action"), $surveyid, $gid); + return; + } + $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; + $this->config->set_item("css_admin_includes", $css_admin_includes); + self::_getAdminHeader(); + self::_showadminmenu($surveyid); + self::_surveybar($surveyid,$gid); + self::_questiongroupbar($surveyid,$gid,null,"exportstructureGroup"); + $this->load->view("admin/Export/group_view", array("surveyid" => $surveyid, "gid" => $gid)); + self::_loadEndScripts(); + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + } + else + { + group_export("exportstructurecsvGroup", $surveyid, $gid); + return; + } + } + + function question($surveyid, $gid, $qid) + { + if($this->config->item("export4lsrc") === true && bHasSurveyPermission($surveyid,'survey','export')) { + if($this->input->post("action")) + { + question_export($this->input->post("action"), $surveyid, $gid, $qid); + return; + } + $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; + $this->config->set_item("css_admin_includes", $css_admin_includes); + self::_getAdminHeader(); + self::_showadminmenu($surveyid); + self::_surveybar($surveyid,$gid); + self::_questiongroupbar($surveyid,$gid,$qid,"exportstructureGroup"); + $this->load->view("admin/Export/question_view", array("surveyid" => $surveyid, "gid" => $gid, "qid" =>$qid)); + self::_loadEndScripts(); + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + } + else + { + question_export("exportstructurecsvQuestion", $surveyid, $gid, $qid); + return; + } + } + +} \ No newline at end of file diff --git a/application/controllers/admin/tokens.php b/application/controllers/admin/tokens.php index 2d612288ab6..5323dfa7c95 100644 --- a/application/controllers/admin/tokens.php +++ b/application/controllers/admin/tokens.php @@ -166,7 +166,7 @@ function browse($surveyid,$limit=50,$start=0,$order=false,$searchstring=false) $data['bresult'] = $this->tokens_dynamic_model->getAllRecords($surveyid,false,$limit,$start,$order,$idata); $data['clang']=$clang; - $data['thissurvey']=$thissurvey; + $data['thissurvey']=getSurveyInfo($surveyid); $data['searchstring']=$searchstring; $data['imageurl'] = $this->config->item('imageurl'); $data['surveyid']=$surveyid; @@ -1192,6 +1192,37 @@ function remind($surveyid) } } + /** + * Export Dialog + */ + function exportdialog($surveyid) + { + if (bHasSurveyPermission($surveyid, 'tokens','export') )//EXPORT FEATURE SUBMITTED BY PIETERJAN HEYSE + { + $this->load->helper("database"); + if ($this->input->post('submit')) + { + $this->load->helper("export"); + tokens_export($surveyid); + } + $langquery = "SELECT language FROM ".$this->db->dbprefix("tokens_$surveyid")." group by language"; + $langresult = db_execute_assoc($langquery); + $data['resultr'] = $langresult->row_array(); + + $data['clang']=$this->limesurvey_lang; + $thissurvey=getSurveyInfo($surveyid); + $data['thissurvey']=$thissurvey; + $data['imageurl'] = $this->config->item('imageurl'); + $data['surveyid']=$surveyid; + + + self::_getAdminHeader(); + $this->load->view("admin/token/tokenbar",$data); + $this->load->view("admin/token/exportdialog",$data); + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + } + } + /** * Generate Tokens */ diff --git a/application/helpers/admin/domxml_wrapper_helper.php b/application/helpers/admin/domxml_wrapper_helper.php new file mode 100644 index 00000000000..22298c49891 --- /dev/null +++ b/application/helpers/admin/domxml_wrapper_helper.php @@ -0,0 +1,484 @@ +=5.1 for XPath evaluation functions, and PHP>=5.1/libxml for DOMXML error reports) + + Typical use: + { + if (version_compare(PHP_VERSION,'5','>=')) + require_once('domxml-php4-to-php5.php'); + } + + Version 1.19, 2007-09-30, http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/ + + ------------------------------------------------------------------ + Written by Alexandre Alapetite, http://alexandre.alapetite.net/cv/ + + Copyright 2004-2007, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR), + http://creativecommons.org/licenses/by-sa/2.0/fr/ + http://alexandre.alapetite.net/divers/apropos/#by-sa + - Attribution. You must give the original author credit + - Share Alike. If you alter, transform, or build upon this work, + you may distribute the resulting work only under a license identical to this one + (Can be included in GPL/LGPL projects) + - The French law is authoritative + - Any of these conditions can be waived if you get permission from Alexandre Alapetite + - Please send to Alexandre Alapetite the modifications you make, + in order to improve this file for the benefit of everybody + + If you want to distribute this code, please do it as a link to: + http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/ + */ +@ini_set('zend.ze1_compatibility_mode', '0'); +define('DOMXML_LOAD_PARSING',0); +define('DOMXML_LOAD_VALIDATING',1); +define('DOMXML_LOAD_RECOVERING',2); +define('DOMXML_LOAD_SUBSTITUTE_ENTITIES',4); +//define('DOMXML_LOAD_COMPLETE_ATTRS',8); +define('DOMXML_LOAD_DONT_KEEP_BLANKS',16); + +function domxml_new_doc($version) {return new php4DOMDocument();} +function domxml_new_xmldoc($version) {return new php4DOMDocument();} +function domxml_open_file($filename,$mode=DOMXML_LOAD_PARSING,&$error=null) +{ + $dom=new php4DOMDocument($mode); + $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); + if ($errorMode) libxml_use_internal_errors(true); + if (!$dom->myDOMNode->load($filename)) $dom=null; + if ($errorMode) + { + $error=array_map('_error_report',libxml_get_errors()); + libxml_clear_errors(); + } + return $dom; +} +function domxml_open_mem($str,$mode=DOMXML_LOAD_PARSING,&$error=null) +{ + $dom=new php4DOMDocument($mode); + $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); + if ($errorMode) libxml_use_internal_errors(true); + if (!$dom->myDOMNode->loadXML($str)) $dom=null; + if ($errorMode) + { + $error=array_map('_error_report',libxml_get_errors()); + libxml_clear_errors(); + } + return $dom; +} +function html_doc($html_doc,$from_file=false) +{ + $dom=new php4DOMDocument(); + if ($from_file) $result=$dom->myDOMNode->loadHTMLFile($html_doc); + else $result=$dom->myDOMNode->loadHTML($html_doc); + return $result ? $dom : null; +} +function html_doc_file($filename) {return html_doc($filename,true);} +function xmldoc($str) {return domxml_open_mem($str);} +function xmldocfile($filename) {return domxml_open_file($filename);} +function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->xpath_eval($eval_str,$contextnode);} +function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);} +function xpath_register_ns($xpath_context,$prefix,$namespaceURI) {return $xpath_context->myDOMXPath->registerNamespace($prefix,$namespaceURI);} +function _entityDecode($text) {return html_entity_decode(strtr($text,array('''=>'\'')),ENT_QUOTES,'UTF-8');} +function _error_report($error) {return array('errormessage'=>$error->message,'nodename'=>'','line'=>$error->line,'col'=>$error->column)+($error->file==''?array():array('directory'=>dirname($error->file),'file'=>basename($error->file)));} + +class php4DOMAttr extends php4DOMNode +{ + function name() {return $this->myDOMNode->name;} + function set_content($text) {} + //function set_value($content) {return $this->myDOMNode->value=htmlspecialchars($content,ENT_QUOTES);} + function specified() {return $this->myDOMNode->specified;} + function value() {return $this->myDOMNode->value;} +} + +class php4DOMDocument extends php4DOMNode +{ + function php4DOMDocument($mode=DOMXML_LOAD_PARSING) + { + $this->myDOMNode=new DOMDocument(); + $this->myOwnerDocument=$this; + if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse=true; + if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover=true; + if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities=true; + if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace=false; + } + function add_root($name) + { + if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); + return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument); + } + function create_attribute($name,$value) + { + $myAttr=$this->myDOMNode->createAttribute($name); + $myAttr->value=htmlspecialchars($value,ENT_QUOTES); + return new php4DOMAttr($myAttr,$this); + } + function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);} + function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);} + function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} + function create_element_ns($uri,$name,$prefix=null) + { + if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri); + if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri)); + return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==null ? $name : $prefix.':'.$name),$this); + } + function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content),$this);} //By Walter Ebert 2007-01-22 + function create_processing_instruction($target,$data=''){return new php4DomProcessingInstruction($this->myDOMNode->createProcessingInstruction($target,$data),$this);} + function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content),$this);} + function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} + function dump_file($filename,$compressionmode=false,$format=false) + { + $format0=$this->myDOMNode->formatOutput; + $this->myDOMNode->formatOutput=$format; + $res=$this->myDOMNode->save($filename); + $this->myDOMNode->formatOutput=$format0; + return $res; + } + function dump_mem($format=false,$encoding=false) + { + $format0=$this->myDOMNode->formatOutput; + $this->myDOMNode->formatOutput=$format; + $encoding0=$this->myDOMNode->encoding; + if ($encoding) $this->myDOMNode->encoding=$encoding; + $dump=$this->myDOMNode->saveXML(); + $this->myDOMNode->formatOutput=$format0; + if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding + return $dump; + } + function free() + { + if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); + $this->myDOMNode=null; + $this->myOwnerDocument=null; + } + function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);} + function get_elements_by_tagname($name) + { + $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); + $nodeSet=array(); + $i=0; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); + return $nodeSet; + } + function html_dump_mem() {return $this->myDOMNode->saveHTML();} + function root() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} + function xpath_new_context() {return new php4DOMXPath($this);} +} + +class php4DOMElement extends php4DOMNode +{ + function add_namespace($uri,$prefix) + { + if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false; + else + { + $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri); //By Daniel Walker 2006-09-08 + return true; + } + } + function get_attribute($name) {return $this->myDOMNode->getAttribute($name);} + function get_attribute_node($name) {return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name),$this->myOwnerDocument);} + function get_elements_by_tagname($name) + { + $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); + $nodeSet=array(); + $i=0; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); + return $nodeSet; + } + function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} + function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);} + function set_attribute($name,$value) + { + //return $this->myDOMNode->setAttribute($name,$value); //Does not return a DomAttr + $myAttr=$this->myDOMNode->ownerDocument->createAttribute($name); + $myAttr->value=htmlspecialchars($value,ENT_QUOTES); //Entity problem reported by AL-DesignWorks 2007-09-07 + $this->myDOMNode->setAttributeNode($myAttr); + return new php4DOMAttr($myAttr,$this->myOwnerDocument); + } + /*function set_attribute_node($attr) + { + $this->myDOMNode->setAttributeNode($this->_importNode($attr)); + return $attr; + }*/ + function set_name($name) + { + if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name); + else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); + $myDOMNodeList=$this->myDOMNode->attributes; + $i=0; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item($i++)) + if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value); + else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); + $myDOMNodeList=$this->myDOMNode->childNodes; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); + $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode); + $this->myDOMNode=$newNode; + return true; + } + function tagname() {return $this->myDOMNode->tagName;} +} + +class php4DOMNode +{ + public $myDOMNode; + public $myOwnerDocument; + function php4DOMNode($aDomNode,$aOwnerDocument) + { + $this->myDOMNode=$aDomNode; + $this->myOwnerDocument=$aOwnerDocument; + } + function __get($name) + { + switch ($name) + { + case 'type': return $this->myDOMNode->nodeType; + case 'tagname': return $this->myDOMNode->tagName; //DomElement + case 'content': return $this->myDOMNode->textContent; + case 'name': return $this->myDOMNode->name; //DomAttribute + case 'value': return $this->myDOMNode->value; + default: + $myErrors=debug_backtrace(); + trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE); + return false; + } + } + function add_child($newnode) {return append_child($newnode);} + function add_namespace($uri,$prefix) {return false;} + function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} + function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} + function attributes() + { + $myDOMNodeList=$this->myDOMNode->attributes; + $nodeSet=array(); + $i=0; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); + return $nodeSet; + } + function child_nodes() + { + $myDOMNodeList=$this->myDOMNode->childNodes; + $nodeSet=array(); + $i=0; + if (isset($myDOMNodeList)) + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); + return $nodeSet; + } + function children() {return $this->child_nodes();} + function clone_node($deep=false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);} + //dump_node($node) should only be called on php4DOMDocument + function dump_node($node=null) {return $node==null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode);} + function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);} + function get_content() {return $this->myDOMNode->textContent;} + function has_attributes() {return $this->myDOMNode->hasAttributes();} + function has_child_nodes() {return $this->myDOMNode->hasChildNodes();} + function insert_before($newnode,$refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode),$refnode==null?null:$refnode->myDOMNode),$this->myOwnerDocument);} + function is_blank_node() {return ($this->myDOMNode->nodeType===XML_TEXT_NODE)&&preg_match('%^\s*$%',$this->myDOMNode->nodeValue);} + function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);} + function new_child($name,$content) + { + $mySubNode=$this->myDOMNode->ownerDocument->createElement($name); + $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($content))); + $this->myDOMNode->appendChild($mySubNode); + return new php4DOMElement($mySubNode,$this->myOwnerDocument); + } + function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);} + function node_name() {return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;} //Avoid namespace prefix for DOMElement + function node_type() {return $this->myDOMNode->nodeType;} + function node_value() {return $this->myDOMNode->nodeValue;} + function owner_document() {return $this->myOwnerDocument;} + function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);} + function prefix() {return $this->myDOMNode->prefix;} + function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);} + function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);} + function replace_child($newnode,$oldnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode),$oldnode->myDOMNode),$this->myOwnerDocument);} + function replace_node($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode),$this->myDOMNode),$this->myOwnerDocument);} + function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($text)));} //Entity problem reported by AL-DesignWorks 2007-09-07 + //function set_name($name) {return $this->myOwnerDocument->renameNode($this->myDOMNode,$this->myDOMNode->namespaceURI,$name);} + function set_namespace($uri,$prefix=null) + {//Contributions by Daniel Walker 2006-09-08 + $nsprefix=$this->myDOMNode->lookupPrefix($uri); + if ($nsprefix==null) + { + $nsprefix= $prefix==null ? $nsprefix='a'.sprintf('%u',crc32($uri)) : $prefix; + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) + { + if (($prefix!=null)&&$this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)&& + ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)!=$uri)) + {//Remove namespace + $parent=$this->myDOMNode->ownerElement; + $parent->removeAttributeNode($this->myDOMNode); + $parent->setAttribute($this->myDOMNode->localName,$this->myDOMNode->nodeValue); + $this->myDOMNode=$parent->getAttributeNode($this->myDOMNode->localName); + return; + } + $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$nsprefix,$uri); + } + } + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) + { + $parent=$this->myDOMNode->ownerElement; + $parent->removeAttributeNode($this->myDOMNode); + $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue); + $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName); + } + elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) + { + $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName); + foreach ($this->myDOMNode->attributes as $n) $NewNode->appendChild($n->cloneNode(true)); + foreach ($this->myDOMNode->childNodes as $n) $NewNode->appendChild($n->cloneNode(true)); + $xpath=new DOMXPath($this->myDOMNode->ownerDocument); + $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode); //Add old namespaces + foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); + $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode); + $this->myDOMNode=$NewNode; + } + } + function unlink_node() + { + if ($this->myDOMNode->parentNode!=null) + { + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); + else $this->myDOMNode->parentNode->removeChild($this->myDOMNode); + } + } + protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //To import DOMNode from another DOMDocument + static function _newDOMElement($aDOMNode,$aOwnerDocument) + {//Check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper + if ($aDOMNode==null) return null; + switch ($aDOMNode->nodeType) + { + case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument); + case XML_TEXT_NODE: return new php4DOMText($aDOMNode,$aOwnerDocument); + case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode,$aOwnerDocument); + case XML_PI_NODE: return new php4DomProcessingInstruction($aDOMNode,$aOwnerDocument); + default: return new php4DOMNode($aDOMNode,$aOwnerDocument); + } + } +} + +class php4DomProcessingInstruction extends php4DOMNode +{ + function data() {return $this->myDOMNode->data;} + function target() {return $this->myDOMNode->target;} +} + +class php4DOMText extends php4DOMNode +{ + function __get($name) + { + if ($name==='tagname') return '#text'; + else return parent::__get($name); + } + function tagname() {return '#text';} + function set_content($text) {$this->myDOMNode->nodeValue=$text; return true;} +} + +if (!defined('XPATH_NODESET')) +{ + define('XPATH_UNDEFINED',0); + define('XPATH_NODESET',1); + define('XPATH_BOOLEAN',2); + define('XPATH_NUMBER',3); + define('XPATH_STRING',4); + /*define('XPATH_POINT',5); + define('XPATH_RANGE',6); + define('XPATH_LOCATIONSET',7); + define('XPATH_USERS',8); + define('XPATH_XSLT_TREE',9);*/ +} + +class php4DOMNodelist +{ + private $myDOMNodelist; + public $nodeset; + public $type; + public $value; + function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) + { + if (is_object($aDOMNodelist)||is_array($aDOMNodelist)) + { + $this->myDOMNodelist=$aDOMNodelist; + $this->nodeset=array(); + if (isset($this->myDOMNodelist)) + { + $this->type=XPATH_NODESET; + $i=0; + while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); + } + else $this->type=XPATH_UNDEFINED; + } + elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) + { + $this->type=XPATH_NUMBER; + $this->value=$aDOMNodelist; + } + elseif (is_bool($aDOMNodelist)) + { + $this->type=XPATH_BOOLEAN; + $this->value=$aDOMNodelist; + } + elseif (is_string($aDOMNodelist)) + { + $this->type=XPATH_STRING; + $this->value=$aDOMNodelist; + } + else $this->type=XPATH_UNDEFINED; + } +} + +class php4DOMXPath +{ + public $myDOMXPath; + private $myOwnerDocument; + function php4DOMXPath($dom_document) + { + //TODO: If $dom_document is a DomElement, make that default $contextnode and modify XPath. Ex: '/test' + $this->myOwnerDocument=$dom_document->myOwnerDocument; + $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode); + } + function xpath_eval($eval_str,$contextnode=null) + { + if (method_exists($this->myDOMXPath,'evaluate')) + return isset($contextnode) ? new php4DOMNodelist($this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument) : new php4DOMNodelist($this->myDOMXPath->evaluate($eval_str),$this->myOwnerDocument); + else return isset($contextnode) ? new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument) : new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument); + } + function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} +} + +if (extension_loaded('xsl')) +{//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/ +function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));} +function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);} +function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));} +class php4DomXsltStylesheet +{ + private $myxsltProcessor; + function php4DomXsltStylesheet($dom_document) + { + $this->myxsltProcessor=new xsltProcessor(); + $this->myxsltProcessor->importStyleSheet($dom_document); + } + function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) + { + foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value); + $myphp4DOMDocument=new php4DOMDocument(); + $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); + return $myphp4DOMDocument; + } + function result_dump_file($dom_document,$filename) + { + $html=$dom_document->myDOMNode->saveHTML(); + file_put_contents($filename,$html); + return $html; + } + function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();} +} +} + +//END \ No newline at end of file diff --git a/application/helpers/export_helper.php b/application/helpers/export_helper.php new file mode 100644 index 00000000000..877ab7b40aa --- /dev/null +++ b/application/helpers/export_helper.php @@ -0,0 +1,1904 @@ +$query
".$connect->ErrorMsg()); //Checked + $num_fields = $result->FieldCount(); + + //This shouldn't occur, but just to be safe: + if (count($fields)<>$num_fields) safe_die("Database inconsistency error"); + + while (!$result->EOF) { + $row = $result->GetRowAssoc(true); //Get assoc array, use uppercase + reset($fields); //Jump to the first element in the field array + $i = 1; + foreach ($fields as $field) + { + $fieldno = strtoupper($field['sql_name']); + if ($field['SPSStype']=='DATETIME23.2'){ + #convert mysql datestamp (yyyy-mm-dd hh:mm:ss) to SPSS datetime (dd-mmm-yyyy hh:mm:ss) format + if (isset($row[$fieldno])) + { + list( $year, $month, $day, $hour, $minute, $second ) = preg_split( '([^0-9])', $row[$fieldno] ); + if ($year != '' && (int)$year >= 1970) + { + echo "'".date('d-m-Y H:i:s', mktime( $hour, $minute, $second, $month, $day, $year ) )."'"; + } else + { + echo ($na); + } + } else + { + echo ($na); + } + } else if ($field['LStype'] == 'Y') + { + if ($row[$fieldno] == 'Y') // Yes/No Question Type + { + echo( "'1'"); + } else if ($row[$fieldno] == 'N'){ + echo( "'2'"); + } else { + echo($na); + } + } else if ($field['LStype'] == 'G') //Gender + { + if ($row[$fieldno] == 'F') + { + echo( "'1'"); + } else if ($row[$fieldno] == 'M'){ + echo( "'2'"); + } else { + echo($na); + } + } else if ($field['LStype'] == 'C') //Yes/No/Uncertain + { + if ($row[$fieldno] == 'Y') + { + echo( "'1'"); + } else if ($row[$fieldno] == 'N'){ + echo( "'2'"); + } else if ($row[$fieldno] == 'U'){ + echo( "'3'"); + } else { + echo($na); + } + } else if ($field['LStype'] == 'E') //Increase / Same / Decrease + { + if ($row[$fieldno] == 'I') + { + echo( "'1'"); + } else if ($row[$fieldno] == 'S'){ + echo( "'2'"); + } else if ($row[$fieldno] == 'D'){ + echo( "'3'"); + } else { + echo($na); + } + } elseif (($field['LStype'] == 'P' || $field['LStype'] == 'M') && (substr($field['code'],-7) != 'comment' && substr($field['code'],-5) != 'other')) + { + if ($row[$fieldno] == 'Y') + { + echo("'1'"); + } else + { + echo("'0'"); + } + } elseif (!$field['hide']) { + $strTmp=mb_substr(strip_tags_full($row[$fieldno]), 0, $length_data); + if (trim($strTmp) != ''){ + $strTemp=str_replace(array("'","\n","\r"),array("''",' ',' '),trim($strTmp)); + /* + * Temp quick fix for replacing decimal dots with comma's + if (my_is_numeric($strTemp)) { + $strTemp = str_replace('.',',',$strTemp); + } + */ + echo "'$strTemp'"; + } + else + { + echo $na; + } + } + if ($i<$num_fields && !$field['hide']) echo ','; + $i++; + } + echo "\n"; + $result->MoveNext(); + } +} + +/** + * Check it the gives field has a labelset and return it as an array if true + * + * @param $field array field from spss_fieldmap + * @return array or false + */ +function spss_getvalues ($field = array(), $qidattributes = null ) { + global $surveyid, $dbprefix, $connect, $clang, $language, $length_vallabel; + + if (!isset($field['LStype']) || empty($field['LStype'])) return false; + $answers=array(); + if (strpos("!LORFWZWH1",$field['LStype']) !== false) { + if (substr($field['code'],-5) == 'other' || substr($field['code'],-7) == 'comment') { + //We have a comment field, so free text + } else { + $query = "SELECT {$dbprefix}answers.code, {$dbprefix}answers.answer, + {$dbprefix}questions.type FROM {$dbprefix}answers, {$dbprefix}questions WHERE"; + + if (isset($field['scale_id'])) $query .= " {$dbprefix}answers.scale_id = " . (int) $field['scale_id'] . " AND"; + + $query .= " {$dbprefix}answers.qid = '".$field["qid"]."' and {$dbprefix}questions.language='".$language."' and {$dbprefix}answers.language='".$language."' + and {$dbprefix}questions.qid='".$field['qid']."' ORDER BY sortorder ASC"; + $result=db_execute_assoc($query) or safe_die("Couldn't lookup value labels
$query
".$connect->ErrorMsg()); //Checked + $num_results = $result->num_rows(); + if ($num_results > 0) + { + $displayvaluelabel = 0; + # Build array that has to be returned + for ($i=0; $i < $num_results; $i++) + { + $row = $result->row_array(); + $answers[] = array('code'=>$row['code'], 'value'=>mb_substr(strip_tags_full($row["answer"]),0,$length_vallabel)); + } + } + } + } elseif ($field['LStype'] == ':') { + $displayvaluelabel = 0; + //Get the labels that could apply! + if (is_null($qidattributes)) $qidattributes=getQuestionAttributes($field["qid"], $field['LStype']); + if (trim($qidattributes['multiflexible_max'])!='') { + $maxvalue=$qidattributes['multiflexible_max']; + } else { + $maxvalue=10; + } + if (trim($qidattributes['multiflexible_min'])!='') + { + $minvalue=$qidattributes['multiflexible_min']; + } else { + $minvalue=1; + } + if (trim($qidattributes['multiflexible_step'])!='') + { + $stepvalue=$qidattributes['multiflexible_step']; + } else { + $stepvalue=1; + } + if ($qidattributes['multiflexible_checkbox']!=0) { + $minvalue=0; + $maxvalue=1; + $stepvalue=1; + } + for ($i=$minvalue; $i<=$maxvalue; $i+=$stepvalue) + { + $answers[] = array('code'=>$i, 'value'=>$i); + } + } elseif ($field['LStype'] == 'M' && substr($field['code'],-5) != 'other' && $field['size'] > 0) + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Yes')); + $answers[] = array('code'=>0, 'value'=>$clang->gT('Not Selected')); + } elseif ($field['LStype'] == "P" && substr($field['code'],-5) != 'other' && substr($field['code'],-7) != 'comment') + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Yes')); + $answers[] = array('code'=>0, 'value'=>$clang->gT('Not Selected')); + } elseif ($field['LStype'] == "G" && $field['size'] > 0) + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Female')); + $answers[] = array('code'=>2, 'value'=>$clang->gT('Male')); + } elseif ($field['LStype'] == "Y" && $field['size'] > 0) + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Yes')); + $answers[] = array('code'=>2, 'value'=>$clang->gT('No')); + } elseif ($field['LStype'] == "C" && $field['size'] > 0) + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Yes')); + $answers[] = array('code'=>2, 'value'=>$clang->gT('No')); + $answers[] = array('code'=>3, 'value'=>$clang->gT('Uncertain')); + } elseif ($field['LStype'] == "E" && $field['size'] > 0) + { + $answers[] = array('code'=>1, 'value'=>$clang->gT('Increase')); + $answers[] = array('code'=>2, 'value'=>$clang->gT('Same')); + $answers[] = array('code'=>3, 'value'=>$clang->gT('Decrease')); + } + if (count($answers)>0) { + //check the max width of the answers + $size = 0; + $spsstype = $field['SPSStype']; + foreach ($answers as $answer) { + $len = mb_strlen($answer['code']); + if ($len>$size) $size = $len; + if ($spsstype=='F' && (my_is_numeric($answer['code'])===false || $size>16)) $spsstype='A'; + } + $answers['SPSStype'] = $spsstype; + $answers['size'] = $size; + return $answers; + } else { + return false; + } +} + +/** + * Creates a fieldmap with all information necessary to output the fields + * + * @param $prefix string prefix for the variable ID + * @return array + */ +function spss_fieldmap($prefix = 'V') { + global $surveyid, $dbprefix, $typeMap, $connect, $clang; + global $surveyprivate, $tokensexist, $language; + + $fieldmap = createFieldMap($surveyid, 'full'); //Create a FULL fieldmap + + #See if tokens are being used + $tokensexist = tableExists('tokens_'.$surveyid); + + #Lookup the names of the attributes + $query="SELECT sid, anonymized, language FROM {$dbprefix}surveys WHERE sid=$surveyid"; + $result=db_execute_assoc($query) or safe_die("Couldn't count fields
$query
".$connect->ErrorMsg()); //Checked + $num_results = $result->num_rows(); + $num_fields = $num_results; + # Build array that has to be returned + for ($i=0; $i < $num_results; $i++) { + $row = $result->row_array(); + $surveyprivate=$row['anonymized']; + $language=$row['language']; + } + + $fieldno=0; + + $fields=array(); + if (isset($tokensexist) && $tokensexist == true && $surveyprivate == 'N') { + $tokenattributes=GetTokenFieldsAndNames($surveyid,false); + foreach ($tokenattributes as $attributefield=>$attributedescription) + { + //Drop the token field, since it is in the survey too + if($attributefield!='token') { + $fieldno++; + $fields[] = array('id'=>"$prefix$fieldno",'name'=>mb_substr($attributefield, 0, 8), + 'qid'=>0,'code'=>'','SPSStype'=>'A','LStype'=>'Undef', + 'VariableLabel'=>$attributedescription,'sql_name'=>$attributefield,'size'=>'100', + 'title'=>$attributefield,'hide'=>0, 'scale'=>''); + } + } + } + + $tempArray = array(); + $fieldnames = array_values($connect->MetaColumnNames("{$dbprefix}survey_$surveyid", true)); + $num_results = count($fieldnames); + $num_fields = $num_results; + $diff = 0; + $noQID = Array('id', 'token', 'datestamp', 'submitdate', 'startdate', 'startlanguage', 'ipaddr', 'refurl', 'lastpage'); + # Build array that has to be returned + for ($i=0; $i < $num_results; $i++) { + #Conditions for SPSS fields: + # - Length may not be longer than 8 characters + # - Name may not begin with a digit + $fieldname = $fieldnames[$i]; + $fieldtype = ''; + $ftype=''; + $val_size = 1; + $hide = 0; + $export_scale = ''; + $code=''; + $scale_id = null; + $aQuestionAttribs=array(); + + #Determine field type + if ($fieldname=='submitdate' || $fieldname=='startdate' || $fieldname == 'datestamp') { + $fieldtype = 'DATETIME23.2'; + } elseif ($fieldname=='startlanguage') { + $fieldtype = 'A'; + $val_size = 19; + } elseif ($fieldname=='token') { + $fieldtype = 'A'; + $val_size = 16; + } elseif ($fieldname=='id') { + $fieldtype = 'F'; + $val_size = 7; //Arbitrarilty restrict to 9,999,999 (7 digits) responses/survey + } elseif ($fieldname == 'ipaddr') { + $fieldtype = 'A'; + $val_size = 15; + } elseif ($fieldname == 'refurl') { + $fieldtype = 'A'; + $val_size = 255; + } elseif ($fieldname == 'lastpage') { + $hide = 1; + } + + #Get qid (question id) + if (in_array($fieldname, $noQID) || substr($fieldname,0,10)=='attribute_'){ + $qid = 0; + $varlabel = $fieldname; + $ftitle = $fieldname; + } else{ + //GET FIELD DATA + if (!isset($fieldmap[$fieldname])) { + //Field in database but no longer in survey... how is this possible? + //@TODO: think of a fix. + $fielddata = array(); + $qid=0; + $varlabel = $fieldname; + $ftitle = $fieldname; + $fieldtype = "F"; + $val_size = 1; + } else { + $fielddata=$fieldmap[$fieldname]; + $qid=$fielddata['qid']; + $ftype=$fielddata['type']; + $fsid=$fielddata['sid']; + $fgid=$fielddata['gid']; + $code=mb_substr($fielddata['fieldname'],strlen($fsid."X".$fgid."X".$qid)); + $varlabel=$fielddata['question']; + if (isset($fielddata['scale'])) $varlabel = "[{$fielddata['scale']}] ". $varlabel; + if (isset($fielddata['subquestion'])) $varlabel = "[{$fielddata['subquestion']}] ". $varlabel; + if (isset($fielddata['subquestion2'])) $varlabel = "[{$fielddata['subquestion2']}] ". $varlabel; + if (isset($fielddata['subquestion1'])) $varlabel = "[{$fielddata['subquestion1']}] ". $varlabel; + $ftitle=$fielddata['title']; + if (!is_null($code) && $code<>"" ) $ftitle .= "_$code"; + if (isset($typeMap[$ftype]['size'])) $val_size = $typeMap[$ftype]['size']; + if (isset($fielddata['scale_id'])) $scale_id = $fielddata['scale_id']; + if($fieldtype == '') $fieldtype = $typeMap[$ftype]['SPSStype']; + if (isset($typeMap[$ftype]['hide'])) { + $hide = $typeMap[$ftype]['hide']; + $diff++; + } + //Get default scale for this type + if (isset($typeMap[$ftype]['Scale'])) $export_scale = $typeMap[$ftype]['Scale']; + //But allow override + $aQuestionAttribs = getQuestionAttributes($qid,$ftype); + if (isset($aQuestionAttribs['scale_export'])) $export_scale = $aQuestionAttribs['scale_export']; + } + + } + $fieldno++; + $fid = $fieldno - $diff; + $lsLong = isset($typeMap[$ftype]["name"])?$typeMap[$ftype]["name"]:$ftype; + $tempArray = array('id'=>"$prefix$fid",'name'=>mb_substr($fieldname, 0, 8), + 'qid'=>$qid,'code'=>$code,'SPSStype'=>$fieldtype,'LStype'=>$ftype,"LSlong"=>$lsLong, + 'ValueLabels'=>'','VariableLabel'=>$varlabel,"sql_name"=>$fieldname,"size"=>$val_size, + 'title'=>$ftitle,'hide'=>$hide,'scale'=>$export_scale, 'scale_id'=>$scale_id); + //Now check if we have to retrieve value labels + $answers = spss_getvalues($tempArray, $aQuestionAttribs); + if (is_array($answers)) { + //Ok we have answers + if (isset($answers['size'])) { + $tempArray['size'] = $answers['size']; + unset($answers['size']); + } + if (isset($answers['SPSStype'])) { + $tempArray['SPSStype'] = $answers['SPSStype']; + unset($answers['SPSStype']); + } + $tempArray['answers'] = $answers; + } + $fields[] = $tempArray; + } + return $fields; +} + +/** + * Creates a query string with all fields for the export + * + * @return string + */ +function spss_getquery() { + global $surveyprivate, $dbprefix, $surveyid, $tokensexist; + + #See if tokens are being used + if (isset($tokensexist) && $tokensexist == true && $surveyprivate == 'N') { + $query="SELECT "; + $tokenattributes=GetTokenFieldsAndNames($surveyid,false); + foreach ($tokenattributes as $attributefield=>$attributedescription) { + //Drop the token field, since it is in the survey too + if($attributefield!='token') { + $query .= "{$dbprefix}tokens_$surveyid.$attributefield, "; + } + } + $query .= "{$dbprefix}survey_$surveyid.* + FROM {$dbprefix}survey_$surveyid + LEFT JOIN {$dbprefix}tokens_$surveyid ON {$dbprefix}survey_$surveyid.token = {$dbprefix}tokens_$surveyid.token"; + } else { + $query = "SELECT * + FROM {$dbprefix}survey_$surveyid"; + } + switch (incompleteAnsFilterstate()) { + case 'inc': + //Inclomplete answers only + $query .= ' WHERE submitdate is null '; + break; + case 'filter': + //Inclomplete answers only + $query .= ' WHERE submitdate is not null '; + break; + } + return $query; +} + +/** +* BuildXMLFromQuery() creates a datadump of a table in XML using XMLWriter +* +* @param mixed $xmlwriter The existing XMLWriter object +* @param mixed $Query The table query to build from +* @param mixed $tagname If the XML tag of the resulting question should be named differently than the table name set it here +* @param array $excludes array of columnames not to include in export +*/ +function BuildXMLFromQuery($xmlwriter, $Query, $tagname='', $excludes = array()) +{ + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + $QueryResult = db_execute_assoc($Query) or safe_die ("ERROR: $QueryResult
".$connect->ErrorMsg()); //safe + preg_match('/FROM (\w+)( |,)/', $Query, $MatchResults); + if ($tagname!='') + { + $TableName=$tagname; + } + else + { + $TableName = $MatchResults[1];; + $TableName = substr($TableName, strlen($dbprefix), strlen($TableName)); + } + if ($QueryResult->num_rows()>0) + { + $exclude = array_flip($excludes); //Flip key/value in array for faster checks + $xmlwriter->startElement($TableName); + $xmlwriter->startElement('fields'); + $Columninfo = $QueryResult->row_array(); + foreach ($Columninfo as $fieldname=>$value) + { + if (!isset($exclude[$fieldname])) $xmlwriter->writeElement('fieldname',$fieldname); + } + $xmlwriter->endElement(); // close columns + $xmlwriter->startElement('rows'); + foreach($QueryResult->result_array() as $Row) + { + $xmlwriter->startElement('row'); + foreach ($Row as $Key=>$Value) + { + if (!isset($exclude[$Key])) { + $xmlwriter->startElement($Key); + // Remove invalid XML characters + $xmlwriter->writeCData(preg_replace('/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u','',$Value)); + $xmlwriter->endElement(); + } + } + $xmlwriter->endElement(); // close row + } + $xmlwriter->endElement(); // close rows + $xmlwriter->endElement(); // close tablename + } +} + +/** + * from export_structure_xml.php + */ +function survey_getXMLStructure($surveyid, $xmlwriter, $exclude=array()) +{ + + $CI =& get_instance(); + + $sdump = ""; + + $dbprefix = $CI->db->dbprefix; + + if ((!isset($exclude) && $exclude['answers'] !== true) || empty($exclude)) + { + //Answers table + $aquery = "SELECT {$dbprefix}answers.* + FROM {$dbprefix}answers, {$dbprefix}questions + WHERE {$dbprefix}answers.language={$dbprefix}questions.language + AND {$dbprefix}answers.qid={$dbprefix}questions.qid + AND {$dbprefix}questions.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$aquery); + } + + // Assessments + $query = "SELECT {$dbprefix}assessments.* + FROM {$dbprefix}assessments + WHERE {$dbprefix}assessments.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$query); + + if ((!isset($exclude) && $exclude['conditions'] !== true) || empty($exclude)) + { + //Conditions table + $cquery = "SELECT DISTINCT {$dbprefix}conditions.* + FROM {$dbprefix}conditions, {$dbprefix}questions + WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid + AND {$dbprefix}questions.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$cquery); + } + + //Default values + $query = "SELECT {$dbprefix}defaultvalues.* + FROM {$dbprefix}defaultvalues JOIN {$dbprefix}questions ON {$dbprefix}questions.qid = {$dbprefix}defaultvalues.qid AND {$dbprefix}questions.sid=$surveyid AND {$dbprefix}questions.language={$dbprefix}defaultvalues.language "; + + BuildXMLFromQuery($xmlwriter,$query); + + // Groups + $gquery = "SELECT * + FROM {$dbprefix}groups + WHERE sid=$surveyid + ORDER BY gid"; + BuildXMLFromQuery($xmlwriter,$gquery); + + //Questions + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE sid=$surveyid and parent_qid=0 + ORDER BY qid"; + BuildXMLFromQuery($xmlwriter,$qquery); + + //Subquestions + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE sid=$surveyid and parent_qid>0 + ORDER BY qid"; + BuildXMLFromQuery($xmlwriter,$qquery,'subquestions'); + + //Question attributes + $sBaseLanguage=GetBaseLanguageFromSurveyID($surveyid); + if ($CI->db->platform() == 'odbc_mssql' || $CI->db->platform() == 'odbtp' || $CI->db->platform() == 'mssql_n' || $CI->db->platform() =='mssqlnative') + { + $query="SELECT qa.qid, qa.attribute, cast(qa.value as varchar(4000)) as value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, cast(qa.value as varchar(4000))"; + } + else { + $query="SELECT qa.qid, qa.attribute, qa.value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, qa.value"; + } + + BuildXMLFromQuery($xmlwriter,$query,'question_attributes'); + + if ((!isset($exclude) && $exclude['quotas'] !== true) || empty($exclude)) + { + //Quota + $query = "SELECT {$dbprefix}quota.* + FROM {$dbprefix}quota + WHERE {$dbprefix}quota.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$query); + + //1Quota members + $query = "SELECT {$dbprefix}quota_members.* + FROM {$dbprefix}quota_members + WHERE {$dbprefix}quota_members.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$query); + + //Quota languagesettings + $query = "SELECT {$dbprefix}quota_languagesettings.* + FROM {$dbprefix}quota_languagesettings, {$dbprefix}quota + WHERE {$dbprefix}quota.id = {$dbprefix}quota_languagesettings.quotals_quota_id + AND {$dbprefix}quota.sid=$surveyid"; + BuildXMLFromQuery($xmlwriter,$query); + } + + // Surveys + $squery = "SELECT * + FROM {$dbprefix}surveys + WHERE sid=$surveyid"; + //Exclude some fields from the export + BuildXMLFromQuery($xmlwriter,$squery,'',array('owner_id','active','datecreated')); + + // Survey language settings + $slsquery = "SELECT * + FROM {$dbprefix}surveys_languagesettings + WHERE surveyls_survey_id=$surveyid"; + BuildXMLFromQuery($xmlwriter,$slsquery); + +} + +/** + * from export_structure_xml.php + */ +function survey_getXMLData($surveyid, $exclude = array()) +{ + $CI =& get_instance(); + $xml = getXMLWriter(); + $xml->openMemory(); + $xml->setIndent(true); + $xml->startDocument('1.0', 'UTF-8'); + $xml->startElement('document'); + $xml->writeElement('LimeSurveyDocType','Survey'); + $xml->writeElement('DBVersion',$CI->config->item("dbversionnumber")); + $xml->startElement('languages'); + $surveylanguages=GetAdditionalLanguagesFromSurveyID($surveyid); + $surveylanguages[]=GetBaseLanguageFromSurveyID($surveyid); + foreach ($surveylanguages as $surveylanguage) + { + $xml->writeElement('language',$surveylanguage); + } + $xml->endElement(); + survey_getXMLStructure($surveyid, $xml,$exclude); + $xml->endElement(); // close columns + $xml->endDocument(); + return $xml->outputMemory(true); +} + +/** + * from export_structure_quexml.php + */ +function quexml_cleanup($string) +{ + return trim(strip_tags(str_ireplace("
","\n",$string))); +} + +/** + * from export_structure_quexml.php + */ +function quexml_create_free($f,$len,$lab="") +{ + global $dom; + $free = $dom->create_element("free"); + + $format = $dom->create_element("format"); + $format->set_content(quexml_cleanup($f)); + + $length = $dom->create_element("length"); + $length->set_content(quexml_cleanup($len)); + + $label = $dom->create_element("label"); + $label->set_content(quexml_cleanup($lab)); + + $free->append_child($format); + $free->append_child($length); + $free->append_child($label); + + + return $free; +} + +/** + * from export_structure_quexml.php + */ +function quexml_fixed_array($array) +{ + global $dom; + $fixed = $dom->create_element("fixed"); + + foreach ($array as $key => $v) + { + $category = $dom->create_element("category"); + + $label = $dom->create_element("label"); + $label->set_content(quexml_cleanup("$key")); + + $value= $dom->create_element("value"); + $value->set_content(quexml_cleanup("$v")); + + $category->append_child($label); + $category->append_child($value); + + $fixed->append_child($category); + } + + + return $fixed; +} + +/** + * Calculate if this item should have a quexml_skipto element attached to it + * + * from export_structure_quexml.php + * + * @param mixed $qid + * @param mixed $value + * + * @return bool|string Text of item to skip to otherwise false if nothing to skip to + * @author Adam Zammit + * @since 2010-10-28 + */ +function quexml_skipto($qid,$value,$cfieldname = "") +{ + global $connect ; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + global $surveyid ; + $clang=$CI->limesurvey_lang; + + $zeros = $CI->db->escape("0000000000"); + + $Query = "SELECT q.*," . concat("RIGHT(" . concat($zeros,'g.gid') . ",10)","RIGHT(". concat($zeros,'q.question_order') .",10)") ." as globalorder + FROM {$dbprefix}questions as q, {$dbprefix}questions as q2, {$dbprefix}groups as g, {$dbprefix}groups as g2 + WHERE q.parent_qid = 0 + AND q2.parent_qid = 0 + AND q.sid=$surveyid + AND q2.sid=$surveyid + AND q2.qid = $qid + AND g2.gid =q2.gid + AND g.gid = q.gid + AND " . concat("RIGHT(" . concat($zeros,'g.gid') . ",10)","RIGHT(". concat($zeros,'q.question_order') .",10)") ." > " . concat("RIGHT(" . concat($zeros,'g2.gid') . ",10)","RIGHT(". concat($zeros,'q2.question_order') .",10)") ." + ORDER BY globalorder"; + + $QueryResult = db_execute_assoc($Query); + + $nextqid=""; + $nextorder=""; + + $Row = $QueryResult->row_array(); + if ($Row) + { + $nextqid = $Row['qid']; + $nextorder = $Row['globalorder']; + } + else + return false; + + + $Query = "SELECT q.* + FROM {$dbprefix}questions as q + JOIN {$dbprefix}groups as g ON (g.gid = q.gid) + LEFT JOIN {$dbprefix}conditions as c ON (c.cqid = '$qid' AND c.qid = q.qid AND c.method LIKE '==' AND c.value NOT LIKE '$value' $cfieldname) + WHERE q.sid = $surveyid + AND q.parent_qid = 0 + AND " . concat("RIGHT(" . concat($zeros,'g.gid') . ",10)","RIGHT(". concat($zeros,'q.question_order') .",10)") ." >= $nextorder + AND c.cqid IS NULL + ORDER BY " . concat("RIGHT(" . concat($zeros,'g.gid') . ",10)","RIGHT(". concat($zeros,'q.question_order') .",10)"); + + + $QueryResult = db_execute_assoc($Query); + + $Row = $QueryResult->row_array(); + if ($Row) + { + if ($nextqid == $Row['qid']) + return false; + else + return $Row['title']; + } + else + return $clang->gT("End"); + +} + +/** + * from export_structure_quexml.php + */ +function quexml_create_fixed($qid,$rotate=false,$labels=true,$scale=0,$other=false) +{ + global $dom; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + global $quexmllang; + $clang=$CI->limesurvey_lang; + + if ($labels) + $Query = "SELECT * FROM {$dbprefix}labels WHERE lid = $labels AND language='$quexmllang' ORDER BY sortorder ASC"; + else + $Query = "SELECT code,answer as title,sortorder FROM {$dbprefix}answers WHERE qid = $qid AND scale_id = $scale AND language='$quexmllang' ORDER BY sortorder ASC"; + + $QueryResult = db_execute_assoc($Query); + + $fixed = $dom->create_element("fixed"); + + $nextcode = ""; + + foreach($QueryResult->result_array() as $Row) + { + $category = $dom->create_element("category"); + + $label = $dom->create_element("label"); + $label->set_content(quexml_cleanup($Row['title'])); + + $value= $dom->create_element("value"); + $value->set_content(quexml_cleanup($Row['code'])); + + $category->append_child($label); + $category->append_child($value); + + $st = quexml_skipto($qid,$Row['code']); + if ($st !== false) + { + $quexml_skipto = $dom->create_element("quexml_skipto"); + $quexml_skipto->set_content($st); + $category->append_child($quexml_skipto); + } + + + $fixed->append_child($category); + $nextcode = $Row['code']; + } + + if ($other) + { + $category = $dom->create_element("category"); + + $label = $dom->create_element("label"); + $label->set_content(quexml_get_lengthth($qid,"other_replace_text","Other")); + + $value= $dom->create_element("value"); + + //Get next code + if (is_numeric($nextcode)) + $nextcode++; + else if (is_string($nextcode)) + $nextcode = chr(ord($nextcode) + 1); + + $value->set_content($nextcode); + + $category->append_child($label); + $category->append_child($value); + + $contingentQuestion = $dom->create_element("contingentQuestion"); + $length = $dom->create_element("length"); + $text = $dom->create_element("text"); + + $text->set_content($clang->gT("Please specify")); + $length->set_content(24); + $contingentQuestion->append_child($text); + $contingentQuestion->append_child($length); + + $category->append_child($contingentQuestion); + + $fixed->append_child($category); + } + + if ($rotate) $fixed->set_attribute("rotate","true"); + + return $fixed; +} + +/** + * from export_structure_quexml.php + */ +function quexml_get_lengthth($qid,$attribute,$default) +{ + global $dom; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + + $Query = "SELECT value FROM {$dbprefix}question_attributes WHERE qid = $qid AND attribute = '$attribute'"; + //$QueryResult = mysql_query($Query) or die ("ERROR: $QueryResult
".mysql_error()); + $QueryResult = db_execute_assoc($Query); + + $Row = $QueryResult->row_array(); + if ($Row && !empty($Row['value'])) + return $Row['value']; + else + return $default; + +} + +/** + * from export_structure_quexml.php + */ +function quexml_create_multi(&$question,$qid,$varname,$scale_id = false,$free = false,$other = false) +{ + global $dom; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + global $quexmllang ; + global $surveyid; + $clang=$CI->limesurvey_lang; + + $Query = "SELECT * FROM {$dbprefix}questions WHERE parent_qid = $qid AND language='$quexmllang' "; + if ($scale_id != false) $Query .= " AND scale_id = $scale_id "; + $Query .= " ORDER BY question_order ASC"; + //$QueryResult = mysql_query($Query) or die ("ERROR: $QueryResult
".mysql_error()); + $QueryResult = db_execute_assoc($Query); + + $nextcode = ""; + + foreach($QueryResult->result_array() as $Row) + { + $response = $dom->create_element("response"); + if ($free == false) + { + $fixed = $dom->create_element("fixed"); + $category = $dom->create_element("category"); + + $label = $dom->create_element("label"); + $label->set_content(quexml_cleanup($Row['question'])); + + $value= $dom->create_element("value"); + //$value->set_content(quexml_cleanup($Row['title'])); + $value->set_content("1"); + $nextcode = $Row['title']; + + $category->append_child($label); + $category->append_child($value); + + $st = quexml_skipto($qid,'Y'," AND c.cfieldname LIKE '+$surveyid" . "X" . $Row['gid'] . "X" . $qid . $Row['title'] . "' "); + if ($st !== false) + { + $quexml_skipto = $dom->create_element("quexml_skipto"); + $quexml_skipto->set_content($st); + $category->append_child($quexml_skipto); + } + + + $fixed->append_child($category); + + $response->append_child($fixed); + } + else + $response->append_child(quexml_create_free($free['f'],$free['len'],$Row['question'])); + + $response->set_attribute("varName",$varname . quexml_cleanup($Row['title'])); + + $question->append_child($response); + } + + if ($other && $free==false) + { + $response = $dom->create_element("response"); + $fixed = $dom->create_element("fixed"); + $category = $dom->create_element("category"); + + $label = $dom->create_element("label"); + $label->set_content(quexml_get_lengthth($qid,"other_replace_text","Other")); + + $value= $dom->create_element("value"); + + //Get next code + if (is_numeric($nextcode)) + $nextcode++; + else if (is_string($nextcode)) + $nextcode = chr(ord($nextcode) + 1); + + $value->set_content(1); + + $category->append_child($label); + $category->append_child($value); + + $contingentQuestion = $dom->create_element("contingentQuestion"); + $length = $dom->create_element("length"); + $text = $dom->create_element("text"); + + $text->set_content($clang->gT("Please specify")); + $length->set_content(24); + $contingentQuestion->append_child($text); + $contingentQuestion->append_child($length); + + $category->append_child($contingentQuestion); + + $fixed->append_child($category); + $response->append_child($fixed); + $response->set_attribute("varName",$varname . quexml_cleanup($nextcode)); + + $question->append_child($response); + } + + + + + return; + +} + +/** + * from export_structure_quexml.php + */ +function quexml_create_subQuestions(&$question,$qid,$varname,$use_answers = false) +{ + global $dom; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + global $quexmllang ; + + if ($use_answers) + $Query = "SELECT answer as question, code as title FROM {$dbprefix}answers WHERE qid = $qid AND language='$quexmllang' ORDER BY sortorder ASC"; + else + $Query = "SELECT * FROM {$dbprefix}questions WHERE parent_qid = $qid and scale_id = 0 AND language='$quexmllang' ORDER BY question_order ASC"; + $QueryResult = db_execute_assoc($Query); + foreach($QueryResult->result_array() as $Row) + { + $subQuestion = $dom->create_element("subQuestion"); + $text = $dom->create_element("text"); + $text->set_content(quexml_cleanup($Row['question'])); + $subQuestion->append_child($text); + $subQuestion->set_attribute("varName",$varname . quexml_cleanup($Row['title'])); + $question->append_child($subQuestion); + } + + return; +} + +/** + * Export quexml survey. + */ +function quexml_export($surveyi, $quexmllan) +{ + global $dom, $quexmllang, $surveyid; + $quexmllang = $quexmllan; + $surveyid = $surveyi; + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + + $CI->load->helper("admin/domxml_wrapper"); + $dom = domxml_new_doc("1.0"); + + //Title and survey id + $questionnaire = $dom->create_element("questionnaire"); + $title = $dom->create_element("title"); + + $Query = "SELECT * FROM {$dbprefix}surveys,{$dbprefix}surveys_languagesettings WHERE sid=$surveyid and surveyls_survey_id=sid and surveyls_language='".$quexmllang."'"; + $QueryResult = db_execute_assoc($Query); + $Row = $QueryResult->row_array(); + $questionnaire->set_attribute("id", $Row['sid']); + $title->set_content(quexml_cleanup($Row['surveyls_title'])); + $questionnaire->append_child($title); + + //investigator and datacollector + $investigator = $dom->create_element("investigator"); + $name = $dom->create_element("name"); + $name = $dom->create_element("firstName"); + $name = $dom->create_element("lastName"); + $dataCollector = $dom->create_element("dataCollector"); + + $questionnaire->append_child($investigator); + $questionnaire->append_child($dataCollector); + + //questionnaireInfo == welcome + if (!empty($Row['surveyls_welcometext'])) + { + $questionnaireInfo = $dom->create_element("questionnaireInfo"); + $position = $dom->create_element("position"); + $text = $dom->create_element("text"); + $administration = $dom->create_element("administration"); + $position->set_content("before"); + $text->set_content(quexml_cleanup($Row['surveyls_welcometext'])); + $administration->set_content("self"); + $questionnaireInfo->append_child($position); + $questionnaireInfo->append_child($text); + $questionnaireInfo->append_child($administration); + $questionnaire->append_child($questionnaireInfo); + } + + //section == group + + + $Query = "SELECT * FROM {$dbprefix}groups WHERE sid=$surveyid AND language='$quexmllang' order by group_order ASC"; + $QueryResult = db_execute_assoc($Query); + + //for each section + foreach($QueryResult->result_array() as $Row) + { + $gid = $Row['gid']; + + $section = $dom->create_element("section"); + + if (!empty($Row['group_name'])) + { + $sectionInfo = $dom->create_element("sectionInfo"); + $position = $dom->create_element("position"); + $text = $dom->create_element("text"); + $administration = $dom->create_element("administration"); + $position->set_content("title"); + $text->set_content(quexml_cleanup($Row['group_name'])); + $administration->set_content("self"); + $sectionInfo->append_child($position); + $sectionInfo->append_child($text); + $sectionInfo->append_child($administration); + $section->append_child($sectionInfo); + } + + + if (!empty($Row['description'])) + { + $sectionInfo = $dom->create_element("sectionInfo"); + $position = $dom->create_element("position"); + $text = $dom->create_element("text"); + $administration = $dom->create_element("administration"); + $position->set_content("before"); + $text->set_content(quexml_cleanup($Row['description'])); + $administration->set_content("self"); + $sectionInfo->append_child($position); + $sectionInfo->append_child($text); + $sectionInfo->append_child($administration); + $section->append_child($sectionInfo); + } + + + + $section->set_attribute("id", $gid); + + //boilerplate questions convert to sectionInfo elements + $Query = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND gid = $gid AND type LIKE 'X' AND language='$quexmllang' ORDER BY question_order ASC"; + $QR = db_execute_assoc($Query); + foreach($QR->result_array() as $RowQ) + { + $sectionInfo = $dom->create_element("sectionInfo"); + $position = $dom->create_element("position"); + $text = $dom->create_element("text"); + $administration = $dom->create_element("administration"); + + $position->set_content("before"); + $text->set_content(quexml_cleanup($RowQ['question'])); + $administration->set_content("self"); + $sectionInfo->append_child($position); + $sectionInfo->append_child($text); + $sectionInfo->append_child($administration); + + $section->append_child($sectionInfo); + } + + + + //foreach question + $Query = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND gid = $gid AND parent_qid=0 AND language='$quexmllang' AND type NOT LIKE 'X' ORDER BY question_order ASC"; + $QR = db_execute_assoc($Query); + foreach($QR->result_array() as $RowQ) + { + $question = $dom->create_element("question"); + $type = $RowQ['type']; + $qid = $RowQ['qid']; + + $other = false; + if ($RowQ['other'] == 'Y') $other = true; + + //create a new text element for each new line + $questiontext = explode('
',$RowQ['question']); + foreach ($questiontext as $qt) + { + $txt = quexml_cleanup($qt); + if (!empty($txt)) + { + $text = $dom->create_element("text"); + $text->set_content($txt); + $question->append_child($text); + } + } + + + //directive + if (!empty($RowQ['help'])) + { + $directive = $dom->create_element("directive"); + $position = $dom->create_element("position"); + $position->set_content("during"); + $text = $dom->create_element("text"); + $text->set_content(quexml_cleanup($RowQ['help'])); + $administration = $dom->create_element("administration"); + $administration->set_content("self"); + + $directive->append_child($position); + $directive->append_child($text); + $directive->append_child($administration); + + $question->append_child($directive); + } + + $response = $dom->create_element("response"); + $response->set_attribute("varName",quexml_cleanup($RowQ['title'])); + + switch ($type) + { + case "X": //BOILERPLATE QUESTION - none should appear + + break; + case "5": //5 POINT CHOICE radio-buttons + $response->append_child(quexml_fixed_array(array("1" => 1,"2" => 2,"3" => 3,"4" => 4,"5" => 5))); + $question->append_child($response); + break; + case "D": //DATE + $response->append_child(quexml_create_free("date","8","")); + $question->append_child($response); + break; + case "L": //LIST drop-down/radio-button list + $response->append_child(quexml_create_fixed($qid,false,false,0,$other)); + $question->append_child($response); + break; + case "!": //List - dropdown + $response->append_child(quexml_create_fixed($qid,false,false,0,$other)); + $question->append_child($response); + break; + case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea + $response->append_child(quexml_create_fixed($qid,false,false,0,$other)); + $question->append_child($response); + //no comment - this should be a separate question + break; + case "R": //RANKING STYLE + quexml_create_subQuestions($question,$qid,$RowQ['title'],true); + $Query = "SELECT COUNT(*) as sc FROM {$dbprefix}answers WHERE qid = $qid AND language='$quexmllang' "; + $QRE = db_execute_assoc($Query); + //$QRE = mysql_query($Query) or die ("ERROR: $QRE
".mysql_error()); + //$QROW = mysql_fetch_assoc($QRE); + $QROW = $QRE->row_array(); + $response->append_child(quexml_create_free("integer",strlen($QROW['sc']),"")); + $question->append_child($response); + break; + case "M": //Multiple choice checkbox + quexml_create_multi($question,$qid,$RowQ['title'],false,false,$other); + break; + case "P": //Multiple choice with comments checkbox + text + //Not yet implemented + quexml_create_multi($question,$qid,$RowQ['title'],false,false,$other); + //no comments added + break; + case "Q": //MULTIPLE SHORT TEXT + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_create_free("text",quexml_get_lengthth($qid,"maximum_chars","10"),"")); + $question->append_child($response); + break; + case "K": //MULTIPLE NUMERICAL + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_create_free("integer",quexml_get_lengthth($qid,"maximum_chars","10"),"")); + $question->append_child($response); + break; + case "N": //NUMERICAL QUESTION TYPE + $response->append_child(quexml_create_free("integer",quexml_get_lengthth($qid,"maximum_chars","10"),"")); + $question->append_child($response); + break; + case "S": //SHORT FREE TEXT + $response->append_child(quexml_create_free("text",quexml_get_lengthth($qid,"maximum_chars","240"),"")); + $question->append_child($response); + break; + case "T": //LONG FREE TEXT + $response->append_child(quexml_create_free("longtext",quexml_get_lengthth($qid,"display_rows","40"),"")); + $question->append_child($response); + break; + case "U": //HUGE FREE TEXT + $response->append_child(quexml_create_free("longtext",quexml_get_lengthth($qid,"display_rows","80"),"")); + $question->append_child($response); + break; + case "Y": //YES/NO radio-buttons + $response->append_child(quexml_fixed_array(array("Yes" => 1,"No" => 2))); + $question->append_child($response); + break; + case "G": //GENDER drop-down list + $response->append_child(quexml_fixed_array(array("Female" => 1,"Male" => 2))); + $question->append_child($response); + break; + case "A": //ARRAY (5 POINT CHOICE) radio-buttons + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_fixed_array(array("1" => 1,"2" => 2,"3" => 3,"4" => 4,"5" => 5))); + $question->append_child($response); + break; + case "B": //ARRAY (10 POINT CHOICE) radio-buttons + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_fixed_array(array("1" => 1,"2" => 2,"3" => 3,"4" => 4,"5" => 5,"6" => 6,"7" => 7,"8" => 8,"9" => 9,"10" => 10))); + $question->append_child($response); + break; + case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_fixed_array(array("Yes" => 1,"Uncertain" => 2,"No" => 3))); + $question->append_child($response); + break; + case "E": //ARRAY (Increase/Same/Decrease) radio-buttons + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_fixed_array(array("Increase" => 1,"Same" => 2,"Decrease" => 3))); + $question->append_child($response); + break; + case "F": //ARRAY (Flexible) - Row Format + //select subQuestions from answers table where QID + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response->append_child(quexml_create_fixed($qid,false,false,0,$other)); + $question->append_child($response); + //select fixed responses from + break; + case "H": //ARRAY (Flexible) - Column Format + quexml_create_subQuestions($question,$RowQ['qid'],$RowQ['title']); + $response->append_child(quexml_create_fixed($qid,true,false,0,$other)); + $question->append_child($response); + break; + case "1": //Dualscale multi-flexi array + //select subQuestions from answers table where QID + quexml_create_subQuestions($question,$qid,$RowQ['title']); + $response = $dom->create_element("response"); + $response->append_child(quexml_create_fixed($qid,false,false,0,$other)); + $response2 = $dom->create_element("response"); + $response2->set_attribute("varName",quexml_cleanup($RowQ['title']) . "_2"); + $response2->append_child(quexml_create_fixed($qid,false,false,1,$other)); + $question->append_child($response); + $question->append_child($response2); + break; + case ":": //multi-flexi array numbers + quexml_create_subQuestions($question,$qid,$RowQ['title']); + //get multiflexible_checkbox - if set then each box is a checkbox (single fixed response) + $mcb = quexml_get_lengthth($qid,'multiflexible_checkbox',-1); + if ($mcb != -1) + quexml_create_multi($question,$qid,$RowQ['title'],1); + else + { + //get multiflexible_max - if set then make boxes of max this width + $mcm = strlen(quexml_get_lengthth($qid,'multiflexible_max',1)); + quexml_create_multi($question,$qid,$RowQ['title'],1,array('f' => 'integer', 'len' => $mcm, 'lab' => '')); + } + break; + case ";": //multi-flexi array text + quexml_create_subQuestions($question,$qid,$RowQ['title']); + //foreach question where scale_id = 1 this is a textbox + quexml_create_multi($question,$qid,$RowQ['title'],1,array('f' => 'text', 'len' => 10, 'lab' => '')); + break; + case "^": //SLIDER CONTROL - not supported + $response->append_child(quexml_fixed_array(array("NOT SUPPORTED:$type" => 1))); + $question->append_child($response); + break; + } //End Switch + + + + + $section->append_child($question); + } + + + $questionnaire->append_child($section); + } + + + $dom->append_child($questionnaire); + + return $dom->dump_mem(true,'UTF-8'); +} + +/** + * From adodb + * + * Different SQL databases used different methods to combine strings together. + * This function provides a wrapper. + * + * param s variable number of string parameters + * + * Usage: $db->Concat($str1,$str2); + * + * @return concatenated string + */ +function concat() +{ + $arr = func_get_args(); + return implode('+', $arr); +} + +/** + * LSRC csv survey export + */ +function lsrccsv_export($surveyid) +{ + // DUMP THE RELATED DATA FOR A SINGLE SURVEY INTO A SQL FILE FOR IMPORTING LATER ON OR ON ANOTHER SURVEY SETUP + // DUMP ALL DATA WITH RELATED SID FROM THE FOLLOWING TABLES + // 1. Surveys + // 2. Surveys Language Table + // 3. Groups + // 4. Questions + // 5. Answers + // 6. Conditions + // 7. Label Sets + // 8. Labels + // 9. Question Attributes + // 10. Assessments + // 11. Quota + // 12. Quota Members + + include_once("login_check.php"); + + if (!isset($surveyid)) {$surveyid=returnglobal('sid');} + + + if (!$surveyid) + { + echo $htmlheader + ."
\n" + ."\n" + ."\t\n" + ."\t\n" + ."
" + .$clang->gT("Export Survey")."
\n" + ."
" + .$clang->gT("Error")."
\n" + .$clang->gT("No SID has been provided. Cannot dump survey")."
\n" + ."
\n" + ."\t
\n" + ."\n"; + exit; + } + + $dumphead = "# LimeSurvey Survey Dump\n" + . "# DBVersion $dbversionnumber\n" + . "# This is a dumped survey from the LimeSurvey Script\n" + . "# http://www.limesurvey.org/\n" + . "# Do not change this header!\n"; + + //1: Surveys table + $squery = "SELECT * + FROM {$dbprefix}surveys + WHERE sid=$surveyid"; + $sdump = BuildCSVFromQuery($squery); + + //2: Surveys Languagsettings table + $slsquery = "SELECT * + FROM {$dbprefix}surveys_languagesettings + WHERE surveyls_survey_id=$surveyid"; + $slsdump = BuildCSVFromQuery($slsquery); + + //3: Groups Table + $gquery = "SELECT * + FROM {$dbprefix}groups + WHERE sid=$surveyid + ORDER BY gid"; + $gdump = BuildCSVFromQuery($gquery); + + //4: Questions Table + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE sid=$surveyid + ORDER BY qid"; + $qdump = BuildCSVFromQuery($qquery); + + //5: Answers table + $aquery = "SELECT {$dbprefix}answers.* + FROM {$dbprefix}answers, {$dbprefix}questions + WHERE {$dbprefix}answers.language={$dbprefix}questions.language + AND {$dbprefix}answers.qid={$dbprefix}questions.qid + AND {$dbprefix}questions.sid=$surveyid"; + $adump = BuildCSVFromQuery($aquery); + + //6: Conditions table + $cquery = "SELECT DISTINCT {$dbprefix}conditions.* + FROM {$dbprefix}conditions, {$dbprefix}questions + WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid + AND {$dbprefix}questions.sid=$surveyid"; + $cdump = BuildCSVFromQuery($cquery); + + //7: Label Sets + $lsquery = "SELECT DISTINCT {$dbprefix}labelsets.lid, label_name, {$dbprefix}labelsets.languages + FROM {$dbprefix}labelsets, {$dbprefix}questions + WHERE ({$dbprefix}labelsets.lid={$dbprefix}questions.lid or {$dbprefix}labelsets.lid={$dbprefix}questions.lid1) + AND type IN ('F', 'H', 'W', 'Z', '1', ':', ';') + AND sid=$surveyid"; + $lsdump = BuildCSVFromQuery($lsquery); + + //8: Labels + $lquery = "SELECT {$dbprefix}labels.lid, {$dbprefix}labels.code, {$dbprefix}labels.title, {$dbprefix}labels.sortorder,{$dbprefix}labels.language + FROM {$dbprefix}labels, {$dbprefix}questions + WHERE ({$dbprefix}labels.lid={$dbprefix}questions.lid or {$dbprefix}labels.lid={$dbprefix}questions.lid1) + AND type in ('F', 'W', 'H', 'Z', '1', ':', ';') + AND sid=$surveyid + GROUP BY {$dbprefix}labels.lid, {$dbprefix}labels.code, {$dbprefix}labels.title, {$dbprefix}labels.sortorder,{$dbprefix}labels.language"; + $ldump = BuildCSVFromQuery($lquery); + + //9: Question Attributes + $query = "SELECT DISTINCT {$dbprefix}question_attributes.* + FROM {$dbprefix}question_attributes, {$dbprefix}questions + WHERE {$dbprefix}question_attributes.qid={$dbprefix}questions.qid + AND {$dbprefix}questions.sid=$surveyid"; + $qadump = BuildCSVFromQuery($query); + + //10: Assessments; + $query = "SELECT {$dbprefix}assessments.* + FROM {$dbprefix}assessments + WHERE {$dbprefix}assessments.sid=$surveyid"; + $asdump = BuildCSVFromQuery($query); + + //11: Quota; + $query = "SELECT {$dbprefix}quota.* + FROM {$dbprefix}quota + WHERE {$dbprefix}quota.sid=$surveyid"; + $quotadump = BuildCSVFromQuery($query); + + //12: Quota Members; + $query = "SELECT {$dbprefix}quota_members.* + FROM {$dbprefix}quota_members + WHERE {$dbprefix}quota_members.sid=$surveyid"; + $quotamemdump = BuildCSVFromQuery($query); + + $fn = "limesurvey_survey_$surveyid.csv"; + + //header("Content-Type: application/download"); + //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: cache"); // HTTP/1.0 + + //include("../config.php"); + include_once("../config-defaults.php"); + include_once("../common.php"); + include("remotecontrol/lsrc.config.php"); + + $lsrcString = $dumphead. $sdump. $gdump. $qdump. $adump. $cdump. $lsdump. $ldump. $qadump. $asdump. $slsdump. $quotadump. $quotamemdump."\n"; + + //Select title as Filename and save + $surveyTitleSql = "SELECT surveyls_title + FROM {$dbprefix}surveys_languagesettings + WHERE surveyls_survey_id=$surveyid"; + $surveyTitleRs = db_execute_assoc($surveyTitleSql); + $surveyTitle = $surveyTitleRs->FetchRow(); + file_put_contents("remotecontrol/".$coreDir.$surveyTitle['surveyls_title'].".csv",$lsrcString); + + header("Location: $scriptname?sid=$surveyid"); + exit; +} + +// 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 + +function group_export($action, $surveyid, $gid) +{ + $fn = "limesurvey_group_$gid.lsg"; + $xml = getXMLWriter(); + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + + + if($action=='exportstructureLsrcCsvGroup') + { + include_once($homedir.'/remotecontrol/lsrc.config.php'); + //Select group_name as Filename and save + $groupTitleSql = "SELECT group_name + FROM {$dbprefix}groups + WHERE sid=$surveyid AND gid=$gid "; + $groupTitle = $connect->GetOne($groupTitleSql); + $xml->openURI('remotecontrol/'.$queDir.substr($groupTitle,0,20).".lsq"); + } + else + { + header("Content-Type: text/html/force-download"); + 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: cache"); // HTTP/1.0 + + $xml->openURI('php://output'); + } + + $xml->setIndent(true); + $xml->startDocument('1.0', 'UTF-8'); + $xml->startElement('document'); + $xml->writeElement('LimeSurveyDocType','Group'); + $xml->writeElement('DBVersion',$CI->config->item("dbversionnumber")); + $xml->startElement('languages'); + $lquery = "SELECT language + FROM {$dbprefix}groups + WHERE gid=$gid group by language"; + $lresult=db_execute_assoc($lquery); + foreach($lresult->result_array() as $row) + { + $xml->writeElement('language',$row['language']); + } + $xml->endElement(); + group_getXMLStructure($xml,$gid); + $xml->endElement(); // close columns + $xml->endDocument(); + exit; +} + +function group_getXMLStructure($xml,$gid) +{ + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + // Groups + $gquery = "SELECT * + FROM {$dbprefix}groups + WHERE gid=$gid"; + BuildXMLFromQuery($xml,$gquery); + + // Questions table + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE gid=$gid and parent_qid=0 order by question_order, language, scale_id"; + BuildXMLFromQuery($xml,$qquery); + + // Questions table - Subquestions + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE gid=$gid and parent_qid>0 order by question_order, language, scale_id"; + BuildXMLFromQuery($xml,$qquery,'subquestions'); + + //Answers + $aquery = "SELECT DISTINCT {$dbprefix}answers.* + FROM {$dbprefix}answers, {$dbprefix}questions + WHERE ({$dbprefix}answers.qid={$dbprefix}questions.qid) + AND ({$dbprefix}questions.gid=$gid)"; + BuildXMLFromQuery($xml,$aquery); + + //Conditions - THIS CAN ONLY EXPORT CONDITIONS THAT RELATE TO THE SAME GROUP + $cquery = "SELECT DISTINCT c.* + FROM {$dbprefix}conditions c, {$dbprefix}questions q, {$dbprefix}questions b + WHERE (c.cqid=q.qid) + AND (c.qid=b.qid) + AND (q.gid={$gid}) + AND (b.gid={$gid})"; + BuildXMLFromQuery($xml,$cquery,'conditions'); + + //Question attributes + $surveyid=db_execute_assoc("select sid from {$dbprefix}groups where gid={$gid}"); + $surveyid=reset($surveyid->row_array()); + $sBaseLanguage=GetBaseLanguageFromSurveyID($surveyid); + if ($CI->db->platform() == 'odbc_mssql' || $CI->db->platform() == 'odbtp' || $CI->db->platform() == 'mssql_n' || $CI->db->platform() =='mssqlnative') + { + $query="SELECT qa.qid, qa.attribute, cast(qa.value as varchar(4000)) as value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} and q.gid={$gid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, cast(qa.value as varchar(4000))"; + } + else { + $query="SELECT qa.qid, qa.attribute, qa.value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} and q.gid={$gid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, qa.value"; + } + BuildXMLFromQuery($xml,$query,'question_attributes'); + + // Default values + $query = "SELECT dv.* + FROM {$dbprefix}defaultvalues dv + JOIN {$dbprefix}questions ON {$dbprefix}questions.qid = dv.qid + AND {$dbprefix}questions.language=dv.language + AND {$dbprefix}questions.gid=$gid + order by dv.language, dv.scale_id"; + BuildXMLFromQuery($xml,$query,'defaultvalues'); +} + + +// 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 +// - Questions +// - Answers +// - Question attributes +// - Default values + +function question_export($action, $surveyid, $gid, $qid) +{ + $fn = "limesurvey_group_$qid.lsg"; + $xml = getXMLWriter(); + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + + if($action=='exportstructureLsrcCsvQuestion') + { + include_once($homedir.'/remotecontrol/lsrc.config.php'); + //Select title as Filename and save + $questionTitleSql = "SELECT title + FROM {$dbprefix}questions + WHERE qid=$qid AND sid=$surveyid AND gid=$gid "; + $questionTitle = $connect->GetOne($questionTitleSql); + $xml->openURI('remotecontrol/'.$queDir.substr($questionTitle,0,20).".lsq"); + } + else + { + header("Content-Type: text/html/force-download"); + 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: cache"); // HTTP/1.0 + + $xml->openURI('php://output'); + } + + $xml->setIndent(true); + $xml->startDocument('1.0', 'UTF-8'); + $xml->startElement('document'); + $xml->writeElement('LimeSurveyDocType','Question'); + $xml->writeElement('DBVersion',$CI->config->item("dbversionnumber")); + $xml->startElement('languages'); + $lquery = "SELECT language + FROM {$dbprefix}questions + WHERE qid=$qid or parent_qid=$qid group by language"; + $lresult=db_execute_assoc($lquery); + foreach($lresult->result_array() as $row) + { + $xml->writeElement('language',$row['language']); + } + $xml->endElement(); + question_getXMLStructure($xml,$gid,$qid); + $xml->endElement(); // close columns + $xml->endDocument(); + exit; +} + +function question_getXMLStructure($xml,$gid,$qid) +{ + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + + // Questions table + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE qid=$qid and parent_qid=0 order by language, scale_id, question_order"; + BuildXMLFromQuery($xml,$qquery); + + // Questions table - Subquestions + $qquery = "SELECT * + FROM {$dbprefix}questions + WHERE parent_qid=$qid order by language, scale_id, question_order"; + BuildXMLFromQuery($xml,$qquery,'subquestions'); + + + // Answers table + $aquery = "SELECT * + FROM {$dbprefix}answers + WHERE qid = $qid order by language, scale_id, sortorder"; + BuildXMLFromQuery($xml,$aquery); + + + + // Question attributes + $surveyid=db_execute_assoc("select sid from {$dbprefix}groups where gid={$gid}"); + $surveyid=reset($surveyid->row_array()); + $sBaseLanguage=GetBaseLanguageFromSurveyID($surveyid); + if ($CI->db->platform() == 'odbc_mssql' || $CI->db->platform() == 'odbtp' || $CI->db->platform() == 'mssql_n' || $CI->db->platform() =='mssqlnative') + { + $query="SELECT qa.qid, qa.attribute, cast(qa.value as varchar(4000)) as value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} and q.qid={$qid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, cast(qa.value as varchar(4000))"; + } + else { + $query="SELECT qa.qid, qa.attribute, qa.value + FROM {$dbprefix}question_attributes qa JOIN {$dbprefix}questions q ON q.qid = qa.qid AND q.sid={$surveyid} and q.qid={$qid} + where q.language='{$sBaseLanguage}' group by qa.qid, qa.attribute, qa.value"; + } + BuildXMLFromQuery($xml,$query); + + // Default values + $query = "SELECT * + FROM {$dbprefix}defaultvalues + WHERE qid=$qid order by language, scale_id"; + BuildXMLFromQuery($xml,$query); + +} + + +function tokens_export($surveyid) +{ + header("Content-Disposition: attachment; filename=tokens_".$surveyid.".csv"); + header("Content-type: text/comma-separated-values; charset=UTF-8"); + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + header("Pragma: cache"); + + $CI =& get_instance(); + $dbprefix = $CI->db->dbprefix; + $_POST = $CI->input->post(); + + $bquery = "SELECT * FROM ".$CI->db->dbprefix("tokens_$surveyid").' where 1=1'; + if (trim($_POST['filteremail'])!='') + { + if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $connect->databaseType == 'mssqlnative') + { + $bquery .= ' and CAST(email as varchar) like '.db_quoteall('%'.$_POST['filteremail'].'%', true); + } + else + { + $bquery .= ' and email like '.db_quoteall('%'.$_POST['filteremail'].'%', true); + } + } + if ($_POST['tokenstatus']==1) + { + $bquery .= " and completed<>'N'"; + } + if ($_POST['tokenstatus']==2) + { + $bquery .= " and completed='N'"; + if ($thissurvey['anonymized']=='N') + { + $bquery .=" and token not in (select token from ".db_table_name("survey_$surveyid")." group by token)"; + } + } + if ($_POST['tokenstatus']==3 && $thissurvey['anonymized']=='N') + { + $bquery .= " and completed='N' and token in (select token from ".db_table_name("survey_$surveyid")." group by token)"; + } + + if ($_POST['invitationstatus']==1) + { + $bquery .= " and sent<>'N'"; + } + if ($_POST['invitationstatus']==2) + { + $bquery .= " and sent='N'"; + } + + if ($_POST['reminderstatus']==1) + { + $bquery .= " and remindersent<>'N'"; + } + if ($_POST['reminderstatus']==2) + { + $bquery .= " and remindersent='N'"; + } + + if ($_POST['tokenlanguage']!='') + { + $bquery .= " and language=".db_quoteall($_POST['tokenlanguage']); + } + $bquery .= " ORDER BY tid"; + + $bresult = db_execute_assoc($bquery) or die ("$bquery
".htmlspecialchars($connect->ErrorMsg())); + $bfieldcount=$bresult->num_rows(); + // Export UTF8 WITH BOM + $tokenoutput = chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF')); + $tokenoutput .= "tid,firstname,lastname,email,emailstatus,token,language,validfrom,validuntil,invited,reminded,remindercount,completed,usesleft"; + $attrfieldnames = GetAttributeFieldnames($surveyid); + $attrfielddescr = GetTokenFieldsAndNames($surveyid, true); + foreach ($attrfieldnames as $attr_name) + { + $tokenoutput .=", $attr_name"; + if (isset($attrfielddescr[$attr_name])) + $tokenoutput .=" <".str_replace(","," ",$attrfielddescr[$attr_name]).">"; + } + $tokenoutput .="\n"; + foreach($bresult->result_array() as $brow) + { + + if (trim($brow['validfrom']!='')) + { + $datetimeobj = new Date_Time_Converter($brow['validfrom'] , "Y-m-d H:i:s"); + $brow['validfrom']=$datetimeobj->convert('Y-m-d H:i'); + } + if (trim($brow['validuntil']!='')) + { + $datetimeobj = new Date_Time_Converter($brow['validuntil'] , "Y-m-d H:i:s"); + $brow['validuntil']=$datetimeobj->convert('Y-m-d H:i'); + } + + $tokenoutput .= '"'.trim($brow['tid']).'",'; + $tokenoutput .= '"'.trim($brow['firstname']).'",'; + $tokenoutput .= '"'.trim($brow['lastname']).'",'; + $tokenoutput .= '"'.trim($brow['email']).'",'; + $tokenoutput .= '"'.trim($brow['emailstatus']).'",'; + $tokenoutput .= '"'.trim($brow['token']).'",'; + $tokenoutput .= '"'.trim($brow['language']).'",'; + $tokenoutput .= '"'.trim($brow['validfrom']).'",'; + $tokenoutput .= '"'.trim($brow['validuntil']).'",'; + $tokenoutput .= '"'.trim($brow['sent']).'",'; + $tokenoutput .= '"'.trim($brow['remindersent']).'",'; + $tokenoutput .= '"'.trim($brow['remindercount']).'",'; + $tokenoutput .= '"'.trim($brow['completed']).'",'; + $tokenoutput .= '"'.trim($brow['usesleft']).'",'; + foreach ($attrfieldnames as $attr_name) + { + $tokenoutput .='"'.trim($brow[$attr_name]).'",'; + } + $tokenoutput = substr($tokenoutput,0,-1); // remove last comma + $tokenoutput .= "\n"; + } + echo $tokenoutput; + exit; +} diff --git a/application/views/admin/Export/group_view.php b/application/views/admin/Export/group_view.php new file mode 100644 index 00000000000..3932049d8ce --- /dev/null +++ b/application/views/admin/Export/group_view.php @@ -0,0 +1,18 @@ +
+
gT("Export group structure");?>
+ +

+ + + + +

\ No newline at end of file diff --git a/application/views/admin/Export/question_view.php b/application/views/admin/Export/question_view.php new file mode 100644 index 00000000000..83ca8574a77 --- /dev/null +++ b/application/views/admin/Export/question_view.php @@ -0,0 +1,18 @@ +
+
gT("Export question structure");?>
+ +

+ + + + +

\ No newline at end of file diff --git a/application/views/admin/Export/survey_view.php b/application/views/admin/Export/survey_view.php new file mode 100644 index 00000000000..cc58f2d7206 --- /dev/null +++ b/application/views/admin/Export/survey_view.php @@ -0,0 +1,23 @@ +
+
+gT("Export Survey Structure");?>

+ + +

+ +

+ \ No newline at end of file diff --git a/application/views/admin/Survey/Question/questionbar_view.php b/application/views/admin/Survey/Question/questionbar_view.php index 627739188d0..d011ef8daa9 100644 --- a/application/views/admin/Survey/Question/questionbar_view.php +++ b/application/views/admin/Survey/Question/questionbar_view.php @@ -62,7 +62,7 @@ if(bHasSurveyPermission($surveyid,'surveycontent','export')) { ?> - " > /dumpquestion.png' alt='gT("Export this question"); ?>' name='ExportQuestion' /> diff --git a/application/views/admin/Survey/QuestionGroups/questiongroupbar_view.php b/application/views/admin/Survey/QuestionGroups/questiongroupbar_view.php index 80ce6ac919e..279ba71237a 100644 --- a/application/views/admin/Survey/QuestionGroups/questiongroupbar_view.php +++ b/application/views/admin/Survey/QuestionGroups/questiongroupbar_view.php @@ -50,7 +50,7 @@ } else { ?> - "/blank.gif' alt='' width='40' /> + /blank.gif' alt='' width='40' /> - " > + " > /dumpgroup.png' title='' alt='gT("Export this question group"); ?>' name='ExportGroup' /> <?php echo $clang->gT("Display / Export");?>