Access control improvements. (#530)
[openemr.git] / interface / main / tabs / js / menu_analysis.js
blob10cd32c48e01c2f82de0ce9333f3b989c88d2575
1 /**
2  * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
3  *
4  * LICENSE: This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
14  *
15  * @package OpenEMR
16  * @author  Kevin Yeh <kevin.y@integralemr.com>
17  * @link    http://www.open-emr.org
18  */
20 var targets={};
21 targets['Calendar']='lst';
22 targets['Flow Board']='lst';
23 targets['Messages ']='pat';
24 targets['Administration']='adm';
25 targets['Reports']='rep';
26 targets['Miscellaneous']='msc';
28 targets['Patients']='lst';
30 var acl_reqs={};
31 var global_reqs={};
33 //Billing Menu Restrictions
34 acl_reqs['EDI History']=['acct','eob'];
35 global_reqs['EDI History']='enable_edihistory_in_left_menu'
37 // Administration Menu restrictions
38 acl_reqs['Globals']=['admin','super'];
39 acl_reqs['Facilities']=['admin','users'];
40 acl_reqs['Users']=['admin','users'];
41 acl_reqs['Addr Book']=['admin','practice'];
42 acl_reqs['Practice']=['admin','practice'];
43 acl_reqs['Codes']=['admin','superbill'];
44 acl_reqs['Layouts']=['admin','super'];
45 acl_reqs['Lists']=['admin','super'];
46 acl_reqs['ACL']=['admin','acl'];
47 acl_reqs['Files']=['admin','super'];
48 acl_reqs['Backup']=['admin','super'];
51 acl_reqs['Rules']=['admin','super'];
52 global_reqs['Rules']='enable_cdr'
54 acl_reqs['Alerts']=['admin','super'];
55 global_reqs['Alerts']='enable_cdr'
57 acl_reqs['Patient Reminders']=['admin','super'];
58 global_reqs['Patient Reminders']='enable_cdr'
61 acl_reqs['Language']=['admin','language'];
62 acl_reqs['Forms']=['admin','forms'];
64 acl_reqs['Calendar']=['admin','calendar','main/calendar/index.php?module=PostCalendar&type=admin&func=modifyconfig']
66 acl_reqs['Logs']=['admin','users'];
69 acl_reqs['Database']=['admin','database'];
70 global_reqs['Database']="!disable_phpmyadmin_link";
72 acl_reqs['Certificates']=['admin','users'];
74 acl_reqs['Native Data Loads']=['admin','super'];
75 acl_reqs['External Data Loads']=['admin','super'];
76 acl_reqs['Merge Patient']=['admin','super'];
78 global_reqs['Fax/Scan']=['enable_hylafax','enable_scanner'];
81 function set_acl_reqs(entry)
83     if('url' in entry)
84     {
85         if(entry.label in acl_reqs)
86         {
87             var reqs=acl_reqs[entry.label];
88             if(reqs.length===3)
89             {
90                 if(entry.url.indexOf(reqs[2])!==-1)
91                 {
92                     entry.acl_req=[reqs[0],reqs[1]];
93                 }
94             }
95             else
96             {
97                 entry.acl_req=acl_reqs[entry.label];
98             }
99         }
100         if(entry.label in global_reqs)
101         {
102             entry.global_req=global_reqs[entry.label];
103         }
104     }
107 function setTarget(entry,target)
109     if('url' in entry)
110     {
111         entry.target=target
112     }
113     else
114     {
115         for(var idx=0;idx<entry.children.length;idx++)
116         {
117             setTarget(entry.children[idx],target);
118         }
119     }
121 function post_process(menu_entries)
123     for(var idx=0;idx<menu_entries.length;idx++)
124     {
125         var curEntry=menu_entries[idx];
126         set_acl_reqs(curEntry);
127         if(curEntry.label in targets)
128         {
129             setTarget(curEntry,targets[curEntry.label]);
130         }
131         post_process(curEntry.children);
132     }
134 function parse_link(link,entry)
136     if(link)
137     {
138         var parameters=link.substring(link.indexOf('(')+1,link.indexOf(')'));
139         if(parameters==='')
140         {
141             parameters=link;
142         }
143         if(link.indexOf("loadFrame2")===-1)
144         {
145             var url=parameters.replace(/\'/g,"").replace(/\"/g,"").replace("../","/interface/");
146             entry.url=url;
147             entry.target="report";           
148         }
149         else
150         {
151             parameters=parameters.replace(/\'/g,"").replace(/\"/g,"");
152             var params=parameters.split(",");
153             entry.target=params[1];
154             if(entry.target==='RTop')
155             {
156                 entry.target='pat';
157             }
158             if(entry.target==='RBot')
159             {
160                 entry.target='enc';
161             }
164             entry.url=params[2].replace("../","/");
165             if(entry.url.indexOf("/")>0)
166             {
167                 entry.url="/interface/"+entry.url;
168             }
170         }
171     }
174 function menu_entry(label,link,menu_id)
176     var self=this;
177     self.label=label;
178     self.menu_id=menu_id;
179     parse_link(link,self);
180     self.children=[];
181     self.icon=icon;
182     self.helperText=helperText;
183     self.requirement=0;
184     if(menu_id)
185     {
186         if(menu_id.charAt(3)==='1')
187         {
188             if(self.label==='Summary')
189             {
190                 self.target="pat";
191             }
192             else
193             {
194                 self.target="enc";
195             }
196             self.requirement=1;
197         } else
198         if(menu_id.charAt(3)==='2')
199         {
200             self.target="enc";
201             self.requirement=2;
202             // Special case for "Current" visit entry
203             if(self.label==="Current")
204             {
205                 self.requirement=3;
206             }
207         }
208     }
210       
211     return this;
214 function menu_entry_from_jq(elem)
216     return new menu_entry(elem.text(),elem.attr("onClick"),elem.attr("id"));
218 var menu_entries=[];
219 function analyze_menu()
221     alert('I think you will never see this. --Rod'); // debugging
223     if(!top.left_nav)
224     {
225         setTimeout(analyze_menu,1000);
226         return;
227     }
228     else
229     {
230         if(!top.left_nav.$)
231         {
232             alert("no jq!");
233             setTimeout(analyze_menu,1000);
234             return;
235         }
236     }
237     var jqLeft=top.left_nav.$(top.left_nav.document)
238     var $=top.left_nav.$;
239     jqLeft.ready(function(){
241         var menuTop=jqLeft.find("#navigation-slide");
242         menuTop.children().each(
243                 function(idx,elem)
244                 {
245                     // Header or content
246                     var jqElem=$(elem);
247                     var anchor=jqElem.children("a");
248                     var subMenu = jqElem.children("ul");
249                     
250                     var newEntry=menu_entry_from_jq(anchor); 
251                     if(subMenu.length>0)
252                     {
253                         // 2 (Second) level menu items
254                         subMenu.children("li").each(function(idx,elem)
255                         {
256                             var sub_anchor=$(elem).children("a");
257                             var sub_entry=menu_entry_from_jq(sub_anchor);
258                             if(sub_anchor.length!==1)
259                             {
260                                 alert(sub_anchor.text());
261                             }
262                             var subSubMenu=$(elem).children("ul");
263                             //Third Level Menu Items
264                             if(subSubMenu.length>0 && sub_entry.label !=="Visit Forms")
265                             {
266                                 subSubMenu.children("li").each(function(idx,elem)   
267                                 {
268                                     var sub_sub_anchor=$(elem).children("a");
269                                     var sub_sub_entry=menu_entry_from_jq(sub_sub_anchor);
270                                     sub_entry.children.push(sub_sub_entry);
272                                 });
273                                 
274                             }
275                             //End Third Level Menu Items
276                             newEntry.children.push(sub_entry);
277                         });
278                         // End Second level menu items
279                     }
280                     else
281                     {
283                         
284                     };
285                     menu_entries.push(newEntry);
286                     
287                     
288                 }
289         );
290         // Scan popup select
291         var popups = jqLeft.find("select[name='popups'] option");
292         var popups_menu_header=new menu_entry("Popups","","popup");
293         menu_entries.push(popups_menu_header);
294         popups.each(function(idx,elem)
295             {
296                 var jqElem=$(elem);
297                 if(jqElem.val()!=='')
298                 {
299                     var popup_entry=new menu_entry(jqElem.text(),jqElem.val(),"Popup:"+jqElem.text());
300                     popup_entry.target="pop";
301                     popup_entry.requirement=1;
302                     popups_menu_header.children.push(popup_entry);
303                 }
304             });
305         // Process Complete
306         
307         post_process(menu_entries);
308         var data=$("<div id='#menuData'></div>");
309         data.text("$menu_json=\""+JSON.stringify(menu_entries).replace(/\"/g,"\\\"")+"\";");
310         $("body").append(data);
311     });
313 var toID=setTimeout(analyze_menu,1000);