some optimization for IPPF forms
[openemr.git] / interface / reports / index.php
blobdead460da862094b080f08fd24d67c0c70a7d1cc
1 <?
3 require_once (dirname(__FILE__) . "/../globals.php");
4 require_once (dirname(__FILE__) . "/../../library/sql.inc");
5 require_once (dirname(__FILE__) . "/../../library/Smarty.class.php");
6 require_once (dirname(__FILE__) . "/../../library/adodb/adodb-pager.inc.php");
8 //get db connection setup in sql.inc
9 $db = $GLOBALS['adodb']['db'];
11 //define smarty template directory
12 $template_dir = dirname(__FILE__) . "/../../templates/report/";
14 //initialize a smarty object
15 $smarty = new Smarty();
17 //tell smarty where it can compile the templates, this is the defacto becuases postcalendar's smarty already uses it
18 $smarty->compile_dir = dirname(__FILE__) . "/../main/calendar/modules/PostCalendar/pntemplates/compiled";
20 //assign the styles setup in globals.php
21 $smarty->assign("STYLE",$GLOBALS['style']);
23 // assign the style sheet theme as defined in globals.php -- JRM
24 $smarty->assign("css_header", $GLOBALS['css_header']);
26 //There is not real ALL, so for this purpose we say 20,000
27 $show_options = array ("10" => "10","20" => "20","50" => "50","100" => "100","20000" => "All");
29 $smarty->assign("show_options",$show_options);
31 //query to select all canned queries from the pma_bookmark table
32 $sql = "SELECT * FROM pma_bookmark ORDER BY id";
33 $res = $db->Execute($sql);
35 //array to hold id's and labels of canned queries
36 $queries = array();
38 //loop through results
39 while (!$res->EOF) {
40 //populate the array with the id number and label of each canned query
41 $queries[$res->fields['id']] = $res->fields['label'];
42 $res->MoveNext();
45 //assign the array so the template can loop over it
46 $smarty->assign("queries",$queries);
48 //load the query id
49 $query_id = $_GET['query_id'];
51 //load the result per page number
52 $show = $_GET['show'];
54 //set a default show value
55 if (!is_numeric($show)) {
56 $show = $show_options[0];
59 //assign the var to the template
60 $smarty->assign("show",$show);
62 //conditional to see if a query has been selected and should be run
63 if (is_numeric($query_id)) {
64 //there is a query so set a default so the dropdowns will show the running query
65 $smarty->assign("query_id",$query_id);
67 //get the actual query from the pma_bookmark database
68 $sql = "SELECT query,label from pma_bookmark where id = " . $db->qstr($query_id);
69 //clear current_query var
70 $current_query = "";
72 $res = $db->Execute($sql);
73 if (!$res->EOF) {
74 $current_query = $res->fields['query'];
75 $smarty->assign("title", $res->fields['label']);
78 //current_query will now be empty or contain the query that was selected to be run
80 //each query can have "customizable" pieces, first see if the user entered any values for the first piece
81 if (!empty($_GET['var1'])) {
83 //escape the value the user supplied
84 $var1 = mysql_real_escape_string($_GET['var1']);
86 //use a regex to replace the piece token with the user supplied value
87 $current_query = preg_replace('|/\*(.*)\[VARIABLE\](.*)\*/|imSU', '${1}' . $var1 . '${2}', $current_query);
89 //set a default so the template will fill in the varr fields with what the user last supplied
90 $smarty->assign("var1", $var1);
93 //repeat process if a second value was entered
94 if (!empty($_GET['var2'])) {
95 $var2 = mysql_real_escape_string($_GET['var2']);
96 $current_query = preg_replace('|/\*(.*)\[VARIABLE2\](.*)\*/|imSU', '${1}' . $var2 . '${2}', $current_query);
97 $current_query = preg_replace('|\[VARIABLE2\]|imU', '${1}' . $var2 . '${2}', $current_query);
99 $smarty->assign("var2", $var2);
101 //echo "<pre>" . $current_query . "<br>";
103 //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
104 $pager = new ADODB_Pager($db,$current_query,"report",false,"query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=" . $show);
106 //hide links if in print view
107 if ($_GET['print'] == 1) {
108 $pager->showPageLinks = false;
111 //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?
112 $smarty->assign("pager", $pager);
115 //generate and assign printable link to template
116 $smarty->assign("printable_link",$_SERVER['PHP_SELF'] . "?query_id=" . $query_id . "&var1=" . $var1 . "&var2=" . $var2 . "&show=20000&print=1");
118 if ($_GET['print'] == 1) {
119 //load the printable template instead
120 $smarty->display($template_dir . "printable_default.html");
122 else {
123 //tell smarty to execute the template
124 $smarty->display($template_dir . "general_default.html");