source-function-F_xml_export_results

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

  1: <?php
  2: //============================================================+
  3: // File name   : tce_xml_results.php
  4: // Begin       : 2008-06-06
  5: // Last Update : 2014-01-27
  6: //
  7: // Description : Export all users' results in XML or JSON format.
  8: //
  9: // Author: Nicola Asuni
 10: //
 11: // (c) Copyright:
 12: //               Nicola Asuni
 13: //               Tecnick.com LTD
 14: //               www.tecnick.com
 15: //               info@tecnick.com
 16: //
 17: // License:
 18: //    Copyright (C) 2004-2014  Nicola Asuni - Tecnick.com LTD
 19: //    See LICENSE.TXT file for more information.
 20: //============================================================+
 21: 
 22: /**
 23:  * @file
 24:  * Export all users' results in XML or JSON format.
 25:  * @package com.tecnick.tcexam.admin
 26:  * @author Nicola Asuni
 27:  * @since 2004-06-11
 28:  */
 29: 
 30: /**
 31:  */
 32: 
 33: require_once('../config/tce_config.php');
 34: $pagelevel = K_AUTH_ADMIN_RESULTS;
 35: require_once('../../shared/code/tce_authorization.php');
 36: require_once('../../shared/code/tce_functions_test_stats.php');
 37: 
 38: if (isset($_REQUEST['test_id']) and ($_REQUEST['test_id'] > 0)) {
 39:     $test_id = intval($_REQUEST['test_id']);
 40:     if (!F_isAuthorizedUser(K_TABLE_TESTS, 'test_id', $test_id, 'test_user_id')) {
 41:         exit;
 42:     }
 43: } else {
 44:     $test_id = 0;
 45: }
 46: if (isset($_REQUEST['group_id']) and ($_REQUEST['group_id'] > 0)) {
 47:     $group_id = intval($_REQUEST['group_id']);
 48: } else {
 49:     $group_id = 0;
 50: }
 51: if (isset($_REQUEST['user_id'])) {
 52:     $user_id = intval($_REQUEST['user_id']);
 53: } else {
 54:     $user_id = 0;
 55: }
 56: if (isset($_REQUEST['startdate'])) {
 57:     $startdate = $_REQUEST['startdate'];
 58:     $startdate_time = strtotime($startdate);
 59:     $startdate = date(K_TIMESTAMP_FORMAT, $startdate_time);
 60: } else {
 61:     $startdate = 0;
 62: }
 63: if (isset($_REQUEST['enddate'])) {
 64:     $enddate = $_REQUEST['enddate'];
 65:     $enddate_time = strtotime($enddate);
 66:     $enddate = date(K_TIMESTAMP_FORMAT, $enddate_time);
 67: } else {
 68:     $enddate = 0;
 69: }
 70: if (isset($_REQUEST['display_mode'])) {
 71:     $display_mode = max(0, min(5, intval($_REQUEST['display_mode'])));
 72: } else {
 73:     $display_mode = 0;
 74: }
 75: 
 76: $output_format = isset($_REQUEST['format']) ? strtoupper($_REQUEST['format']) : 'XML';
 77: $out_filename = 'tcexam_results_'.date('YmdHis').'_test_'.$test_id;
 78: $xml = F_xml_export_results($test_id, $group_id, $user_id, $startdate, $enddate, $display_mode);
 79: 
 80: switch ($output_format) {
 81:     case 'JSON': {
 82:         header('Content-Description: JSON File Transfer');
 83:         header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 84:         header('Pragma: public');
 85:         header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
 86:         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 87:         // force download dialog
 88:         header('Content-Type: application/force-download');
 89:         header('Content-Type: application/octet-stream', false);
 90:         header('Content-Type: application/download', false);
 91:         header('Content-Type: application/json', false);
 92:         // use the Content-Disposition header to supply a recommended filename
 93:         header('Content-Disposition: attachment; filename='.$out_filename.'.json;');
 94:         header('Content-Transfer-Encoding: binary');
 95:         $xmlobj = new SimpleXMLElement($xml);
 96:         echo json_encode($xmlobj);
 97:         break;
 98:     }
 99:     case 'XML':
100:     default: {
101:         header('Content-Description: XML File Transfer');
102:         header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
103:         header('Pragma: public');
104:         header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
105:         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
106:         // force download dialog
107:         header('Content-Type: application/force-download');
108:         header('Content-Type: application/octet-stream', false);
109:         header('Content-Type: application/download', false);
110:         header('Content-Type: application/xml', false);
111:         // use the Content-Disposition header to supply a recommended filename
112:         header('Content-Disposition: attachment; filename='.$out_filename.'.xml;');
113:         header('Content-Transfer-Encoding: binary');
114:         echo $xml;
115:         break;
116:     }
117: }
118: 
119: /**
120:  * Export results in XML format.
121:  * @param $test_id (int) test ID.
122:  * @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group.
123:  * @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
124:  * @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
125:  * @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
126:  * @param $display_mode (int) display mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
127:  * @author Nicola Asuni
128:  * @return XML data
129:  */
130: function F_xml_export_results($test_id, $group_id = 0, $user_id = 0, $startdate = 0, $enddate = 0, $display_mode = 1)
131: {
132:     global $l, $db;
133:     require_once('../config/tce_config.php');
134:     
135:     $xml = ''; // XML data to be returned
136: 
137:     $xml .= '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'.K_NEWLINE;
138:     $xml .= '<tcexamresults version="'.K_TCEXAM_VERSION.'">'.K_NEWLINE;
139:     $xml .=  K_TAB.'<header';
140:     $xml .= ' lang="'.K_USER_LANG.'"';
141:     $xml .= ' date="'.date(K_TIMESTAMP_FORMAT).'">'.K_NEWLINE;
142:     $xml .= K_TAB.K_TAB.'<test_id>'.$test_id.'</test_id>'.K_NEWLINE;
143:     $xml .= K_TAB.K_TAB.'<group_id>'.$group_id.'</group_id>'.K_NEWLINE;
144:     $xml .= K_TAB.K_TAB.'<user_id>'.$user_id.'</user_id>'.K_NEWLINE;
145:     $xml .= K_TAB.K_TAB.'<startdate>'.$startdate.'</startdate>'.K_NEWLINE;
146:     $xml .= K_TAB.K_TAB.'<enddate>'.$enddate.'</enddate>'.K_NEWLINE;
147:     $xml .= K_TAB.'</header>'.K_NEWLINE;
148:     $xml .= K_TAB.'<body>'.K_NEWLINE;
149: 
150:     $data = F_getAllUsersTestStat($test_id, $group_id, $user_id, $startdate, $enddate, 'total_score', false, $display_mode);
151:     $xml .= getDataXML($data);
152: 
153:     $xml .= K_TAB.'</body>'.K_NEWLINE;
154:     $xml .= '</tcexamresults>'.K_NEWLINE;
155:     
156:     return $xml;
157: }
158: 
159: //============================================================+
160: // END OF FILE
161: //============================================================+
162: 
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy