* @copyright Deakin University 2007,2008 * @package queXS * @subpackage admin * @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 * * */ /** * Configuration file */ include("../config.inc.php"); /** * Database file */ include ("../db.inc.php"); /** * Authentication file */ require ("auth-admin.php"); /** * XHTML functions */ include("../functions/functions.xhtml.php"); /** * Input functions */ include("../functions/functions.input.php"); /* * From: https://secure.php.net/manual/en/function.array-multisort.php#100534 */ function array_orderby() { $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $field) { if (is_string($field)) { $tmp = array(); foreach ($data as $key => $row) $tmp[$key] = $row[$field]; $args[$n] = $tmp; } } $args[] = &$data; call_user_func_array('array_multisort', $args); return array_pop($args); } global $db; $sample_import_id = false; if (isset($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']); if (isset($_GET['ajax'])) { $length = intval($_GET['length']); $start = intval($_GET['start']); $search = ""; if (isset($_GET['search']['value'])) { $search = " WHERE (sv.val LIKE " . $db->qstr("%" . $_GET['search']['value'] . "%") . " OR c.case_id LIKE " . $db->qstr("%" . $_GET['search']['value'] . "%") . " OR sv.sample_id LIKE " . $db->qstr("%" . $_GET['search']['value'] . "%") . ")"; } $sql = "SELECT count(*) FROM sample WHERE import_id = '$sample_import_id'"; $totalData = $db->GetOne($sql); $sql = "SELECT sv.sample_id, CASE WHEN c.case_id IS NULL THEN CONCAT(' ') ELSE CONCAT('', c.case_id ,'') END as link, CASE WHEN c.case_id IS NULL THEN CONCAT('') ELSE '' END as assigncase FROM sample_var AS sv JOIN (sample as s) ON (s.import_id = '$sample_import_id' and sv.sample_id = s.sample_id) LEFT JOIN (`case` AS c, questionnaire AS q) ON ( c.sample_id = sv.sample_id AND q.questionnaire_id = c.questionnaire_id )" . $search . " GROUP BY sv.sample_id, c.case_id"; $r = $db->GetAll($sql); $totalFiltered = count($r); $s = array(); if ($r) { $sql = "SELECT var,var_id FROM sample_import_var_restrict WHERE sample_import_id = $sample_import_id ORDER by var ASC"; $rs = $db->GetAll($sql); foreach($r as &$rw) { $sql = "SELECT var_id,val FROM sample_var WHERE sample_id = {$rw['sample_id']}"; $rs = $db->GetAll($sql); foreach($rs as $rsw){ $rw['v' . $rsw['var_id']] = $rsw['val']; } } if (isset($_GET['order'][0]['column'])) { $col = intval($_GET['order'][0]['column']); $dir = SORT_DESC; if ($_GET['order'][0]['dir'] != 'desc') $dir = SORT_ASC; $keys = array_keys($r[0]); error_log("key:{$keys[$col]} dir:$dir"); $r = array_orderby($r,$keys[$col], $dir, SORT_NATURAL); } for ($i=0; $i < $length; $i++) { $j = $i + $start; if (isset($r[$j])) { $s[] = $r[$j]; } else { break; } } unset($r); } $json_data = array( "draw" => intval( $_GET['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $s // total data array ); echo json_encode($json_data); die(); } $css = array( "../include/bootstrap/css/bootstrap.min.css", "../include/bootstrap/css/bootstrap-theme.min.css", "../include/font-awesome/css/font-awesome.css", /* "../include/bootgrid/jquery.bootgrid.css", */ "../include/datatables/datatables.min.css", "../css/custom.css" ); $js_head = array( "../include/jquery/jquery.min.js", "../include/bootstrap/js/bootstrap.min.js", /* "../include/bootgrid/jquery.bootgrid.min.js", */ ); $js_foot = array( "../include/datatables/datatables.min.js", "../js/window.js", "../js/custom.js" ); $subtitle = T_("Search within this sample"); xhtml_head(T_("Search the sample"),true,$css,$js_head); ?>
" . T_("Go back") . ""; $sql = "SELECT sample_import_id as value,description, CASE WHEN sample_import_id = '$sample_import_id' THEN 'selected=\'selected\'' ELSE '' END AS selected FROM sample_import ORDER BY description ASC"; $r = $db->GetAll($sql); if(!empty($r)) print "" . T_("Sample ID") . " " . $sample_id . " " . T_("Deleted") . ".
" . T_("Added") . " " . $cases . " " . T_("Cases") . ".