Focus the search term on load
[openemr.git] / interface / reports / report.script.php
blobe3506336cfbd0664e055eb0108b450325dfa27f5
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
28 <!-- Common javascript functions are stored in this page. -->
29 <script type="text/javascript">
30 //Calendar Functions to set From and To dates
31 function calendar_function(val,from,to){
33 var date = new Date();
34 fromdate=document.getElementById(from);
35 todate =document.getElementById(to);
36 if(val=='this_month_to_date'){
37 var dt = date.getDate()-1;
38 fromdate.value=disp_date(-dt,0,0);
39 todate.value=disp_date(0,0,0);
41 else if(val=='today'){
42 fromdate.value=disp_date(0,0,0);
43 todate.value=disp_date(0,0,0);
45 else if(val=='last_month'){
46 var m = date.getMonth();
47 var yy = date.getYear();
48 var mt=daysInMonth(m,yy);
49 fromdate.value=last_month()+"-01";
50 todate.value=last_month()+"-"+mt;
52 else if(val=='this_calendar_year'){
53 var dt = date.getDate()-1;
54 var m = date.getMonth();
55 fromdate.value=disp_date(-dt,-m,0);
56 dt=30-dt;
57 m=11-m;
58 todate.value=disp_date(dt,m,0);
60 else if(val=='last_calendar_year'){
61 var dt = date.getDate()-1;
62 var m = date.getMonth();
63 fromdate.value=disp_date(-dt,-m,-1);
64 dt=30-dt;
65 m=11-m;
66 todate.value=disp_date(dt,m,-1);
68 else if(val=='this_week_to_date'){
69 fromdate.value=week_date();
70 todate.value=disp_date(0,0,0);
72 else{
73 fromdate.value='';
74 todate.value='';
78 //Below functions are called in the above function
79 function disp_date(dt,mt,yr){
80 var date = new Date();
81 var d = date.getDate() + dt;
82 var day = (d < 10) ? '0' + d : d;
83 var m = date.getMonth() + 1 + mt;
84 var month = (m < 10) ? '0' + m : m;
85 var yy = date.getYear() + yr;
86 var year = (yy < 1000) ? yy + 1900 : yy;
87 current=(year + "-" + month + "-" + day);
88 return current;
90 function daysInMonth(month,year) {
91 var dd = new Date(year, month, 0);
92 return dd.getDate();
94 function last_month(){
95 var date = new Date();
96 var yy=date.getYear();
97 var m=date.getMonth();
98 if(date.getMonth()==0){
99 yy--;
100 m=12;
102 var month = (m < 10) ? '0' + m : m;
103 var year = (yy < 1000) ? yy + 1900 : yy;
104 current=(year + "-" + month );
105 return current;
107 function week_date(){
108 var today = new Date();
109 var day = today.getDate();
110 var month = today.getMonth() + 1;
111 var year = today.getYear();
112 if (year < 2000)
113 year = year + 1900;
114 var offset = today.getDay();
115 var week;
117 if(offset != 0) {
118 day = day - offset;
119 if ( day < 1) {
120 if ( month == 1) day = 31 + day;
121 if (month == 2) day = 31 + day;
122 if (month == 3) {
123 if (( year == 00) || ( year == 04)) {
124 day = 29 + day;
126 else {
127 day = 28 + day;
130 if (month == 4) day = 31 + day;
131 if (month == 5) day = 30 + day;
132 if (month == 6) day = 31 + day;
133 if (month == 7) day = 30 + day;
134 if (month == 8) day = 31 + day;
135 if (month == 9) day = 31 + day;
136 if (month == 10) day = 30 + day;
137 if (month == 11) day = 31 + day;
138 if (month == 12) day = 30 + day;
139 if (month == 1) {
140 month = 12;
141 year = year - 1;
143 else {
144 month = month - 1;
148 month = (month < 10) ? '0' + month : month;
149 day = (day < 10) ? '0' + day : day;
150 week = year + "-" + month + "-" + day ;
151 return week;
153 //================================================================================================================================
154 //Search Functionality
155 function CriteriaVisible()//This function is called when, on change event happens, in the select box containing all the search criteria of the page.
156 {//This shows different values based on the type of the search criteria.For 'date' type it shows 'From' 'To' etc.
157 for(OptionIndex=0;OptionIndex<document.getElementById('choose_this_page_criteria').options.length;OptionIndex++)
159 choose_this_page_criteria_value=document.getElementById('choose_this_page_criteria').options[OptionIndex].value;
160 if(document.getElementById('table_'+choose_this_page_criteria_value))
161 document.getElementById('table_'+choose_this_page_criteria_value).style.display='none';
163 choose_this_page_criteria_value=document.getElementById('choose_this_page_criteria').options[document.getElementById('choose_this_page_criteria').selectedIndex].value;
164 document.getElementById('table_'+choose_this_page_criteria_value).style.display='';
166 function checkOptionExist(value0,seperator)//It returns the position of the option, if the value is found, in the final criteria select box submitted.
167 {//If doesn't exist new insertion is done.If exist it is updated.
168 var elSel = document.getElementById('final_this_page_criteria');
169 var i;
170 for (i = elSel.length - 1; i>=0; i--) {
171 OptionValue=elSel.options[i].value;
172 OptionValue=OptionValue.split(seperator);
173 if (OptionValue[0]==value0) {
174 return i;
177 return -1;
179 function checkOptionExistDateCriteria(value0)//For Date Criteria.It returns the position of the option, if the value is found,
180 {//in the final criteria select box submitted.//If doesn't exist new insertion is done.If exist it is updated.
181 var elSel = document.getElementById('final_this_page_criteria');
182 var i;
183 for (i = elSel.length - 1; i>=0; i--) {
184 OptionValue=elSel.options[i].value;
185 OptionValue=OptionValue.split(' between ');
186 if (OptionValue[0]=='('+value0) {
187 return i;
190 return -1;
192 function appendOptionRadioCriteria(text0,value0,text1,value1,seperator,Type)
193 {//If option doesn't exist new insertion is done.If exist it is updated in the select drop down.//Remove the item if the option is All.
194 var elOptNew = document.createElement('option');
195 if(Type=='radio' || Type=='query_drop_down')
197 elOptNew.text = text0+seperator+text1;
198 elOptNew.value = value0+seperator+"'"+value1+"'";
200 else if (Type=='radio_like')
202 elOptNew.text = text0+' = '+text1;
203 elOptNew.value = value0+seperator+"'"+value1+"'";
205 var elSel = document.getElementById('final_this_page_criteria');
206 TheOptionIndex=checkOptionExist(value0,seperator);
207 if(TheOptionIndex==-1)
209 if(value1!='all')
211 try {
212 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
214 catch(ex) {
215 elSel.add(elOptNew); // IE only
219 else if(value1=='all')
221 elSel.remove(TheOptionIndex);
223 else
225 elSel.options[TheOptionIndex].value=elOptNew.value;
226 elSel.options[TheOptionIndex].text=elOptNew.text;
229 function appendOptionTextCriteria(text0,value0,text1,value1,seperator,Type)
230 {//If option doesn't exist new insertion is done.If exist it is updated in the select drop down.//Remove the item if the value is blank.
231 var elOptNew = document.createElement('option');
232 elOptNew.text = text0+seperator+text1;
233 if(Type=='text')
235 elOptNew.value = value0+seperator+"'"+value1+"'";
237 else if (Type=='text_like')
239 elOptNew.value = value0+seperator+"'"+value1+"%'";
241 var elSel = document.getElementById('final_this_page_criteria');
242 TheOptionIndex=checkOptionExist(value0,seperator);
243 if(TheOptionIndex==-1)
245 if(!(value1=='' || value1=='&nbsp;'))//'&nbsp;' is for ajax case
247 try {
248 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
250 catch(ex) {
251 elSel.add(elOptNew); // IE only
255 else if(value1=='' || value1=='&nbsp;')
257 elSel.remove(TheOptionIndex);
259 else
261 elSel.options[TheOptionIndex].value=elOptNew.value;
262 elSel.options[TheOptionIndex].text=elOptNew.text;
265 function appendOptionDateCriteria(text0,value0,text1,value1,seperator,FromDate,ToDate,Type)//For Date drop down
266 {//If option doesn't exist new insertion is done.If exist it is updated in the select drop down.//Remove the item if the drop down is All.
267 var elOptNew = document.createElement('option');
268 elOptNew.text = text0+seperator+text1;
269 FromDateValue=document.getElementById(FromDate).value;
270 ToDateValue=document.getElementById(ToDate).value;
271 if(Type=='date')
273 elOptNew.value = "("+value0+" between '"+FromDateValue+"' and '"+ToDateValue+"')";
275 if(Type=='datetime')
277 elOptNew.value = "("+value0+" between '"+FromDateValue+" 00:00:00' and '"+ToDateValue+" 23:59:59')";
279 var elSel = document.getElementById('final_this_page_criteria');
280 TheOptionIndex=checkOptionExistDateCriteria(value0);
281 if(TheOptionIndex==-1)
283 if(value1!='all')
285 try {
286 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
288 catch(ex) {
289 elSel.add(elOptNew); // IE only
293 else if(value1=='all')
295 elSel.remove(TheOptionIndex);
297 else
299 elSel.options[TheOptionIndex].value=elOptNew.value;
300 elSel.options[TheOptionIndex].text=elOptNew.text;
303 function CleanUpAjax(text0,value0,seperator)
304 {//Cleans the values in the ajax (Insurance Company criteria)
305 document.getElementById('type_code').value='';
306 document.getElementById('hidden_ajax_close_value').value='';
307 document.getElementById('hidden_type_code').value='';
308 document.getElementById('div_insurance_or_patient').innerHTML='';
309 var elSel = document.getElementById('final_this_page_criteria');
310 TheOptionIndex=checkOptionExist(value0,seperator);
311 if(TheOptionIndex==-1)
314 else
316 elSel.remove(TheOptionIndex);
319 function removeOptionSelected()
320 {//Remove the selected options from the drop down.
321 OptionRemoved='no';
322 var elSel = document.getElementById('final_this_page_criteria');
323 var i;
324 for (i = elSel.length - 1; i>=0; i--) {
325 if (elSel.options[i].selected) {
326 elSel.remove(i);
327 OptionRemoved='yes';
330 if(OptionRemoved=='no')
332 alert("<?php echo htmlspecialchars( xl('Select Criteria to Remove'), ENT_QUOTES) ?>")
335 function ProcessBeforeSubmitting()//Validations and necessary actions are taken here.
336 {//Text of the drop down 'final_this_page_criteria' is copied to the value of the drop down 'final_this_page_criteria_text'
337 //So that both value and text of the final criteria can be restored back.
338 if(!ValidateDateCriteria('final_this_page_criteria'))
339 return false;
340 var selObj = document.getElementById('final_this_page_criteria');
341 var elSel = document.getElementById('final_this_page_criteria_text');
342 var i;
343 for (i = elSel.length - 1; i>=0; i--) {
344 elSel.remove(i);
346 for (var i=0; i<selObj.options.length; i++) {
347 var elOptNew = document.createElement('option');
348 elOptNew.text = 'Sample';//This value has no relevance can be any thing.
349 elOptNew.value = selObj.options[i].text;
350 try {
351 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
353 catch(ex) {
354 elSel.add(elOptNew); // IE only
357 selectAllOptions('final_this_page_criteria');
358 selectAllOptions('final_this_page_criteria_text');
359 return true;
361 function selectAllOptions(selStr)
362 {//Before submitting the multiselct drop downs are selected,then only they will be got in php.
363 var selObj = document.getElementById(selStr);
364 for (var i=0; i<selObj.options.length; i++) {
365 selObj.options[i].selected=true;
368 function SetDateCriteriaCustom(ObjectPassed)
369 {//Setting the value of drop down to 'custom' when user changes the date manually using the date picker.
370 var selObj = document.getElementById(ObjectPassed);
371 selObj.value='custom';
373 function ValidateDateCriteria(selStr)
374 {//From date should not be greater than To date.
375 var selObj = document.getElementById(selStr);
376 for (var i=0; i<selObj.options.length; i++) {
377 if(selObj.options[i].value.indexOf('between') != -1)
379 DateArray=selObj.options[i].value.split("'");
380 if(DateArray[1]>DateArray[3])
382 alert("<?php echo htmlspecialchars( xl('From Date Cannot be Greater than To Date.'), ENT_QUOTES) ?>");
383 return false;
385 if(DateArray[1]=='' || DateArray[3]=='')
387 alert("<?php echo htmlspecialchars( xl('Date values Cannot be Blank.'), ENT_QUOTES) ?>");
388 return false;
392 return true;
394 function getPosition(who,TopOrLeft){//Returns the top and left position of the passed object.
395 var T= 0,L= 0;
396 while(who){
397 L+= who.offsetLeft;
398 T+= who.offsetTop;
399 who= who.offsetParent;
401 if(TopOrLeft=='Top')
402 return T;
403 else if(TopOrLeft=='Left')
404 return L;
406 //-------------------------------------------------------------------------------------------------------------------------
407 //In Internet Explorer the ajax drop down of insurance was gettign hidden under the select drop down towards the right side.
408 //So an iframe is added to solve this issue.
409 //-------------------------------------------------------------------------------------------------------------------------
410 function show_frame_to_hide() {//Show the iframe
411 if(document.getElementById("AjaxContainerInsurance"))
413 document.getElementById("frame_to_hide").style.top = getPosition(document.getElementById('ajax_div_insurance'),'Top') + "px";
414 document.getElementById("frame_to_hide").style.left = getPosition(document.getElementById('final_this_page_criteria'),'Left') + "px";;
415 document.getElementById("frame_to_hide").style.display = "inline";
418 function hide_frame_to_hide() {//Hide the iframe
419 if(!document.getElementById("AjaxContainerInsurance"))
421 document.getElementById("frame_to_hide").style.display = "none";
424 //-------------------------------------------------------------------------------------------------------------------------
425 function TakeActionOnHide()//Action on clicking out side the ajax drop down of insurance.Hides the same.
427 HideTheAjaxDivs();
428 hide_frame_to_hide();
430 //===================================================================================================================================
431 </script>