Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Time Restrictor

Is there a way to restrict access to a forum based on the computer's clock? I have my forum set up for my students and it is working great. But... I have a few of the munchkins who like to get on during class time when they shouldn't be on. Thoughts/suggestions?

Comments

  • Ban them.
  • I'll do it if I need to, but I'd prefer to have a "This Forum is Closed at this time" type message...
  • MarkMark Vanilla Staff
    I'd write an extension that redirects to the extensions page with your message during certain hours. Should be very very simple and easy to do. Something like:

    <?php /* Extension Name: Time Restrictor Extension Url: http://lussumo.com/docs/ Description: Closes the forum for certain periods of time. Version: 1.0 Author: Mark O'Sullivan Author Url: http://www.markosullivan.ca/ */ $CurrentHour = date("G"); $ClassHour = 13; // Assuming class is on from 1pm to 2pm if ($CurrentHour == $ClassHour) { if ($Context->SelfUrl != 'extension.php') { header('location: extension.php?PostBackAction=ForumClosed'); } else { $PostBackAction = ForceIncomingString('PostBackAction', ''); if ($PostBackAction == 'ForumClosed') $NoticeCollector->AddNotice('The forum is currently closed.'); } } ?>

    This is untested, but the theory is sound.
  • Thanks Mark, that sounds like something that should work. If anyone (or you if you are willing, Mark) can add onto this as I know _nothing_ about php, that would be great (or a little lesson, so I could learn something)

    I need to set certain times to be off limits, like 8:30 - 12:20 as well as 1:30-3:15 (that specific if possible). Except on weekends, when they can get on at anytime...

    Anyone want to do that for me/help me learn how to do that? *asks sheepishly*
  • I'll do that tomorrow and upload it if I can get to a computer, looks quite simple - good starting point mark O sullivan.
  • Try this..
    <?php /* Extension Name: Time Restrictor Extension Url: http://lussumo.com/docs/ Description: Closes the forum for certain periods of time. Version: 1.0 Author: Mark O'Sullivan Author Url: http://www.markosullivan.ca/ */ $CurrentHour = date('G'); $CurrentMinute = date('i'); $StartHour1 = '08'; $StartMinute1 = '30'; $EndHour1 = '12'; $EndMinute1 = '20'; $StartHour2 = '13'; $StartMinute2 = '15'; $EndHour2 = '15'; $EndMinute2 = '15'; if ((($CurrentHour == $StartHour1) && ($CurrentMinute > $StartMinute1)) || ($StartHour1 < $CurrentHour < $EndHour1) || (($CurrentHour == $EndHour1) && ($CurrentMinute < $EndMinute1)) || (($CurrentHour == $StartHour2) && ($CurrentMinute > $StartMinute2)) || ($StartHour2 < $CurrentHour < $EndHour2) || (($CurrentHour == $EndHour2) && ($CurrentMinute < $EndMinute2))) { if ($Context->SelfUrl != 'extension.php') { header('location: extension.php?PostBackAction=ForumClosed'); } else { $PostBackAction = ForceIncomingString('PostBackAction', ''); if ($PostBackAction == 'ForumClosed') $NoticeCollector->AddNotice('The forum is currently closed.'); } } ?>

    I'm pretty sure there should be a more efficient/sensible/whatever way to do it (and a way to have a dynamic number of periods of time) but that should do the job and I don't want to tax my brain too much for the evening...
  • I tried the above code, but there was an error on line 23 (on the less than symbol). Any other thoughts?

    Meadow, I'm still holding my breath for your answer tomorrow. :)
  • I think what he means for "($StartHour1 < $CurrentHour < $EndHour1)" is the the current hour is between the start and end hour. This should be:

    ( $CurrentHour > $StartHour1 && $CurrentHour < $EndHour1)

    You would also need to change "($StartHour2 < $CurrentHour < $EndHour2)" to:

    ( $CurrentHour > $StartHour2 && $CurrentHour < $EndHour2)
  • That worked for me. Awesome.
  • You are my hero. It works great. One last request? (This is inspiring me to try to learn a bit about php)

    I want them to be able to get on to the forum anytime on the weekend. How do I disable the restriction on Sat. and Sun.?
  • edited October 2006
    To allow them on during saturday and sunday, put this code before all the variables are defined:
    $day=date(D); $allow_day1="Sat"; $allow_day2="Sun"; if($day!=$allow_day1 && $day!=$allow_day2){

    And then at the end of all the code (before ?>), put this:

    }

    This basicly means that if it isn't saturday or sunday it will run the main part of the code, and if it is saturday or sunday, it won't do anything.
  • Although I don't see a use for it now but I like it ...
  • Hum, you cant use 'between' statements in php? That's new to me. Cheers for clearing that up though guys. And sorry I forgot about the weekends thing..got a bit carried away. Glad it's all working for you though.
  • My use is for my middle school students who aren't mature enough yet to be left alone and trusted to do the right thing in other classes (not all of them, but a good handfull). So I need to turn off the forum during class time. This looks like it should work well. Thanks Minisweeper. meadow, mark, and jim. I really appreciate it.
  • Just in case anyone else wants to use this in the future, you have to change this:
    $day=date(D);
    to this:
    $day=date('D');

    Look! I did my first php thingy.... I fixed an error! I know. simple stuff...
  • edited October 2006
    I've created the main part of a dynamic script, which works off a database, but I can't figure out how to add configuration options to the settings panel, could some one just give me some basic code to add text to the settings panel, or I could post what I have already on the internet and someone could create the configuration bit themselves.
This discussion has been closed.