ChrisJ
(Fresh Scripter)
2006-09-22 12:57 PM
MOTD script

I want to send a message of the day as a pop up message on login at a school split across two sites. We need to have different messages for different groups of students/staff/locations.

My idea was to create a folder available to staff for them to add text files to, one message per file. This way I can expire files based on their date so that we don't get old messages appearing.

Does anyone have anything vaguely similar I could build on?

ChrisJ


Gargoyle
(MM club member)
2006-09-22 02:36 PM
Re: MOTD script

There are alot of different ways this could be done.
Off the top of my head...
Create your folders
Then to present random messages from that folder, build an array that contains the message file names.
At random pick one of the messages
Then using @Site (assuming that you have AD and there are two seperate sites) put the contents of the selected message into a messagebox.

Here is a logic flow, not by any means a working script
Code:

$Messages = DirPlus("\\server\messages","*.txt")
$Count = Ubound($Messages)
Select
Case @Site = "Site1"
$File = Rnd($Count)
$ = MessageBox($Messages[$File],"MOTD")
Case @Site = "Site2"
$File = Rnd($Count)
$ = MessageBox($Messages[$File],"MOTD")
Case1
$ = MessageBox("An error was encountered please contact the help desk", "Warning")
EndSelect



Björn
(Korg Regular)
2006-09-22 02:38 PM
Re: MOTD script

Garg; Doesn't MessageBox sit and wait for userinteraction before script execution continues? If it does it could prove a 'problem'.

Witto
(MM club member)
2006-09-22 03:37 PM
Re: MOTD script

Provide the 4th MessageBox parameter, Time-Out in seconds.
I presume to have really random MOTD's you will want to use SRnd() ?
I thought I read somewhere that using Rnd() without SRnd() does not really generate randoms.


Mart
(KiX Supporter)
2006-09-22 03:43 PM
Re: MOTD script

Quote:

Garg; Doesn't MessageBox sit and wait for userinteraction before script execution continues? If it does it could prove a 'problem'.




Yep it does but is also has a timeout option.


Richard H.Administrator
(KiX Supporter)
2006-09-22 03:52 PM
Re: MOTD script

Don't use RND. Use a modulo of the date, which will ensure different MOTD each day, but the same MOTD for eveyone on that day.

This came up only recently, so search recent posts for the solution.


Mart
(KiX Supporter)
2006-09-22 03:55 PM
Re: MOTD script

You could setup a message of the day source file in ini format. This way it will be quite easy to read the message for that day.

Les
(KiX Master)
2006-09-22 04:01 PM
Re: MOTD script

Quote:

Yep it does but is also has a timeout option.



But the timer stops if focus is lost.

While I am a staunch believer that logon scripts should neither be seen nor heard, if you really do want to annoy users, at least separate the message from the script by spawning it in the web browser. Users tend to view the message as just slowing them down during logon and will simply stop logging off.


Richard H.Administrator
(KiX Supporter)
2006-09-22 04:05 PM
Re: MOTD script

Here is that discussion thread I referred to: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=162749&an=&page=&vc=1

Witto
(MM club member)
2006-09-22 05:28 PM
Re: MOTD script

Quote:


While I am a staunch believer that logon scripts should neither be seen nor heard




Me too


Gargoyle
(MM club member)
2006-09-22 06:02 PM
Re: MOTD script

Quote:


Use a modulo of the date



Care to explain how this is done?


Les
(KiX Master)
2006-09-22 06:19 PM
Re: MOTD script

If you read the rest of his post, he goes on to say "This came up only recently, so search recent posts for the solution".
How hard can it be?
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Board=UBB1&Number=162841


Gargoyle
(MM club member)
2006-09-22 06:31 PM
Re: MOTD script

Yes how to implement it, but not the how the modulus works, for those of us without a major in mathematics, it can be difficult to understand without the plain english explanation.

masken
(MM club member)
2006-09-22 06:36 PM
Re: MOTD script

Another idea, change the IE home page if possible. Or just start an IE session pointing to the right page.... ie, http://intranet/2006-09-22.htm

Or perhaps there isn't any need for formatting etc?


Les
(KiX Master)
2006-09-22 07:06 PM
Re: MOTD script

No, I meant the searching bit.

Richard H.Administrator
(KiX Supporter)
2006-09-25 09:53 AM
Re: MOTD script

Quote:

Yes how to implement it, but not the how the modulus works, for those of us without a major in mathematics, it can be difficult to understand without the plain english explanation.




The link provided gives a working script.

As for the maths, it's very simple. You start with a big number (let's call it D), divide by a smaller number (lets call it Q) and take the remainder. The remainder is always going to be between 0 and Q-1. As D increases by 1, so the remainder will increase by 1. This remainder is also known as the modulus.

Here is an example. Lets start D and Q both at 3 and see what the effect of increasing D is:

Quote:

When D is 3 (D mod Q) is 0
When D is 4 (D mod Q) is 1
When D is 5 (D mod Q) is 2
When D is 6 (D mod Q) is 0
When D is 7 (D mod Q) is 1
When D is 8 (D mod Q) is 2
When D is 9 (D mod Q) is 0




So how does this help? Well, assume that "D" represents Date, and "Q" represents "Quotes". This gives us a really simple way of going through the quotes in a linear fashion. All you need to do is get the date in a numeric format.

There are a number of "serial date" functions to convert dates into an internal format that you can use in maths, but you don't really need them.

Here is one very simple way of determining the quote:
Code:
Break ON

$Q=12345 ; Number of quotes
$D=CDbl(Join(Split(@DATE,"/"),"")) ; Convert date to a number

"Number of quotes : "+$Q+@CRLF
"Today : "+@DATE+@CRLF
"Today as a number : "+$D+@CRLF
@CRLF
"Quote for today is : "+($D mod $Q)+@CRLF



See, I told you it was simple

The only drawback to using this method is that some quotes will be skipped on each cycle, however they will be picked up in later cycles so it is not an issue unless you are paranoid about all your quotes being displayed.

Don't forget that the result is between 0 and Q-1.


Gargoyle
(MM club member)
2006-09-25 02:18 PM
Re: MOTD script

Ok, I think I get the jist of it. Thanks for putting up with me