var cmn=require("../$common.js"), fs=require("fs"), mkdirp=require("mkdirp"); var moddir; var dbdir=cmn.persistdir+"/zelfoverhoor"; mkdirp.sync(dbdir); var accounts=null; try { accounts=require("./accounts.json"); } catch (e) { console.error(e); } var SHUFFLE_QUESTIONS=false; // {: {q: "question", a: "answer"}} var questiondb={}; // {: {id, name, description, questions: []}} var questionsets={}; // {: []} var userlists={}; function uniqidstr(validp){ for(var len=6;;len++){ var str=""; for(var i=0;i0;i--){ j=Math.floor(Math.random()*(i+1)); v=a[i]; a[i]=a[j]; a[j]=v; } } function checkQsetJson(json,errfunc){ var qset; try { qset=JSON.parse(json); } catch(e){ errfunc("Invalid json received"); return null; } if(!qset.name||typeof qset.name!="string"|| !qset.description||typeof qset.description!="string"|| !qset.questions||!Array.isArray(qset.questions)){ errfunc("Invalid data received"); return null; } var i; for(i=0;i",req.params.id) .replace("/*###QUESTIONSET###*/",JSON.stringify(resset))); }); }); app.get("/zelfoverhoor/qsdata/:id",function(req,res){ var qset=questionsets[req.params.id]; if(qset==null){ res.status(404).send("ID not found"); return; } var list=[]; for(var i=0;i/g,req.authuser)); }); }); app.get("/zelfoverhoor/docent/sets",function(req,res){ if(userlists[req.authuser]==null){ userlists[req.authuser]=[]; } var ul=userlists[req.authuser]; var list=[]; for(var i=0;i