ongoing internationalization of date widget
[openemr.git] / interface / reports / index.php
blob992d14f4e863926a11cb41c923b37577af2cf1cb
1 <?php
3 require_once(dirname(__FILE__) . "/../globals.php");
4 require_once(dirname(__FILE__) . "/../../library/adodb/adodb-pager.inc.php");
6 //get db connection setup in sql.inc
7 $db = $GLOBALS['adodb']['db'];
9 //define smarty template directory
10 $template_dir = dirname(__FILE__) . "/../../templates/report/";
12 //initialize a smarty object
13 $smarty = new Smarty();
15 //tell smarty where it can compile the templates, this is the defacto becuases postcalendar's smarty already uses it
16 $smarty->compile_dir = dirname(__FILE__) . "/../main/calendar/modules/PostCalendar/pntemplates/compiled";
18 //assign the styles setup in globals.php
19 $smarty->assign("STYLE", $GLOBALS['style']);
21 // assign the style sheet theme as defined in globals.php -- JRM
22 $smarty->assign("css_header", $GLOBALS['css_header']);
24 //There is not real ALL, so for this purpose we say 20,000
25 $show_options = array ("10" => "10","20" => "20","50" => "50","100" => "100","20000" => "All");
27 $smarty->assign("show_options", $show_options);
29 //query to select all canned queries from the pma_bookmark table
30 $sql = "SELECT * FROM pma_bookmark ORDER BY id";
31 $res = $db->Execute($sql);
33 //array to hold id's and labels of canned queries
34 $queries = array();
36 //loop through results
37 while (!$res->EOF) {
38 //populate the array with the id number and label of each canned query
39 $queries[$res->fields['id']] = $res->fields['label'];
40 $res->MoveNext();
43 //assign the array so the template can loop over it
44 $smarty->assign("queries", $queries);
46 //load the query id
47 $query_id = $_GET['query_id'];
49 //load the result per page number
50 $show = $_GET['show'];
52 //set a default show value
53 if (!is_numeric($show)) {
54 $show = $show_options[0];
57 //assign the var to the template
58 $smarty->assign("show", $show);
60 //conditional to see if a query has been selected and should be run
61 if (is_numeric($query_id)) {
62 //there is a query so set a default so the dropdowns will show the running query
63 $smarty->assign("query_id", $query_id);
65 //get the actual query from the pma_bookmark database
66 $sql = "SELECT query,label from pma_bookmark where id = " . $db->qstr($query_id);
67 //clear current_query var
68 $current_query = "";
70 $res = $db->Execute($sql);
71 if (!$res->EOF) {
72 $current_query = $res->fields['query'];
73 $smarty->assign("title", $res->fields['label']);
76 //current_query will now be empty or contain the query that was selected to be run
78 //each query can have "customizable" pieces, first see if the user entered any values for the first piece
79 if (!empty($_GET['var1'])) {
80 //escape the value the user supplied
81 $var1 = add_escape_custom($_GET['var1']);
83 //use a regex to replace the piece token with the user supplied value
84 $current_query = preg_replace('|/\*(.*)\[VARIABLE\](.*)\*/|imSU', '${1}' . $var1 . '${2}', $current_query);
86 //set a default so the template will fill in the varr fields with what the user last supplied
87 $smarty->assign("var1", $var1);
90 //repeat process if a second value was entered
91 if (!empty($_GET['var2'])) {
92 $var2 = add_escape_custom($_GET['var2']);
93 $current_query = preg_replace('|/\*(.*)\[VARIABLE2\](.*)\*/|imSU', '${1}' . $var2 . '${2}', $current_query);
94 $current_query = preg_replace('|\[VARIABLE2\]|imU', '${1}' . $var2 . '${2}', $current_query);
96 $smarty->assign("var2", $var2);
99 //echo "<pre>" . $current_query . "<br>";
101 //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
102 $pager = new ADODB_Pager($db, $current_query, "report", false, "query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=" . $show);
104 //hide links if in print view
105 if ($_GET['print'] == 1) {
106 $pager->showPageLinks = false;
109 //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?
110 $smarty->assign("pager", $pager);
113 //generate and assign printable link to template
114 $smarty->assign("printable_link", $_SERVER['PHP_SELF'] . "?query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=20000&print=1");
116 if ($_GET['print'] == 1) {
117 //load the printable template instead
118 $smarty->display($template_dir . "printable_default.html");
119 } else {
120 //tell smarty to execute the template
121 $smarty->display($template_dir . "general_default.html");