Graham Quince Posted March 28, 2018 Share Posted March 28, 2018 Paul’s code converts the IP address to a string, so you should be able to use something like: https://www.w3schools.com/jsref/jsref_indexof.asp or https://www.w3schools.com/jsref/jsref_indexof_array.asp Graham Link to comment Share on other sites More sharing options...
mmclaughlin Posted April 17, 2018 Author Share Posted April 17, 2018 (edited) So I am back to working on this because it does not seem to be working completely. WE ran into that we have a range of IPs. I tried to edit it as below. It does not seem to hide widget. I am also getting a malformed java error. Thoughts Matt @Graham Quince @pconkie Edited April 17, 2018 by mmclaughlin Link to comment Share on other sites More sharing options...
Simon Law Posted April 18, 2018 Share Posted April 18, 2018 If I was javascript, I would probably not like You are trying to use an ip address as though it was a number and comparing it to ip[0] which is a string 10 is a number 10.0 is a number 10.0.112 is not a valid number 10.0.112.1 is not a valid number so ...... var r = /\b(\d{1,3}).(\d{1,3}).(\d{1,3})\b/; // capture the individual parts of the ip address var ip = data.match(r); if (ip && ip[1] === '10' && ip[2] === '0' && (parseInt(ip[3]) >= 112 && parseInt(ip[3]) <= 127)) { Link to comment Share on other sites More sharing options...
mmclaughlin Posted April 18, 2018 Author Share Posted April 18, 2018 So I replaced the if statement with 4 hours ago, Simon Law said: if (ip && ip[1] === '10' && ip[2] === '0' && (parseInt(ip[3]) >= 112 && parseInt(ip[3]) <= 127)) { Does not seem to have worked. Link to comment Share on other sites More sharing options...
Simon Law Posted April 18, 2018 Share Posted April 18, 2018 8 minutes ago, mmclaughlin said: So I replaced the if statement with Does not seem to have worked. The regex has also changed and you need that too Where can I see the widget working/not working (site/page)? Link to comment Share on other sites More sharing options...
mmclaughlin Posted April 18, 2018 Author Share Posted April 18, 2018 I can't share the site, but here is the code as it sits now. Link to comment Share on other sites More sharing options...
Simon Law Posted April 18, 2018 Share Posted April 18, 2018 (edited) <script> /////////////////////////////////////// //logic: /////Always hide widget.. ////Show widget if all criteria met /////////////////////////////////////// //declare and set vars //change these values as required //SL my widget has different uuid var widget_to_hide = "7E50015020028EF283501F8FD1F30A0096EE04DCC9DB2497"; var school_ip_lower = "10.0.112.1"; var school_ip_upper = "10.0.127.254"; var format = 'hh:mm:ss'; var time = moment(); var beforeTime = moment('07:30:00', format); //SL I am working late so I set for late night var afterTime = moment('19:00:00', format); var currentuser = FrogOS.getUser(); var dayOfWeek = moment().day(); //SL made theWidget so I could use it again and again var theWidget = $("div[data-content-uuid='"+widget_to_hide+"']"); //SL added debugger so I could step through in dev tools debugger; //hide widget theWidget.hide(); //SL logged in as not a student for testing if (currentuser.profile.type == "student") { //they are not a student - show the widget theWidget.show(); } else { //async load of users school ip address...waits for response... $.get( "../ipaddress.php", function( data ) { //SL added debugger so I don't have to step through ipaddress call debugger; var r = /\b(\d{1,3}).(\d{1,3}).(\d{1,3})\b/; var ip = data.match(r); // capture the individual parts of the ip address // my ip was 192.168.99 so I had to if condition if (ip && ip[1] === '192' && ip[2] === '168' && (parseInt(ip[3]) >= 90 && parseInt(ip[3]) <= 99)) { //they are at school //if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 5) { //SL cleaner to use inArray if ($.inArray(dayOfWeek, [1,2,3,4,5])) { //0=sunday, 1=monday etc BUT perhaps this isn't correct for US? //it should be Mon-Fri if (time.isBetween(beforeTime, afterTime)) { //it's within school hours //finally show the widget! theWidget.show(); } } } }); } </script> I had to alter code see //SL but it worked for me Edited April 18, 2018 by Simon Law added more comments and extra debugger Link to comment Share on other sites More sharing options...
Simon Law Posted April 18, 2018 Share Posted April 18, 2018 I suggest you add the debugger line, open up dev tools and step through the code to see where it is failing, because the code I just submitted worked Link to comment Share on other sites More sharing options...
mmclaughlin Posted April 18, 2018 Author Share Posted April 18, 2018 Will do Link to comment Share on other sites More sharing options...
mmclaughlin Posted April 18, 2018 Author Share Posted April 18, 2018 Used the code... I changed the time. and I changed the 192 to 10 the 168 to 0 the 90 to 112 and the 99 to 127. I also made sure to target the correct uuid for the site. See below for the changes. I also change the == to a !== to make it disappear for the student and appear for staff. It now is in a state of disappear and I don't see it for student thought I would be in the correct ip. Will try to work with someone on it some more. I understand your code pretty well and it should be working. Matt <script> /////////////////////////////////////// //logic: /////Always hide widget.. ////Show widget if all criteria met /////////////////////////////////////// //declare and set vars //change these values as required var widget_to_hide = "A1209E3C20028742D15E5F56768642005CF72A5C3CA5F865"; var school_ip_lower = "10.0.112.1"; var school_ip_upper = "10.0.127.254"; var format = 'hh:mm:ss'; var time = moment(); //time is in UTC var beforeTime = moment('11:30:00', format); //SL I am working late so I set for late night var afterTime = moment('19:00:00', format); var currentuser = FrogOS.getUser(); var dayOfWeek = moment().day(); //SL made theWidget so I could use it again and again var theWidget = $("div[data-content-uuid='"+widget_to_hide+"']"); //SL added debugger so I could step through in dev tools debugger; //hide widget theWidget.hide(); //SL logged in as not a student for testing if (currentuser.profile.type !== "student") { //they are not a student - show the widget theWidget.show(); } else { //async load of users school ip address...waits for response... $.get( "../ipaddress.php", function( data ) { var r = /\b(\d{1,3}).(\d{1,3}).(\d{1,3})\b/; var ip = data.match(r); // capture the individual parts of the ip address // see above for the range if (ip && ip[1] === '10' && ip[2] === '0' && (parseInt(ip[3]) >= 112 && parseInt(ip[3]) <= 127)) { //they are at school //if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 5) { //SL cleaner to use inArray if ($.inArray(dayOfWeek, [1,2,3,4,5])) { //0=sunday, 1=monday etc BUT perhaps this isn't correct for US? //it should be Mon-Fri if (time.isBetween(beforeTime, afterTime)) { //it's within school hours //finally show the widget! theWidget.show(); } } } }); } </script> Link to comment Share on other sites More sharing options...
mmclaughlin Posted May 9, 2018 Author Share Posted May 9, 2018 I wanted to thank everyone who assisted with the code. It is working at this point. At some point, I would love to create a widget that would be able to do this, but am not sure. So @pconkie @Graham Quince @Simon Law you are the greatest! Matt 2 1 Link to comment Share on other sites More sharing options...
ann Posted October 15, 2018 Share Posted October 15, 2018 Hi This code is almost exactly what I need. - can anyone help me with amendments to achieve the following. We would like to automatically show the tutor dashboard to tutors during tutor time. all other staff would go to the default staff dashboard so for........ Staff in usergroups "tutor year 7" & 'Tutor year group 8' etc logged in on School IP address Mon - Fri between 8.30 and 8.55 show the Tutor Time dashboard rather than the default staff dashboard I would guess that the showing of a different site could be dealt with using rules but how do change the code to show a frog site rather that 'not show a widget' as it is currently written Any help gratefully received Ann Link to comment Share on other sites More sharing options...
ADT Posted October 15, 2018 Share Posted October 15, 2018 38 minutes ago, ann said: Hi This code is almost exactly what I need. - can anyone help me with amendments to achieve the following. We would like to automatically show the tutor dashboard to tutors during tutor time. all other staff would go to the default staff dashboard so for........ Staff in usergroups "tutor year 7" & 'Tutor year group 8' etc logged in on School IP address Mon - Fri between 8.30 and 8.55 show the Tutor Time dashboard rather than the default staff dashboard I would guess that the showing of a different site could be dealt with using rules but how do change the code to show a frog site rather that 'not show a widget' as it is currently written Any help gratefully received Ann You could always use a 100% theme @Graham Quince has and then nest each dashboard..... and hide a widget depending on time etc? Link to comment Share on other sites More sharing options...
Graham Quince Posted October 15, 2018 Share Posted October 15, 2018 5 hours ago, ann said: Hi This code is almost exactly what I need. - can anyone help me with amendments to achieve the following. We would like to automatically show the tutor dashboard to tutors during tutor time. all other staff would go to the default staff dashboard so for........ Staff in usergroups "tutor year 7" & 'Tutor year group 8' etc logged in on School IP address Mon - Fri between 8.30 and 8.55 show the Tutor Time dashboard rather than the default staff dashboard I would guess that the showing of a different site could be dealt with using rules but how do change the code to show a frog site rather that 'not show a widget' as it is currently written Any help gratefully received Ann Hi @ann I'd be really nervous about trying to automate a dashboard change. Would it not be easier to provide links to the Tutor sections? Seeing as it's only for a short time each day. Graham Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now