full tab fixes to stop scroll of tab and not show bottom border of active tab (#407)
[openemr.git] / interface / reports / index.php
blob721fc17ed79aa53b65ee20b497cc76e4bf61e7d3
1 <?php
3 require_once (dirname(__FILE__) . "/../globals.php");
4 require_once (dirname(__FILE__) . "/../../library/sql.inc");
5 require_once (dirname(__FILE__) . "/../../library/adodb/adodb-pager.inc.php");
7 //get db connection setup in sql.inc
8 $db = $GLOBALS['adodb']['db'];
10 //define smarty template directory
11 $template_dir = dirname(__FILE__) . "/../../templates/report/";
13 //initialize a smarty object
14 $smarty = new Smarty();
16 //tell smarty where it can compile the templates, this is the defacto becuases postcalendar's smarty already uses it
17 $smarty->compile_dir = dirname(__FILE__) . "/../main/calendar/modules/PostCalendar/pntemplates/compiled";
19 //assign the styles setup in globals.php
20 $smarty->assign("STYLE",$GLOBALS['style']);
22 // assign the style sheet theme as defined in globals.php -- JRM
23 $smarty->assign("css_header", $GLOBALS['css_header']);
25 //There is not real ALL, so for this purpose we say 20,000
26 $show_options = array ("10" => "10","20" => "20","50" => "50","100" => "100","20000" => "All");
28 $smarty->assign("show_options",$show_options);
30 //query to select all canned queries from the pma_bookmark table
31 $sql = "SELECT * FROM pma_bookmark ORDER BY id";
32 $res = $db->Execute($sql);
34 //array to hold id's and labels of canned queries
35 $queries = array();
37 //loop through results
38 while (!$res->EOF) {
39 //populate the array with the id number and label of each canned query
40 $queries[$res->fields['id']] = $res->fields['label'];
41 $res->MoveNext();
44 //assign the array so the template can loop over it
45 $smarty->assign("queries",$queries);
47 //load the query id
48 $query_id = $_GET['query_id'];
50 //load the result per page number
51 $show = $_GET['show'];
53 //set a default show value
54 if (!is_numeric($show)) {
55 $show = $show_options[0];
58 //assign the var to the template
59 $smarty->assign("show",$show);
61 //conditional to see if a query has been selected and should be run
62 if (is_numeric($query_id)) {
63 //there is a query so set a default so the dropdowns will show the running query
64 $smarty->assign("query_id",$query_id);
66 //get the actual query from the pma_bookmark database
67 $sql = "SELECT query,label from pma_bookmark where id = " . $db->qstr($query_id);
68 //clear current_query var
69 $current_query = "";
71 $res = $db->Execute($sql);
72 if (!$res->EOF) {
73 $current_query = $res->fields['query'];
74 $smarty->assign("title", $res->fields['label']);
77 //current_query will now be empty or contain the query that was selected to be run
79 //each query can have "customizable" pieces, first see if the user entered any values for the first piece
80 if (!empty($_GET['var1'])) {
82 //escape the value the user supplied
83 $var1 = add_escape_custom($_GET['var1']);
85 //use a regex to replace the piece token with the user supplied value
86 $current_query = preg_replace('|/\*(.*)\[VARIABLE\](.*)\*/|imSU', '${1}' . $var1 . '${2}', $current_query);
88 //set a default so the template will fill in the varr fields with what the user last supplied
89 $smarty->assign("var1", $var1);
92 //repeat process if a second value was entered
93 if (!empty($_GET['var2'])) {
94 $var2 = add_escape_custom($_GET['var2']);
95 $current_query = preg_replace('|/\*(.*)\[VARIABLE2\](.*)\*/|imSU', '${1}' . $var2 . '${2}', $current_query);
96 $current_query = preg_replace('|\[VARIABLE2\]|imU', '${1}' . $var2 . '${2}', $current_query);
98 $smarty->assign("var2", $var2);
100 //echo "<pre>" . $current_query . "<br>";
102 //create a pager object that will handle all the dirty details of the display and pagination, had to add an argument to the constructor to pass along extra things that should appear in the query string for links generated by the pager
103 $pager = new ADODB_Pager($db,$current_query,"report",false,"query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=" . $show);
105 //hide links if in print view
106 if ($_GET['print'] == 1) {
107 $pager->showPageLinks = false;
110 //assign the pager object so the template can call it, need a more elegant way to do this or need to put error handling in the template, how can you capture the output from the pager?
111 $smarty->assign("pager", $pager);
114 //generate and assign printable link to template
115 $smarty->assign("printable_link",$_SERVER['PHP_SELF'] . "?query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=20000&print=1");
117 if ($_GET['print'] == 1) {
118 //load the printable template instead
119 $smarty->display($template_dir . "printable_default.html");
121 else {
122 //tell smarty to execute the template
123 $smarty->display($template_dir . "general_default.html");