Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted (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 by Mr.Ben
Posted

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

Posted (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 by Mr.Ben
Posted (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 by Mr.Ben

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...