source-function-F_show_select_test_popup

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_functions_test_select.php
  4: // Begin       : 2012-12-02
  5: // Last Update : 2014-03-04
  6: //
  7: // Description : Functions to display and select tests.
  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:  * Functions to display and select tests.
 25:  * @package com.tecnick.tcexam.admin
 26:  * @author Nicola Asuni
 27:  * @since 2012-12-02
 28:  */
 29: 
 30: /**
 31:  * Display test selection for using F_show_select_test function.
 32:  * @author Nicola Asuni
 33:  * @param $order_field (string) order by column name
 34:  * @param $orderdir (string) oreder direction
 35:  * @param $firstrow (string) number of first row to display
 36:  * @param $rowsperpage (string) number of rows per page
 37:  * @param $andwhere (string) additional SQL WHERE query conditions
 38:  * @param $searchterms (string) search terms
 39:  * @return true
 40:  */
 41: function F_select_test($order_field, $orderdir, $firstrow, $rowsperpage, $andwhere = '', $searchterms = '')
 42: {
 43:     global $l;
 44:     require_once('../config/tce_config.php');
 45:     F_show_select_test($order_field, $orderdir, $firstrow, $rowsperpage, $andwhere, $searchterms);
 46:     return true;
 47: }
 48: 
 49: /**
 50:  * Display test selection XHTML table.
 51:  * @author Nicola Asuni
 52:  * @param $order_field (string) Order by column name.
 53:  * @param $orderdir (int) Order direction.
 54:  * @param $firstrow (int) Number of first row to display.
 55:  * @param $rowsperpage (int) Number of rows per page.
 56:  * @param $andwhere (string) Additional SQL WHERE query conditions.
 57:  * @param $searchterms (string) Search terms.
 58:  * @return false in case of empty database, true otherwise
 59:  */
 60: function F_show_select_test($order_field, $orderdir, $firstrow, $rowsperpage, $andwhere = '', $searchterms = '')
 61: {
 62:     global $l, $db;
 63:     require_once('../config/tce_config.php');
 64:     require_once('../../shared/code/tce_functions_page.php');
 65:     require_once('../../shared/code/tce_functions_form.php');
 66:     $filter = '';
 67:     if ($l['a_meta_dir'] == 'rtl') {
 68:         $txtalign = 'right';
 69:         $numalign = 'left';
 70:     } else {
 71:         $txtalign = 'left';
 72:         $numalign = 'right';
 73:     }
 74:     $order_field = F_escape_sql($db, $order_field);
 75:     $orderdir = intval($orderdir);
 76:     $firstrow = intval($firstrow);
 77:     $rowsperpage = intval($rowsperpage);
 78:     if (empty($order_field) or (!in_array($order_field, array('test_name', 'test_description', 'test_begin_time', 'test_end_time', 'test_duration_time', 'test_ip_range', 'test_results_to_users', 'test_report_to_users', 'test_score_right', 'test_score_wrong', 'test_score_unanswered', 'test_max_score', 'test_user_id', 'test_score_threshold', 'test_random_questions_select', 'test_random_questions_order', 'test_questions_order_mode', 'test_random_answers_select', 'test_random_answers_order', 'test_answers_order_mode', 'test_comment_enabled', 'test_menu_enabled', 'test_noanswer_enabled', 'test_mcma_radio', 'test_repeatable', 'test_mcma_partial_score', 'test_logout_on_timeout')))) {
 79:         $order_field = 'test_begin_time DESC,test_name';
 80:     }
 81:     if ($orderdir == 0) {
 82:         $nextorderdir=1;
 83:         $full_order_field = $order_field;
 84:     } else {
 85:         $nextorderdir=0;
 86:         $full_order_field = $order_field.' DESC';
 87:     }
 88:     if (!F_count_rows(K_TABLE_TESTS)) { // if the table is void (no items) display message
 89:         F_print_error('MESSAGE', $l['m_databasempty']);
 90:         return false;
 91:     }
 92:     $wherequery = '';
 93:     if (empty($wherequery)) {
 94:         $wherequery = ' WHERE';
 95:     } else {
 96:         $wherequery .= ' AND';
 97:     }
 98:     $wherequery .= ' (test_id>0)';
 99:     if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
100:         $wherequery .= ' AND test_user_id IN ('.F_getAuthorizedUsers($_SESSION['session_user_id']).')';
101:     }
102:     if (!empty($andwhere)) {
103:         $wherequery .= ' AND ('.$andwhere.')';
104:     }
105:     $sql = 'SELECT * FROM '.K_TABLE_TESTS.$wherequery.' ORDER BY '.$full_order_field;
106:     if (K_DATABASE_TYPE == 'ORACLE') {
107:         $sql = 'SELECT * FROM ('.$sql.') WHERE rownum BETWEEN '.$firstrow.' AND '.($firstrow + $rowsperpage).'';
108:     } else {
109:         $sql .= ' LIMIT '.$rowsperpage.' OFFSET '.$firstrow.'';
110:     }
111:     if ($r = F_db_query($sql, $db)) {
112:         if ($m = F_db_fetch_array($r)) {
113:             // -- Table structure with links:
114:             echo '<div class="container">';
115:             echo '<table class="userselect">'.K_NEWLINE;
116:             // table header
117:             echo '<tr>'.K_NEWLINE;
118:             echo '<th>&nbsp;</th>'.K_NEWLINE;
119:             if (strlen($searchterms) > 0) {
120:                 $filter .= '&amp;searchterms='.urlencode($searchterms);
121:             }
122:             echo F_select_table_header_element('test_begin_time', $nextorderdir, $l['w_time_begin'].' '.$l['w_datetime_format'], $l['w_time_begin'], $order_field, $filter);
123:             echo F_select_table_header_element('test_end_time', $nextorderdir, $l['w_time_end'].' '.$l['w_datetime_format'], $l['w_time_end'], $order_field, $filter);
124:             echo F_select_table_header_element('test_name', $nextorderdir, $l['h_test_name'], $l['w_name'], $order_field, $filter);
125:             echo F_select_table_header_element('test_description', $nextorderdir, $l['h_test_description'], $l['w_description'], $order_field, $filter);
126:             echo '</tr>'.K_NEWLINE;
127:             $itemcount = 0;
128:             do {
129:                 $itemcount++;
130:                 echo '<tr>'.K_NEWLINE;
131:                 echo '<td>';
132:                 echo '<input type="checkbox" name="testid'.$itemcount.'" id="testid'.$itemcount.'" value="'.$m['test_id'].'" title="'.$l['w_select'].'"';
133:                 if (isset($_REQUEST['checkall']) and ($_REQUEST['checkall'] == 1)) {
134:                     echo ' checked="checked"';
135:                 }
136:                 echo ' />';
137:                 echo '</td>'.K_NEWLINE;
138:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_begin_time'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
139:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_end_time'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
140:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;<a href="tce_edit_test.php?test_id='.$m['test_id'].'" title="'.$l['w_edit'].'">'.htmlspecialchars($m['test_name'], ENT_NOQUOTES, $l['a_meta_charset']).'</a></td>'.K_NEWLINE;
141:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_description'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
142:                 echo '</tr>'.K_NEWLINE;
143:             } while ($m = F_db_fetch_array($r));
144: 
145:             echo '</table>'.K_NEWLINE;
146: 
147:             echo '<br />'.K_NEWLINE;
148: 
149:             echo '<input type="hidden" name="order_field" id="order_field" value="'.$order_field.'" />'.K_NEWLINE;
150:             echo '<input type="hidden" name="orderdir" id="orderdir" value="'.$orderdir.'" />'.K_NEWLINE;
151:             echo '<input type="hidden" name="firstrow" id="firstrow" value="'.$firstrow.'" />'.K_NEWLINE;
152:             echo '<input type="hidden" name="rowsperpage" id="rowsperpage" value="'.$rowsperpage.'" />'.K_NEWLINE;
153: 
154:             // check/uncheck all options
155:             echo '<span dir="'.$l['a_meta_dir'].'">';
156:             echo '<input type="radio" name="checkall" id="checkall1" value="1" onclick="document.getElementById(\'form_testselect\').submit()" />';
157:             echo '<label for="checkall1">'.$l['w_check_all'].'</label> ';
158:             echo '<input type="radio" name="checkall" id="checkall0" value="0" onclick="document.getElementById(\'form_testselect\').submit()" />';
159:             echo '<label for="checkall0">'.$l['w_uncheck_all'].'</label>';
160:             echo '</span>'.K_NEWLINE;
161:             echo '<br />'.K_NEWLINE;
162:             echo '<strong style="margin:5px">'.$l['m_with_selected'].'</strong>'.K_NEWLINE;
163:             // delete user
164:             echo '<div>';
165:             F_submit_button('delete', $l['w_delete'], $l['h_delete']);
166:             F_submit_button('lock', $l['w_lock'], $l['w_lock']);
167:             F_submit_button('unlock', $l['w_unlock'], $l['w_unlock']);
168:             echo '</div>'.K_NEWLINE;
169:             echo '<div class="row"><hr /></div>'.K_NEWLINE;
170: 
171:             // ---------------------------------------------------------------
172:             // -- page jumper (menu for successive pages)
173:             if ($rowsperpage > 0) {
174:                 $sql = 'SELECT count(*) AS total FROM '.K_TABLE_TESTS.''.$wherequery.'';
175:                 if (!empty($order_field)) {
176:                     $param_array = '&amp;order_field='.urlencode($order_field).'';
177:                 }
178:                 if (!empty($orderdir)) {
179:                     $param_array .= '&amp;orderdir='.$orderdir.'';
180:                 }
181:                 if (!empty($searchterms)) {
182:                     $param_array .= '&amp;searchterms='.urlencode($searchterms).'';
183:                 }
184:                 $param_array .= '&amp;submitted=1';
185:                 F_show_page_navigator($_SERVER['SCRIPT_NAME'], $sql, $firstrow, $rowsperpage, $param_array);
186:             }
187: 
188:             echo '<div class="row">'.K_NEWLINE;
189:             echo '</div>'.K_NEWLINE;
190: 
191:             echo '<div class="pagehelp">'.$l['hp_select_tests'].'</div>'.K_NEWLINE;
192:             echo '</div>'.K_NEWLINE;
193:         } else {
194:             F_print_error('MESSAGE', $l['m_search_void']);
195:         }
196:     } else {
197:         F_display_db_error();
198:     }
199:     return true;
200: }
201: 
202: /**
203:  * Display user selection XHTML table (popup mode).
204:  * @author Nicola Asuni
205:  * @since 2012-04-14
206:  * @param $order_field (string) Order by column name.
207:  * @param $orderdir (int) Order direction.
208:  * @param $firstrow (int) Number of first row to display.
209:  * @param $rowsperpage (int) Number of rows per page.
210:  * @param $andwhere (string) Additional SQL WHERE query conditions.
211:  * @param $searchterms (string) Search terms.
212:  * @param string $cid ID of the calling form field.
213:  * @return false in case of empty database, true otherwise
214:  */
215: function F_show_select_test_popup($order_field, $orderdir, $firstrow, $rowsperpage, $andwhere = '', $searchterms = '', $cid = 0)
216: {
217:     global $l, $db;
218:     require_once('../config/tce_config.php');
219:     require_once('../../shared/code/tce_functions_page.php');
220:     require_once('../../shared/code/tce_functions_form.php');
221:     $filter = 'cid='.$cid;
222:     if ($l['a_meta_dir'] == 'rtl') {
223:         $txtalign = 'right';
224:         $numalign = 'left';
225:     } else {
226:         $txtalign = 'left';
227:         $numalign = 'right';
228:     }
229:     $order_field = F_escape_sql($db, $order_field);
230:     $orderdir = intval($orderdir);
231:     $firstrow = intval($firstrow);
232:     $rowsperpage = intval($rowsperpage);
233:     if (empty($order_field) or (!in_array($order_field, array('test_name', 'test_description', 'test_begin_time', 'test_end_time', 'test_duration_time', 'test_ip_range', 'test_results_to_users', 'test_report_to_users', 'test_score_right', 'test_score_wrong', 'test_score_unanswered', 'test_max_score', 'test_user_id', 'test_score_threshold', 'test_random_questions_select', 'test_random_questions_order', 'test_questions_order_mode', 'test_random_answers_select', 'test_random_answers_order', 'test_answers_order_mode', 'test_comment_enabled', 'test_menu_enabled', 'test_noanswer_enabled', 'test_mcma_radio', 'test_repeatable', 'test_mcma_partial_score', 'test_logout_on_timeout')))) {
234:         $order_field = 'test_begin_time DESC,test_name';
235:     }
236:     if ($orderdir == 0) {
237:         $nextorderdir=1;
238:         $full_order_field = $order_field;
239:     } else {
240:         $nextorderdir=0;
241:         $full_order_field = $order_field.' DESC';
242:     }
243:     if (!F_count_rows(K_TABLE_TESTS)) { // if the table is void (no items) display message
244:         F_print_error('MESSAGE', $l['m_databasempty']);
245:         return false;
246:     }
247:     $wherequery = '';
248:     if (empty($wherequery)) {
249:         $wherequery = ' WHERE';
250:     } else {
251:         $wherequery .= ' AND';
252:     }
253:     $wherequery .= ' (test_id>0)';
254:     if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
255:         $wherequery .= ' AND test_user_id IN ('.F_getAuthorizedUsers($_SESSION['session_user_id']).')';
256:     }
257:     if (!empty($andwhere)) {
258:         $wherequery .= ' AND ('.$andwhere.')';
259:     }
260:     $sql = 'SELECT * FROM '.K_TABLE_TESTS.$wherequery.' ORDER BY '.$full_order_field;
261:     if (K_DATABASE_TYPE == 'ORACLE') {
262:         $sql = 'SELECT * FROM ('.$sql.') WHERE rownum BETWEEN '.$firstrow.' AND '.($firstrow + $rowsperpage).'';
263:     } else {
264:         $sql .= ' LIMIT '.$rowsperpage.' OFFSET '.$firstrow.'';
265:     }
266:     if ($r = F_db_query($sql, $db)) {
267:         if ($m = F_db_fetch_array($r)) {
268:             // -- Table structure with links:
269:             echo '<div class="container">';
270:             echo '<table class="userselect" style="font-size:80%;">'.K_NEWLINE;
271:             // table header
272:             echo '<tr>'.K_NEWLINE;
273:             if (strlen($searchterms) > 0) {
274:                 $filter .= '&amp;searchterms='.urlencode($searchterms);
275:             }
276:             echo F_select_table_header_element('test_begin_time', $nextorderdir, $l['w_time_begin'].' '.$l['w_datetime_format'], $l['w_time_begin'], $order_field, $filter);
277:             echo F_select_table_header_element('test_end_time', $nextorderdir, $l['w_time_end'].' '.$l['w_datetime_format'], $l['w_time_end'], $order_field, $filter);
278:             echo F_select_table_header_element('test_name', $nextorderdir, $l['h_test_name'], $l['w_name'], $order_field, $filter);
279:             echo F_select_table_header_element('test_description', $nextorderdir, $l['h_test_description'], $l['w_description'], $order_field, $filter);
280:             echo '</tr>'.K_NEWLINE;
281:             $itemcount = 0;
282:             do {
283:                 $itemcount++;
284:                 // on click the user ID will be returned on the calling form field
285:                 $jsaction = 'javascript:window.opener.document.getElementById(\''.$cid.'\').value='.$m['test_id'].';';
286:                 $jsaction .= 'window.opener.document.getElementById(\''.$cid.'\').onchange();';
287:                 $jsaction .= 'window.close();';
288:                 echo '<tr>'.K_NEWLINE;
289:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_begin_time'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
290:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_end_time'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
291:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;<a href="#" onclick="'.$jsaction.'" title="['.$l['w_select'].']">'.htmlspecialchars($m['test_name'], ENT_NOQUOTES, $l['a_meta_charset']).'</a></td>'.K_NEWLINE;
292:                 echo '<td style="text-align:'.$txtalign.';">&nbsp;'.htmlspecialchars($m['test_description'], ENT_NOQUOTES, $l['a_meta_charset']).'</td>'.K_NEWLINE;
293:                 echo '</tr>'.K_NEWLINE;
294:             } while ($m = F_db_fetch_array($r));
295: 
296:             echo '</table>'.K_NEWLINE;
297:             echo '<input type="hidden" name="order_field" id="order_field" value="'.$order_field.'" />'.K_NEWLINE;
298:             echo '<input type="hidden" name="orderdir" id="orderdir" value="'.$orderdir.'" />'.K_NEWLINE;
299:             echo '<input type="hidden" name="firstrow" id="firstrow" value="'.$firstrow.'" />'.K_NEWLINE;
300:             echo '<input type="hidden" name="rowsperpage" id="rowsperpage" value="'.$rowsperpage.'" />'.K_NEWLINE;
301: 
302:             echo '<div class="row"><hr /></div>'.K_NEWLINE;
303: 
304:             // ---------------------------------------------------------------
305:             // -- page jumper (menu for successive pages)
306:             if ($rowsperpage > 0) {
307:                 $sql = 'SELECT count(*) AS total FROM '.K_TABLE_TESTS.''.$wherequery.'';
308:                 if (!empty($order_field)) {
309:                     $param_array = '&amp;order_field='.urlencode($order_field).'';
310:                 }
311:                 if (!empty($orderdir)) {
312:                     $param_array .= '&amp;orderdir='.$orderdir.'';
313:                 }
314:                 if (!empty($searchterms)) {
315:                     $param_array .= '&amp;searchterms='.urlencode($searchterms).'';
316:                 }
317:                 $param_array .= '&amp;submitted=1';
318:                 F_show_page_navigator($_SERVER['SCRIPT_NAME'], $sql, $firstrow, $rowsperpage, $param_array);
319:             }
320:             echo '</div>'.K_NEWLINE;
321:         } else {
322:             F_print_error('MESSAGE', $l['m_search_void']);
323:         }
324:     } else {
325:         F_display_db_error();
326:     }
327:     return true;
328: }
329: 
330: /**
331:  * Return true if the selected test is active for the selected SSL Certificate
332:  * @param $test_id (int) test ID
333:  * @param $ssl_id (int) SSL Certificate ID
334:  * @return boolean true/false
335:  * @since 12.1.000 (2013-07-09)
336:  */
337: function F_isTestOnSSLCerts($test_id, $ssl_id)
338: {
339:     global $l, $db;
340:     require_once('../config/tce_config.php');
341:     $sql = 'SELECT tstssl_test_id FROM '.K_TABLE_TEST_SSLCERTS.' WHERE tstssl_test_id='.intval($test_id).' AND tstssl_ssl_id='.intval($ssl_id).' LIMIT 1';
342:     if ($r = F_db_query($sql, $db)) {
343:         if ($m = F_db_fetch_array($r)) {
344:             return true;
345:         }
346:     }
347:     return false;
348: }
349: 
350: //============================================================+
351: // END OF FILE
352: //============================================================+
353: 
 

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