source-function-F_xml_export_questions

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_questions.php
  4: // Begin       : 2006-03-06
  5: // Last Update : 2013-09-05
  6: //
  7: // Description : Functions to export questions using 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-2013  Nicola Asuni - Tecnick.com LTD
 19: //    See LICENSE.TXT file for more information.
 20: //============================================================+
 21: 
 22: /**
 23:  * @file
 24:  * Display all questions grouped by topic in XML or JSON format.
 25:  * @package com.tecnick.tcexam.admin
 26:  * @author Nicola Asuni
 27:  * @since 2006-03-11
 28:  */
 29: 
 30: /**
 31:  */
 32: 
 33: if ((isset($_REQUEST['expmode']) and ($_REQUEST['expmode'] > 0))
 34:     and (isset($_REQUEST['module_id']) and ($_REQUEST['module_id'] > 0))
 35:     and (isset($_REQUEST['subject_id']) and ($_REQUEST['subject_id'] > 0))) {
 36:     $expmode = intval($_REQUEST['expmode']);
 37:     $module_id = intval($_REQUEST['module_id']);
 38:     $subject_id = intval($_REQUEST['subject_id']);
 39:     $output_format = isset($_REQUEST['format']) ? strtoupper($_REQUEST['format']) : 'XML';
 40: 
 41:     // set XML file name
 42:     switch ($expmode) {
 43:         case 1: {
 44:             $out_filename = 'tcexam_subject_'.$subject_id;
 45:             break;
 46:         }
 47:         case 2: {
 48:             $out_filename = 'tcexam_module_'.$module_id;
 49:             break;
 50:         }
 51:         case 3: {
 52:             $out_filename = 'tcexam_all_modules';
 53:             break;
 54:         }
 55:         default: {
 56:             $out_filename = 'tcexam_export';
 57:             break;
 58:         }
 59:     }
 60:     $out_filename .= '_'.date('YmdHi');
 61: 
 62:     // get the XML code
 63:     $xml = F_xml_export_questions($module_id, $subject_id, $expmode);
 64: 
 65:     switch ($output_format) {
 66:         case 'JSON': {
 67:             header('Content-Description: JSON File Transfer');
 68:             header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 69:             header('Pragma: public');
 70:             header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
 71:             header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 72:             // force download dialog
 73:             header('Content-Type: application/force-download');
 74:             header('Content-Type: application/octet-stream', false);
 75:             header('Content-Type: application/download', false);
 76:             header('Content-Type: application/json', false);
 77:             // use the Content-Disposition header to supply a recommended filename
 78:             header('Content-Disposition: attachment; filename='.$out_filename.'.json;');
 79:             header('Content-Transfer-Encoding: binary');
 80:             $xmlobj = new SimpleXMLElement($xml);
 81:             echo json_encode($xmlobj);
 82:             break;
 83:         }
 84:         case 'XML':
 85:         default: {
 86:             header('Content-Description: XML File Transfer');
 87:             header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 88:             header('Pragma: public');
 89:             header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
 90:             header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 91:             // force download dialog
 92:             header('Content-Type: application/force-download');
 93:             header('Content-Type: application/octet-stream', false);
 94:             header('Content-Type: application/download', false);
 95:             header('Content-Type: application/xml', false);
 96:             // use the Content-Disposition header to supply a recommended filename
 97:             header('Content-Disposition: attachment; filename='.$out_filename.'.xml;');
 98:             header('Content-Transfer-Encoding: binary');
 99:             echo $xml;
100:             break;
101:         }
102:     }
103: } else {
104:     exit;
105: }
106: 
107: /**
108:  * Export all questions of the selected subject to XML.
109:  * @author Nicola Asuni
110:  * @since 2006-03-06
111:  * @param $module_id (int)  module ID
112:  * @param $subject_id (int) topic ID
113:  * @param $expmode (int) export mode: 1 = selected topic; 2 = selected module; 3 = all modules.
114:  * @return XML data
115:  */
116: function F_xml_export_questions($module_id, $subject_id, $expmode)
117: {
118:     global $l, $db;
119:     require_once('../config/tce_config.php');
120:     require_once('../../shared/code/tce_authorization.php');
121:     require_once('../../shared/code/tce_functions_auth_sql.php');
122:     $module_id = intval($module_id);
123:     $subject_id = intval($subject_id);
124:     $expmode = intval($expmode);
125: 
126:     $boolean = array('false', 'true');
127:     $type = array('single', 'multiple', 'text', 'ordering');
128: 
129:     $xml = ''; // XML data to be returned
130: 
131:     $xml .= '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'.K_NEWLINE;
132:     $xml .= '<tcexamquestions version="'.K_TCEXAM_VERSION.'">'.K_NEWLINE;
133:     $xml .=  K_TAB.'<header';
134:     $xml .= ' lang="'.K_USER_LANG.'"';
135:     $xml .= ' date="'.date(K_TIMESTAMP_FORMAT).'">'.K_NEWLINE;
136:     $xml .= K_TAB.'</header>'.K_NEWLINE;
137:     $xml .=  K_TAB.'<body>'.K_NEWLINE;
138: 
139:     // ---- module
140:     $andmodwhere = '';
141:     if ($expmode < 3) {
142:         $andmodwhere = 'module_id='.$module_id.'';
143:     }
144:     $sqlm = F_select_modules_sql($andmodwhere);
145:     if ($rm = F_db_query($sqlm, $db)) {
146:         while ($mm = F_db_fetch_array($rm)) {
147:             $xml .= K_TAB.K_TAB.'<module>'.K_NEWLINE;
148: 
149:             $xml .= K_TAB.K_TAB.K_TAB.'<name>';
150:             $xml .= F_text_to_xml($mm['module_name']);
151:             $xml .= '</name>'.K_NEWLINE;
152: 
153:             $xml .= K_TAB.K_TAB.K_TAB.'<enabled>';
154:             $xml .= $boolean[intval(F_getBoolean($mm['module_enabled']))];
155:             $xml .= '</enabled>'.K_NEWLINE;
156: 
157:             // ---- topic
158:             $where_sqls = 'subject_module_id='.$mm['module_id'].'';
159:             if ($expmode < 2) {
160:                 $where_sqls .= ' AND subject_id='.$subject_id.'';
161:             }
162:             $sqls = F_select_subjects_sql($where_sqls);
163:             if ($rs = F_db_query($sqls, $db)) {
164:                 while ($ms = F_db_fetch_array($rs)) {
165:                     $xml .= K_TAB.K_TAB.K_TAB.'<subject>'.K_NEWLINE;
166: 
167:                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<name>';
168:                     $xml .= F_text_to_xml($ms['subject_name']);
169:                     $xml .= '</name>'.K_NEWLINE;
170: 
171:                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<description>';
172:                     $xml .= F_text_to_xml($ms['subject_description']);
173:                     $xml .= '</description>'.K_NEWLINE;
174: 
175:                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<enabled>';
176:                     $xml .= $boolean[intval(F_getBoolean($ms['subject_enabled']))];
177:                     $xml .= '</enabled>'.K_NEWLINE;
178: 
179:                     // ---- questions
180:                     $sql = 'SELECT *
181:                         FROM '.K_TABLE_QUESTIONS.'
182:                         WHERE question_subject_id='.$ms['subject_id'].'
183:                         ORDER BY question_enabled DESC, question_position, question_description';
184:                     if ($r = F_db_query($sql, $db)) {
185:                         while ($m = F_db_fetch_array($r)) {
186:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<question>'.K_NEWLINE;
187: 
188:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<enabled>';
189:                             $xml .= $boolean[intval(F_getBoolean($m['question_enabled']))];
190:                             $xml .= '</enabled>'.K_NEWLINE;
191: 
192:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<type>';
193:                             $xml .= $type[$m['question_type']-1];
194:                             $xml .= '</type>'.K_NEWLINE;
195: 
196:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<difficulty>';
197:                             $xml .= $m['question_difficulty'];
198:                             $xml .= '</difficulty>'.K_NEWLINE;
199: 
200:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<position>';
201:                             $xml .= $m['question_position'];
202:                             $xml .= '</position>'.K_NEWLINE;
203: 
204:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<timer>';
205:                             $xml .= $m['question_timer'];
206:                             $xml .= '</timer>'.K_NEWLINE;
207: 
208:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<fullscreen>';
209:                             $xml .= $boolean[intval(F_getBoolean($m['question_fullscreen']))];
210:                             $xml .= '</fullscreen>'.K_NEWLINE;
211: 
212:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<inline_answers>';
213:                             $xml .= $boolean[intval(F_getBoolean($m['question_inline_answers']))];
214:                             $xml .= '</inline_answers>'.K_NEWLINE;
215: 
216:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<auto_next>';
217:                             $xml .= $boolean[intval(F_getBoolean($m['question_auto_next']))];
218:                             $xml .= '</auto_next>'.K_NEWLINE;
219: 
220:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<description>';
221:                             $xml .= F_text_to_xml($m['question_description']);
222:                             $xml .= '</description>'.K_NEWLINE;
223: 
224:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<explanation>';
225:                             $xml .= F_text_to_xml($m['question_explanation']);
226:                             $xml .= '</explanation>'.K_NEWLINE;
227: 
228:                             // display alternative answers
229:                             $sqla = 'SELECT *
230:                                 FROM '.K_TABLE_ANSWERS.'
231:                                 WHERE answer_question_id=\''.$m['question_id'].'\'
232:                                 ORDER BY answer_position,answer_isright DESC';
233:                             if ($ra = F_db_query($sqla, $db)) {
234:                                 while ($ma = F_db_fetch_array($ra)) {
235:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<answer>'.K_NEWLINE;
236: 
237:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<enabled>';
238:                                     $xml .= $boolean[intval(F_getBoolean($ma['answer_enabled']))];
239:                                     $xml .= '</enabled>'.K_NEWLINE;
240: 
241:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<isright>';
242:                                     $xml .= $boolean[intval(F_getBoolean($ma['answer_isright']))];
243:                                     $xml .= '</isright>'.K_NEWLINE;
244: 
245:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<position>';
246:                                     $xml .= $ma['answer_position'];
247:                                     $xml .= '</position>'.K_NEWLINE;
248: 
249:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<keyboard_key>';
250:                                     $xml .= $ma['answer_keyboard_key'];
251:                                     $xml .= '</keyboard_key>'.K_NEWLINE;
252: 
253:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<description>';
254:                                     $xml .= F_text_to_xml($ma['answer_description']);
255:                                     $xml .= '</description>'.K_NEWLINE;
256: 
257:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'<explanation>';
258:                                     $xml .= F_text_to_xml($ma['answer_explanation']);
259:                                     $xml .= '</explanation>'.K_NEWLINE;
260: 
261:                                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.K_TAB.'</answer>'.K_NEWLINE;
262:                                 }
263:                             } else {
264:                                 F_display_db_error();
265:                             }
266: 
267:                             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'</question>'.K_NEWLINE;
268:                         } // end while for questions
269:                     } else {
270:                         F_display_db_error();
271:                     }
272: 
273:                     $xml .= K_TAB.K_TAB.K_TAB.'</subject>'.K_NEWLINE;
274:                 } // end while for topics
275:             } else {
276:                 F_display_db_error();
277:             }
278: 
279:             $xml .= K_TAB.K_TAB.'</module>'.K_NEWLINE;
280:         } // end while for module
281:     } else {
282:         F_display_db_error();
283:     }
284: 
285:     $xml .= K_TAB.'</body>'.K_NEWLINE;
286:     $xml .= '</tcexamquestions>'.K_NEWLINE;
287: 
288:     return $xml;
289: }
290: 
291: //============================================================+
292: // END OF FILE
293: //============================================================+
294: 
 

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