mmclaughlin Posted February 14, 2018 Posted February 14, 2018 So we have been working on coming up with a way to limit information shown on a page either by IP (does not seem easily feasible) or by date and time. I have been working using this code <DOCTYPE html> <header> </header> <body> <input id="btthider" class="bttnhider" type="submit" onclick="showHidden(); showbtthidden();" value="Add a new notice here" > <script> var h = new Date().getHours(); var d = new Date(). getDay(); var butn = document.getElementById('btthider'); if (h <= 7 && h >= 11).btn.disabled=true; if (d = 0 && d = 6). btn.disable=true </script> </body> </DOCTYPE> To hide a button based on time and thought that I may be able to show and hide a .pdf or a widget. The reason for this need is that we have some activities that can ONLY be seen during the day which could then disappear during the evening and weekends. This is not a rules function ability or I would have used that. So any thoughts if this would work on a Frog page? Matt
pconkie Posted February 14, 2018 Posted February 14, 2018 (edited) @mmclaughlin I had a think about the first part (ip address). IF your school has a static IP then the following should work.... Edited February 14, 2018 by pconkie 2
pconkie Posted February 14, 2018 Posted February 14, 2018 And some initial thoughts on hide/show based on time of day.... 1
pconkie Posted February 15, 2018 Posted February 15, 2018 Actually I've just seen @Graham Quince suggestion in the other thread regarding IP addresses in frog... So this is a 100% frog based solution for getting ip address of current user 1 1
mmclaughlin Posted February 15, 2018 Author Posted February 15, 2018 @emoseley Here is the solution we have all be waiting for. Matt
mmclaughlin Posted February 15, 2018 Author Posted February 15, 2018 18 hours ago, pconkie said: And some initial thoughts on hide/show based on time of day.... Could we add day of week as well to this?
mmclaughlin Posted February 15, 2018 Author Posted February 15, 2018 @Graham Quince @pconkie I entered the code in into the site Test bed pdf viewer and am getting an unrecoverable syntax error after the second.show() Thoughts?
pconkie Posted February 15, 2018 Posted February 15, 2018 Need you to post your code and exact error message
mmclaughlin Posted February 16, 2018 Author Posted February 16, 2018 Error for the last one was expecting ) found ] but can't find where I am messing up. Matt
pconkie Posted February 16, 2018 Posted February 16, 2018 On this one... Delete line 19 - that’s a rouge }
pconkie Posted February 16, 2018 Posted February 16, 2018 (edited) On this one... There is a rouge semicolon on the end of line 4 - it should be a { You should also delete line 5 Edited February 16, 2018 by pconkie
pconkie Posted February 16, 2018 Posted February 16, 2018 I should have attached the code so you can copy/paste - hopefully attached by ip.txt by time.txt 1 1
pconkie Posted February 16, 2018 Posted February 16, 2018 This shows a particular widget depending on the day of the week $("div[data-content-uuid='"+widget_to_hide+"']").hide(); // automatically show by day of week var dayOfWeek = moment().day() //0=sunday, 1=monday, 6=saturday etc //show a specific widget if it is the weekend if (dayOfWeek === 6 || dayOfWeek === 0) { $("div[data-content-uuid='"+widget_to_hide+"']").show(); } What exactly do you want to do? Hide a pdf/widget except for a few hours of each day mon-fri?
ADT Posted February 17, 2018 Posted February 17, 2018 9 hours ago, pconkie said: This shows a particular widget depending on the day of the week $("div[data-content-uuid='"+widget_to_hide+"']").hide(); // automatically show by day of week var dayOfWeek = moment().day() //0=sunday, 1=monday, 6=saturday etc //show a specific widget if it is the weekend if (dayOfWeek === 6 || dayOfWeek === 0) { $("div[data-content-uuid='"+widget_to_hide+"']").show(); } What exactly do you want to do? Hide a pdf/widget except for a few hours of each day mon-fri? I was after something like this to hide our Home Drive network widget so the GCSE Computer Science kids couldn't access their network spaces during the controlled assessment............. weekdays 9am - 4pm...... not that we need it now but i'd still like to get it working in case we need it in the future!! Granted they could still access it via Frogdrive but not sure how many kids have actually looked to closely at that!!
mmclaughlin Posted February 20, 2018 Author Posted February 20, 2018 @pconkie So it is a file or widget that we would like to hide except during school hours for students who are in the school. This would then prevent them from accessing it at home. @ADT Thanks!
ADT Posted February 20, 2018 Posted February 20, 2018 2 minutes ago, mmclaughlin said: @pconkie So it is a file or widget that we would like to hide except during school hours for students who are in the school. This would then prevent them from accessing it at home. @ADT Thanks! Not sure what ive done..... @pconkie has done all the work!!
pconkie Posted February 20, 2018 Posted February 20, 2018 (edited) @mmclaughlin Just to check I understand... You have a file.widget that should be hidden unless the student is IN school AND it is between 8am-4pm A student who is "off sick" at home on a school day between 8am-4pm should NOT be able to see it. A student who is in school on a Saturday (!) between 8am-4pm should NOT be able to see it. Please confirm that 64.26.100.114 the ip address you see when you go to this website https://whatismyipaddress.com at school Edited February 20, 2018 by pconkie
mmclaughlin Posted February 21, 2018 Author Posted February 21, 2018 64.26.100.114 is our IP address for the school. It is static. Yes, We would like those conditions to be met. That 1. The student is physically present on our servers in the school. 2. The student is here during the school day and 3. That it is not on the weekend. This would be a widget assigned to a for a site that prevents a pdf or text widget to be available to a student. Matt
pconkie Posted February 22, 2018 Posted February 22, 2018 So this should do it <script> /////////////////////////////////////// //logic: /////Always hide widget.. ////Show widget if all criteria met /////////////////////////////////////// //declare and set vars //change these values as required var widget_to_hide = "8E78A5802002886228C14F5F7A52E20F74E7BD2C79D5CFCA"; var school_ip = "64.26.100.114"; var format = 'hh:mm:ss'; var time = moment(); var beforeTime = moment('08:30:00', format); var afterTime = moment('15:30:00', format); var currentuser = FrogOS.getUser(); var dayOfWeek = moment().day() //hide widget $("div[data-content-uuid='"+widget_to_hide+"']").hide(); if (currentuser.profile.type !== "student") { //they are not a student - show the widget $("div[data-content-uuid='"+widget_to_hide+"']").show(); } else { //async load of users external ip address...waits for response... $.get( "../ipaddress.php", function( data ) { var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/; var ip = data.match(r); if (ip[0] == school_ip) { //they are at school if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 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! $("div[data-content-uuid='"+widget_to_hide+"']").show(); } } } }); } </script> You will need a student account to test as this will not hide the widget if the user is staff / admin. Code also attached for easy copy/paste - code.txt Paul
pconkie Posted February 22, 2018 Posted February 22, 2018 PS: A word of warning: This only hides the widget. It is still on the page in the site. It would still be possible for an inventive student to get to it.
ADT Posted February 23, 2018 Posted February 23, 2018 9 hours ago, pconkie said: So this should do it <script> /////////////////////////////////////// //logic: /////Always hide widget.. ////Show widget if all criteria met /////////////////////////////////////// //declare and set vars //change these values as required var widget_to_hide = "8E78A5802002886228C14F5F7A52E20F74E7BD2C79D5CFCA"; var school_ip = "64.26.100.114"; var format = 'hh:mm:ss'; var time = moment(); var beforeTime = moment('08:30:00', format); var afterTime = moment('15:30:00', format); var currentuser = FrogOS.getUser(); var dayOfWeek = moment().day() //hide widget $("div[data-content-uuid='"+widget_to_hide+"']").hide(); if (currentuser.profile.type !== "student") { //they are not a student - show the widget $("div[data-content-uuid='"+widget_to_hide+"']").show(); } else { //async load of users external ip address...waits for response... $.get( "../ipaddress.php", function( data ) { var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/; var ip = data.match(r); if (ip[0] == school_ip) { //they are at school if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 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! $("div[data-content-uuid='"+widget_to_hide+"']").show(); } } } }); } </script> You will need a student account to test as this will not hide the widget if the user is staff / admin. Code also attached for easy copy/paste - code.txt Paul Another Conkie Special!!!! You should be getting consultancy money from Frog!!!
pconkie Posted February 23, 2018 Posted February 23, 2018 At school i've just noticed that the ip address reported back by https://your-frog-url/ipaddress.php is no the external static address. Can you visit your link @mmclaughlin when you are on your school network and let me know what it says....
mmclaughlin Posted March 27, 2018 Author Posted March 27, 2018 So this worked, but it turns out that we have a range of IP addresses that we use in county and since we happen to have an internal server, these are what is used by Frog not the external IP address. So I need to adjust this to be an IP range instead of a static IP. Any suggestions?
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