source-function-F_tsv_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_tsv_questions.php
  4: // Begin       : 2006-03-06
  5: // Last Update : 2013-09-05
  6: //
  7: // Description : Functions to export questions using CVS format.
  8: //               (tab-separated values)
  9: //
 10: // Author: Nicola Asuni
 11: //
 12: // (c) Copyright:
 13: //               Nicola Asuni
 14: //               Tecnick.com LTD
 15: //               www.tecnick.com
 16: //               info@tecnick.com
 17: //
 18: // License:
 19: //    Copyright (C) 2004-2013  Nicola Asuni - Tecnick.com LTD
 20: //    See LICENSE.TXT file for more information.
 21: //============================================================+
 22: 
 23: /**
 24:  * @file
 25:  * Display all questions grouped by topic in TSV format.
 26:  * @package com.tecnick.tcexam.admin
 27:  * @author Nicola Asuni
 28:  * @since 2012-12-31
 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:     // set TSV file name
 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:     // send TSV headers
 62:     header('Content-Description: TSV File Transfer');
 63:     header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 64:     header('Pragma: public');
 65:     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
 66:     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 67:     // force download dialog
 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:     // use the Content-Disposition header to supply a recommended filename
 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:  * Export all questions of the selected subject to TSV.
 83:  * @param $module_id (int)  module ID
 84:  * @param $subject_id (int) topic ID
 85:  * @param $expmode (int) export mode: 1 = selected topic; 2 = selected module; 3 = all modules.
 86:  * @return TSV data
 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 = ''; // TSV data to be returned
 99:     
100:     // headers
101:     
102:     $tsv .= 'M=MODULE'; // MODULE
103:     $tsv .= K_TAB.'module_enabled';
104:     $tsv .= K_TAB.'module_name';
105:     $tsv .= K_NEWLINE;
106: 
107:     $tsv .= 'S=SUBJECT'; // 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'; // 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'; // 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:     // ---- module
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'; // MODULE
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:             // ---- topic
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'; // SUBJECT
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:                     // ---- questions
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'; // QUESTION
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:                             // display alternative answers
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'; // ANSWER
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:                         } // end while for questions
201:                     } else {
202:                         F_display_db_error();
203:                     }
204:                 } // end while for topics
205:             } else {
206:                 F_display_db_error();
207:             }
208:         } // end while for module
209:     } else {
210:         F_display_db_error();
211:     }
212:     return $tsv;
213: }
214: 
215: //============================================================+
216: // END OF FILE
217: //============================================================+
218: 
 

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