/**
 * Get data array in XML format.
 * @param $data (array) Array of data (key => value).
 * @param $level (int) Indentation level.
 * @return string XML data
 */
function getDataXML($data, $level = 1)
{
    $xml = '';
    $tb = str_repeat("\t", $level);
    foreach ($data as $key => $value) {
        $xml .= $tb . '<' . $key . '>';
        if (is_array($value)) {
            $xml .= "\n" . getDataXML($value, $level + 1);
        } else {
            $xml .= F_text_to_xml($value);
        }
        $xml .= '</' . $key . '>' . "\n";
    }
    return $xml;
}
Esempio n. 2
0
 // convert and save exporting file
 $outfile = date('YmdHis') . '_rackmap_data_' . md5($sqls) . '.';
 switch ($format_type) {
     case 0:
         // PDF
         $outfile .= 'pdf';
         require_once 'tce_pdf_data.php';
         // get PDF data
         $exdata = getDataPDF($data);
         break;
     case 1:
         // XML
         $outfile .= 'xml';
         $exdata = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . K_NEWLINE;
         $exdata .= '<rackmap version="' . K_RACKMAP_VERSION . '">' . K_NEWLINE;
         $exdata .= getDataXML($data);
         $exdata .= '</rackmap>' . K_NEWLINE;
         break;
     case 2:
         // CSV
         $outfile .= 'csv';
         $exdata = getNestedDataCSV($data);
         break;
     case 3:
         // JSON
         $outfile .= 'json';
         $exdata = json_encode($data);
         break;
     case 4:
         // Serialized PHP Array
         $outfile .= 'phps';
Esempio n. 3
0
/**
 * Get data array in XML format.
 * @param $data (array) Array of data (key => value).
 * @param $level (int) Indentation level.
 * @return string XML data
 */
function getDataXML($data, $level = 1)
{
    $xml = '';
    $tb = str_repeat("\t", $level);
    foreach ($data as $key => $value) {
        $key = strtolower($key);
        $key = preg_replace('/[^a-z0-9]+/', '_', $key);
        if (is_numeric($key[0]) or $key[0] == '_') {
            $key = 'item' . $key;
        }
        $xml .= $tb . '<' . $key . '>';
        if (is_array($value)) {
            $xml .= "\n" . getDataXML($value, $level + 1);
        } else {
            $xml .= F_text_to_xml($value);
        }
        $xml .= '</' . $key . '>' . "\n";
    }
    return $xml;
}
Esempio n. 4
0
/**
 * Export results in XML format.
 * @param $test_id (int) test ID.
 * @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group.
 * @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
 * @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
 * @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
 * @param $display_mode (int) display mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
 * @author Nicola Asuni
 * @return XML data
 */
function F_xml_export_results($test_id, $group_id = 0, $user_id = 0, $startdate = 0, $enddate = 0, $display_mode = 1)
{
    global $l, $db;
    require_once '../config/tce_config.php';
    $xml = '';
    // XML data to be returned
    $xml .= '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . K_NEWLINE;
    $xml .= '<tcexamresults version="' . K_TCEXAM_VERSION . '">' . K_NEWLINE;
    $xml .= K_TAB . '<header';
    $xml .= ' lang="' . K_USER_LANG . '"';
    $xml .= ' date="' . date(K_TIMESTAMP_FORMAT) . '">' . K_NEWLINE;
    $xml .= K_TAB . K_TAB . '<test_id>' . $test_id . '</test_id>' . K_NEWLINE;
    $xml .= K_TAB . K_TAB . '<group_id>' . $group_id . '</group_id>' . K_NEWLINE;
    $xml .= K_TAB . K_TAB . '<user_id>' . $user_id . '</user_id>' . K_NEWLINE;
    $xml .= K_TAB . K_TAB . '<startdate>' . $startdate . '</startdate>' . K_NEWLINE;
    $xml .= K_TAB . K_TAB . '<enddate>' . $enddate . '</enddate>' . K_NEWLINE;
    $xml .= K_TAB . '</header>' . K_NEWLINE;
    $xml .= K_TAB . '<body>' . K_NEWLINE;
    $data = F_getAllUsersTestStat($test_id, $group_id, $user_id, $startdate, $enddate, 'total_score', false, $display_mode);
    $xml .= getDataXML($data);
    $xml .= K_TAB . '</body>' . K_NEWLINE;
    $xml .= '</tcexamresults>' . K_NEWLINE;
    return $xml;
}