Mr.Ben Posted March 25, 2013 Posted March 25, 2013 (edited) Hi Edugeekers, I'm looking to use a javascript in PaperCut to restrict students from colour printing when Staff are not in the classroom. So far I've managed this: //Script to restrict students colour printing to lessons only. function getMinutesSinceMidnight (hours, minutes) { return 60 * hours + minutes; } function printJobHook(inputs, actions) { //Variable for Job Submission time var jobtime = getMinutesSinceMidnight (hours, minutes); //Variables to set the start and end times here var schoolstart = getMinutesSinceMidnight(9, 0); var schoolend = getMinutesSinceMidnight(15, 45); var breakstart = getMinutesSinceMidnight(10, 45); var breakend = getMinutesSinceMidnight(11, 0); var lunchstart = getMinutesSinceMidnight(12, 45); var lunchend = getMinutesSinceMidnight(13, 45); //Variables to define times to deny jobs var schoolcloseddeny = (schoolstart <= jobtime && jobtime <= schoolend); var breakdeny = (breakstart <= jobtime && jobtime <= breakend); var lunchdeny =(lunchstart <= jobtime && jobtime <= lunchend); if (inputs.user.isInGroup("Printing_Students")) && (schoolcloseddeny || breakdeny || lunchdeny) { actions.job.cancel(); // send message to the user's client tool actions.client.sendMessage('No Colour Jobs can be printed outside of timetabled periods'); // log a message for debugging actions.log.debug('Canceling job from user ' + inputs.job.username + 'because of colour print time restrictions'); } } Have I got anything wrong here? All help is much appreciated! Ben Edited March 25, 2013 by Mr.Ben
featured_spectre Posted March 25, 2013 Posted March 25, 2013 It looks right to a point, but you need to declare all variables. 1
Mr.Ben Posted March 25, 2013 Author Posted March 25, 2013 (edited) I'm working from this example: PaperCut KB | Script for Time-Based Printer Access So I am assuming that PaperCut has defined 'hours' and 'minutes' as global variables, or are there other ones I need to declare? This is my first bit of Javascript for almost ten years, so be forgiving :-) Edited March 25, 2013 by Mr.Ben
featured_spectre Posted March 25, 2013 Posted March 25, 2013 Your schoolstart, schoolend etc. All should be declared if I am not mistaken. 1
plexer Posted March 25, 2013 Posted March 25, 2013 Not neccessarily the case that variables need to be defined before using them for the first time. Ben 2
Mr.Ben Posted March 25, 2013 Author Posted March 25, 2013 (edited) Just double checked with the power of Google: JavaScript Variables @plexer gets the bonus points! Edited March 25, 2013 by Mr.Ben
plexer Posted March 25, 2013 Posted March 25, 2013 Same in vbscript you can decalre them by assigning a value but if you use option explicit then you have to declare variables before you can assign values to them. Ben
Mr.Ben Posted March 25, 2013 Author Posted March 25, 2013 (edited) Just tried to validate it in Papercut and it failed - if (inputs.user.isInGroup("Printing_Students")) && (schoolcloseddeny || breakdeny || lunchdeny) { needs an extra pair of brackets: if ((inputs.user.isInGroup("Printing_Students")) && (schoolcloseddeny || breakdeny || lunchdeny)) { I will test in the morning to see results! Edited March 25, 2013 by Mr.Ben
Mr.Ben Posted March 26, 2013 Author Posted March 26, 2013 (edited) Script now works after a couple of other changes to the logic (the schoolcloseddeny var has been changed to an 'or' statement and I did have to define hours and minutes) //Script to restrict students printing to lessons only. By Ben Ford function getMinutesSinceMidnight(hours, minutes) { return 60 * hours + minutes; } function printJobHook(inputs, actions) { //Variable for Job Submission time var hours = inputs.job.date.getHours(); var minutes = inputs.job.date.getMinutes(); var jobtime = getMinutesSinceMidnight (hours, minutes); //Variables to set the start and end times in 24 hour format var schoolstart = getMinutesSinceMidnight(9, 0); //9am var schoolend = getMinutesSinceMidnight(15, 45); //3.45pm var breakstart = getMinutesSinceMidnight(10, 45); //10.45am var breakend = getMinutesSinceMidnight(11, 0); //11am var lunchstart = getMinutesSinceMidnight(12, 45); //12.45pm var lunchend = getMinutesSinceMidnight(13, 45); //1.45pm //Variables to define times to deny jobs var schoolcloseddeny = (schoolstart >= jobtime || jobtime >= schoolend); var breakdeny = (breakstart <= jobtime && jobtime <= breakend); var lunchdeny =(lunchstart <= jobtime && jobtime <= lunchend); if ((inputs.user.isInGroup("Printing_Students")) && ( schoolcloseddeny || breakdeny || lunchdeny )) { actions.job.cancel(); //Send message to the user's client tool actions.client.sendMessage('No Colour jobs can be printed outside of timetable periods'); //Log a message for debugging actions.log.debug('Canceling job from user ' + inputs.job.username + ' because of colour print time restrictions'); } } @papercut - One to add in as a recipe? Edited March 26, 2013 by Mr.Ben
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