1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: 24: 25: 26: 27: 28: 29:
30:
31: 32:
33:
34: if ((isset($_REQUEST['expmode']) and ($_REQUEST['expmode'] > 0))
35: and (isset($_REQUEST['module_id']) and ($_REQUEST['module_id'] > 0))
36: and (isset($_REQUEST['subject_id']) and ($_REQUEST['subject_id'] > 0))) {
37: $expmode = intval($_REQUEST['expmode']);
38: $module_id = intval($_REQUEST['module_id']);
39: $subject_id = intval($_REQUEST['subject_id']);
40:
41:
42: switch ($expmode) {
43: case 1: {
44: $tsv_filename = 'tcexam_subject_'.$subject_id.'_'.date('YmdHi').'.tsv';
45: break;
46: }
47: case 2: {
48: $tsv_filename = 'tcexam_module_'.$module_id.'_'.date('YmdHi').'.tsv';
49: break;
50: }
51: case 3: {
52: $tsv_filename = 'tcexam_all_modules_'.date('YmdHi').'.tsv';
53: break;
54: }
55: default: {
56: $tsv_filename = 'tcexam_export_'.date('YmdHi').'.tsv';
57: break;
58: }
59: }
60:
61:
62: header('Content-Description: TSV File Transfer');
63: header('Cache-Control: public, must-revalidate, max-age=0');
64: header('Pragma: public');
65: header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
66: header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
67:
68: header('Content-Type: application/force-download');
69: header('Content-Type: application/octet-stream', false);
70: header('Content-Type: application/download', false);
71: header('Content-Type: text/tab-separated-values', false);
72:
73: header('Content-Disposition: attachment; filename='.$tsv_filename.';');
74: header('Content-Transfer-Encoding: binary');
75:
76: echo F_tsv_export_questions($module_id, $subject_id, $expmode);
77: } else {
78: exit;
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: function F_tsv_export_questions($module_id, $subject_id, $expmode)
89: {
90: global $l, $db;
91: require_once('../config/tce_config.php');
92: require_once('../../shared/code/tce_authorization.php');
93: require_once('../../shared/code/tce_functions_auth_sql.php');
94: $module_id = intval($module_id);
95: $subject_id = intval($subject_id);
96: $expmode = intval($expmode);
97: $qtype = array('S', 'M', 'T', 'O');
98: $tsv = '';
99:
100:
101:
102: $tsv .= 'M=MODULE';
103: $tsv .= K_TAB.'module_enabled';
104: $tsv .= K_TAB.'module_name';
105: $tsv .= K_NEWLINE;
106:
107: $tsv .= 'S=SUBJECT';
108: $tsv .= K_TAB.'subject_enabled';
109: $tsv .= K_TAB.'subject_name';
110: $tsv .= K_TAB.'subject_description';
111: $tsv .= K_NEWLINE;
112:
113: $tsv .= 'Q=QUESTION';
114: $tsv .= K_TAB.'question_enabled';
115: $tsv .= K_TAB.'question_description';
116: $tsv .= K_TAB.'question_explanation';
117: $tsv .= K_TAB.'question_type';
118: $tsv .= K_TAB.'question_difficulty';
119: $tsv .= K_TAB.'question_position';
120: $tsv .= K_TAB.'question_timer';
121: $tsv .= K_TAB.'question_fullscreen';
122: $tsv .= K_TAB.'question_inline_answers';
123: $tsv .= K_TAB.'question_auto_next';
124: $tsv .= K_NEWLINE;
125:
126: $tsv .= 'A=ANSWER';
127: $tsv .= K_TAB.'answer_enabled';
128: $tsv .= K_TAB.'answer_description';
129: $tsv .= K_TAB.'answer_explanation';
130: $tsv .= K_TAB.'answer_isright';
131: $tsv .= K_TAB.'answer_position';
132: $tsv .= K_TAB.'answer_keyboard_key';
133: $tsv .= K_NEWLINE;
134:
135: $tsv .= K_NEWLINE;
136:
137:
138: $andmodwhere = '';
139: if ($expmode < 3) {
140: $andmodwhere = 'module_id='.$module_id.'';
141: }
142: $sqlm = F_select_modules_sql($andmodwhere);
143: if ($rm = F_db_query($sqlm, $db)) {
144: while ($mm = F_db_fetch_array($rm)) {
145: $tsv .= 'M';
146: $tsv .= K_TAB.intval(F_getBoolean($mm['module_enabled']));
147: $tsv .= K_TAB.F_text_to_tsv($mm['module_name']);
148: $tsv .= K_NEWLINE;
149:
150: $where_sqls = 'subject_module_id='.$mm['module_id'].'';
151: if ($expmode < 2) {
152: $where_sqls .= ' AND subject_id='.$subject_id.'';
153: }
154: $sqls = F_select_subjects_sql($where_sqls);
155: if ($rs = F_db_query($sqls, $db)) {
156: while ($ms = F_db_fetch_array($rs)) {
157: $tsv .= 'S';
158: $tsv .= K_TAB.intval(F_getBoolean($ms['subject_enabled']));
159: $tsv .= K_TAB.F_text_to_tsv($ms['subject_name']);
160: $tsv .= K_TAB.F_text_to_tsv($ms['subject_description']);
161: $tsv .= K_NEWLINE;
162:
163: $sql = 'SELECT *
164: FROM '.K_TABLE_QUESTIONS.'
165: WHERE question_subject_id='.$ms['subject_id'].'
166: ORDER BY question_enabled DESC, question_position, question_description';
167: if ($r = F_db_query($sql, $db)) {
168: while ($m = F_db_fetch_array($r)) {
169: $tsv .= 'Q';
170: $tsv .= K_TAB.intval(F_getBoolean($m['question_enabled']));
171: $tsv .= K_TAB.F_text_to_tsv($m['question_description']);
172: $tsv .= K_TAB.F_text_to_tsv($m['question_explanation']);
173: $tsv .= K_TAB.$qtype[$m['question_type']-1];
174: $tsv .= K_TAB.$m['question_difficulty'];
175: $tsv .= K_TAB.$m['question_position'];
176: $tsv .= K_TAB.$m['question_timer'];
177: $tsv .= K_TAB.intval(F_getBoolean($m['question_fullscreen']));
178: $tsv .= K_TAB.intval(F_getBoolean($m['question_inline_answers']));
179: $tsv .= K_TAB.intval(F_getBoolean($m['question_auto_next']));
180: $tsv .= K_NEWLINE;
181:
182: $sqla = 'SELECT *
183: FROM '.K_TABLE_ANSWERS.'
184: WHERE answer_question_id=\''.$m['question_id'].'\'
185: ORDER BY answer_position,answer_isright DESC';
186: if ($ra = F_db_query($sqla, $db)) {
187: while ($ma = F_db_fetch_array($ra)) {
188: $tsv .= 'A';
189: $tsv .= K_TAB.intval(F_getBoolean($ma['answer_enabled']));
190: $tsv .= K_TAB.F_text_to_tsv($ma['answer_description']);
191: $tsv .= K_TAB.F_text_to_tsv($ma['answer_explanation']);
192: $tsv .= K_TAB.intval(F_getBoolean($ma['answer_isright']));
193: $tsv .= K_TAB.$ma['answer_position'];
194: $tsv .= K_TAB.$ma['answer_keyboard_key'];
195: $tsv .= K_NEWLINE;
196: }
197: } else {
198: F_display_db_error();
199: }
200: }
201: } else {
202: F_display_db_error();
203: }
204: }
205: } else {
206: F_display_db_error();
207: }
208: }
209: } else {
210: F_display_db_error();
211: }
212: return $tsv;
213: }
214:
215:
216:
217:
218: