tracking.lib.php 279 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  4. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  5. /**
  6. * Class Tracking
  7. *
  8. * @author Julio Montoya <gugli100@gmail.com>
  9. * @package chamilo.library
  10. */
  11. class Tracking
  12. {
  13. /**
  14. * @param int $user_id
  15. * @param array $courseInfo
  16. * @param int $session_id
  17. * @param string $origin
  18. * @param bool $export_csv
  19. * @param int $lp_id
  20. * @param int $lp_item_id
  21. * @param int $extendId
  22. * @param int $extendAttemptId
  23. * @param string $extendedAttempt
  24. * @param string $extendedAll
  25. * @param string $type classic or simple
  26. * @return null|string
  27. */
  28. public static function getLpStats(
  29. $user_id,
  30. $courseInfo,
  31. $session_id,
  32. $origin,
  33. $export_csv,
  34. $lp_id,
  35. $lp_item_id = null,
  36. $extendId = null,
  37. $extendAttemptId = null,
  38. $extendedAttempt = null,
  39. $extendedAll = null,
  40. $type = 'classic'
  41. ) {
  42. if (empty($courseInfo) || empty($lp_id)) {
  43. return null;
  44. }
  45. $lp_id = intval($lp_id);
  46. $lp_item_id = intval($lp_item_id);
  47. $user_id = intval($user_id);
  48. $session_id = intval($session_id);
  49. $origin = Security::remove_XSS($origin);
  50. $list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
  51. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  52. $course_id = $courseInfo['real_id'];
  53. $courseCode = $courseInfo['code'];
  54. $session_condition = api_get_session_condition($session_id);
  55. // Extend all button
  56. $output = null;
  57. $extend_all = 0;
  58. if ($origin == 'tracking') {
  59. $url_suffix = '&session_id=' . $session_id . '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . $lp_id . '&origin=' . $origin;
  60. } else {
  61. $url_suffix = '&lp_id=' . $lp_id;
  62. }
  63. if (!empty($extendedAll)) {
  64. $extend_all_link = Display::url(
  65. Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')),
  66. api_get_self() . '?action=stats' . $url_suffix
  67. );
  68. $extend_all = 1;
  69. } else {
  70. $extend_all_link = Display::url(
  71. Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')),
  72. api_get_self() . '?action=stats&extend_all=1' . $url_suffix
  73. );
  74. }
  75. if ($origin != 'tracking') {
  76. $output .= Display::page_header(get_lang('ScormMystatus'));
  77. }
  78. $output .= '<table class="data_table">
  79. <tr>
  80. <th width="16">' . $extend_all_link . '</th>
  81. <th colspan="4">
  82. ' . get_lang('ScormLessonTitle') .'
  83. </th>
  84. <th colspan="2">
  85. ' . get_lang('ScormStatus') . '
  86. </th>
  87. <th colspan="2">
  88. ' . get_lang('ScormScore') . '
  89. </th>
  90. <th colspan="2">
  91. ' . get_lang('ScormTime') . '
  92. </th>
  93. <th>
  94. ' . get_lang('Actions') . '
  95. </th>
  96. </tr>';
  97. // Going through the items using the $items[] array instead of the database order ensures
  98. // we get them in the same order as in the imsmanifest file, which is rather random when using
  99. // the database table.
  100. $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
  101. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  102. $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
  103. $tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  104. $TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
  105. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  106. $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  107. $sql = "SELECT max(view_count)
  108. FROM $TBL_LP_VIEW
  109. WHERE
  110. c_id = $course_id AND
  111. lp_id = $lp_id AND
  112. user_id = $user_id
  113. $session_condition";
  114. $res = Database::query($sql);
  115. $view = '';
  116. if (Database :: num_rows($res) > 0) {
  117. $myrow = Database :: fetch_array($res);
  118. $view = $myrow[0];
  119. }
  120. $counter = 0;
  121. $total_time = 0;
  122. $h = get_lang('h');
  123. if (!empty($export_csv)) {
  124. $csv_content[] = array(
  125. get_lang('ScormLessonTitle'),
  126. get_lang('ScormStatus'),
  127. get_lang('ScormScore'),
  128. get_lang('ScormTime')
  129. );
  130. }
  131. $result_disabled_ext_all = true;
  132. $chapterTypes = learnpath::getChapterTypes();
  133. // Show lp items
  134. if (is_array($list) && count($list) > 0) {
  135. foreach ($list as $my_item_id) {
  136. $extend_this = 0;
  137. $order = 'DESC';
  138. if ((!empty($extendId) && $extendId == $my_item_id) || $extend_all) {
  139. $extend_this = 1;
  140. $order = 'ASC';
  141. }
  142. // Prepare statement to go through each attempt.
  143. $viewCondition = null;
  144. if (!empty($view)) {
  145. $viewCondition = " AND v.view_count = $view ";
  146. }
  147. $sql = "SELECT
  148. iv.status as mystatus,
  149. v.view_count as mycount,
  150. iv.score as myscore,
  151. iv.total_time as mytime,
  152. i.id as myid,
  153. i.lp_id as mylpid,
  154. iv.lp_view_id as mylpviewid,
  155. i.title as mytitle,
  156. i.max_score as mymaxscore,
  157. iv.max_score as myviewmaxscore,
  158. i.item_type as item_type,
  159. iv.view_count as iv_view_count,
  160. iv.id as iv_id,
  161. path
  162. FROM $TBL_LP_ITEM as i
  163. INNER JOIN $TBL_LP_ITEM_VIEW as iv
  164. ON (i.id = iv.lp_item_id AND i.c_id = $course_id AND iv.c_id = $course_id)
  165. INNER JOIN $TBL_LP_VIEW as v
  166. ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
  167. WHERE
  168. i.id = $my_item_id AND
  169. i.lp_id = $lp_id AND
  170. v.user_id = $user_id AND
  171. v.session_id = $session_id
  172. $viewCondition
  173. ORDER BY iv.view_count $order ";
  174. $result = Database::query($sql);
  175. $num = Database :: num_rows($result);
  176. $time_for_total = 'NaN';
  177. // Extend all
  178. if (($extend_this || $extend_all) && $num > 0) {
  179. $row = Database :: fetch_array($result);
  180. $result_disabled_ext_all = false;
  181. if ($row['item_type'] == 'quiz') {
  182. // Check results_disabled in quiz table.
  183. $my_path = Database::escape_string($row['path']);
  184. $sql = "SELECT results_disabled
  185. FROM $TBL_QUIZ
  186. WHERE
  187. c_id = $course_id AND
  188. id ='" . $my_path . "'";
  189. $res_result_disabled = Database::query($sql);
  190. $row_result_disabled = Database::fetch_row($res_result_disabled);
  191. if (Database::num_rows($res_result_disabled) > 0 &&
  192. (int) $row_result_disabled[0] === 1
  193. ) {
  194. $result_disabled_ext_all = true;
  195. }
  196. }
  197. // If there are several attempts, and the link to extend has been clicked, show each attempt...
  198. if (($counter % 2) == 0) {
  199. $oddclass = 'row_odd';
  200. } else {
  201. $oddclass = 'row_even';
  202. }
  203. $extend_link = '';
  204. if (!empty($inter_num)) {
  205. $extend_link = Display::url(
  206. Display::return_icon('visible.gif', get_lang('HideAttemptView')),
  207. api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix
  208. );
  209. }
  210. $title = $row['mytitle'];
  211. if (empty($title)) {
  212. $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
  213. }
  214. if (in_array($row['item_type'], $chapterTypes)) {
  215. $title = "<h4> $title </h4>";
  216. }
  217. $lesson_status = $row['mystatus'];
  218. $title = Security::remove_XSS($title);
  219. $counter++;
  220. if (in_array($row['item_type'], $chapterTypes)) {
  221. $output .= '<tr class="'.$oddclass.'">
  222. <td>'.$extend_link.'</td>
  223. <td colspan="4">
  224. '.$title.'
  225. </td>
  226. <td colspan="2">'.learnpathItem::humanize_status($lesson_status, true, $type).'</td>
  227. <td colspan="2"></td>
  228. <td colspan="2"></td>
  229. <td></td>
  230. </tr>';
  231. continue;
  232. } else {
  233. $output .= '<tr class="'.$oddclass.'">
  234. <td>'.$extend_link.'</td>
  235. <td colspan="4">
  236. '.$title.'
  237. </td>
  238. <td colspan="2"></td>
  239. <td colspan="2"></td>
  240. <td colspan="2"></td>
  241. <td></td>
  242. </tr>';
  243. }
  244. $attemptCount = 1;
  245. do {
  246. // Check if there are interactions below.
  247. $extend_attempt_link = '';
  248. $extend_this_attempt = 0;
  249. if ((learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 ||
  250. learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0) &&
  251. !$extend_all
  252. ) {
  253. if ($extendAttemptId == $row['iv_id']) {
  254. // The extend button for this attempt has been clicked.
  255. $extend_this_attempt = 1;
  256. $extend_attempt_link = Display::url(
  257. Display::return_icon('visible.gif', get_lang('HideAttemptView')),
  258. api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix
  259. );
  260. } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
  261. // The extend button for this attempt has not been clicked.
  262. $extend_attempt_link = Display::url(
  263. Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
  264. api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
  265. );
  266. }
  267. }
  268. if (($counter % 2) == 0) {
  269. $oddclass = 'row_odd';
  270. } else {
  271. $oddclass = 'row_even';
  272. }
  273. $lesson_status = $row['mystatus'];
  274. $score = $row['myscore'];
  275. $time_for_total = $row['mytime'];
  276. $time = learnpathItem :: getScormTimeFromParameter('js', $row['mytime']);
  277. if ($score == 0) {
  278. $maxscore = $row['mymaxscore'];
  279. } else {
  280. if ($row['item_type'] == 'sco') {
  281. if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
  282. $maxscore = $row['myviewmaxscore'];
  283. } elseif ($row['myviewmaxscore'] === '') {
  284. $maxscore = 0;
  285. } else {
  286. $maxscore = $row['mymaxscore'];
  287. }
  288. } else {
  289. $maxscore = $row['mymaxscore'];
  290. }
  291. }
  292. // Remove "NaN" if any (@todo: locate the source of these NaN)
  293. $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
  294. if ($row['item_type'] != 'dokeos_chapter') {
  295. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  296. $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  297. } else {
  298. switch ($row['item_type']) {
  299. case 'sco':
  300. if ($maxscore == 0) {
  301. $view_score = $score;
  302. } else {
  303. $view_score = show_score($score, $maxscore, false);
  304. }
  305. break;
  306. case 'document':
  307. $view_score = ($score == 0 ? '/' : show_score($score, $maxscore, false));
  308. break;
  309. default:
  310. $view_score = show_score($score, $maxscore, false);
  311. break;
  312. }
  313. }
  314. $output .= '<tr class="' . $oddclass . '">
  315. <td></td>
  316. <td>' . $extend_attempt_link . '</td>
  317. <td colspan="3">' . get_lang('Attempt') . ' ' . $attemptCount . '</td>
  318. <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
  319. <td colspan="2">' . $view_score . '</td>
  320. <td colspan="2">' . $time . '</td>
  321. <td></td>
  322. </tr>';
  323. $attemptCount++;
  324. if (!empty($export_csv)) {
  325. $temp = array();
  326. $temp[] = $title = Security::remove_XSS($title);
  327. $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false, $type));
  328. if ($row['item_type'] == 'quiz') {
  329. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  330. $temp[] = '/';
  331. } else {
  332. $temp[] = ($score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  333. }
  334. } else {
  335. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  336. }
  337. $temp[] = $time;
  338. $csv_content[] = $temp;
  339. }
  340. }
  341. $counter++;
  342. if ($extend_this_attempt OR $extend_all) {
  343. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  344. foreach ($list1 as $id => $interaction) {
  345. if (($counter % 2) == 0) {
  346. $oddclass = 'row_odd';
  347. } else {
  348. $oddclass = 'row_even';
  349. }
  350. $student_response = urldecode($interaction['student_response']);
  351. $content_student_response = explode('__|', $student_response);
  352. if (count($content_student_response) > 0) {
  353. if (count($content_student_response) >= 3) {
  354. // Pop the element off the end of array.
  355. array_pop($content_student_response);
  356. }
  357. $student_response = implode(',', $content_student_response);
  358. }
  359. $output .= '<tr class="'.$oddclass.'">
  360. <td></td>
  361. <td></td>
  362. <td></td>
  363. <td>'.$interaction['order_id'] . '</td>
  364. <td>'.$interaction['id'] . '</td>
  365. <td colspan="2">' . $interaction['type'].'</td>
  366. <td>'.$student_response . '</td>
  367. <td>'.$interaction['result'] . '</td>
  368. <td>'.$interaction['latency'] . '</td>
  369. <td>'.$interaction['time'] . '</td>
  370. <td></td>
  371. </tr>';
  372. $counter++;
  373. }
  374. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  375. foreach ($list2 as $id => $interaction) {
  376. if (($counter % 2) == 0) {
  377. $oddclass = 'row_odd';
  378. } else {
  379. $oddclass = 'row_even';
  380. }
  381. $output .= '<tr class="'.$oddclass.'">
  382. <td></td>
  383. <td></td>
  384. <td></td>
  385. <td>' . $interaction['order_id'] . '</td>
  386. <td colspan="2">' . $interaction['objective_id'] . '</td>
  387. <td colspan="2">' . $interaction['status'] .'</td>
  388. <td>' . $interaction['score_raw'] . '</td>
  389. <td>' . $interaction['score_max'] . '</td>
  390. <td>' . $interaction['score_min'] . '</td>
  391. <td></td>
  392. </tr>';
  393. $counter++;
  394. }
  395. }
  396. } while ($row = Database :: fetch_array($result));
  397. } elseif ($num > 0) {
  398. // Not extended.
  399. $row = Database :: fetch_array($result, 'ASSOC');
  400. $my_id = $row['myid'];
  401. $my_lp_id = $row['mylpid'];
  402. $my_lp_view_id = $row['mylpviewid'];
  403. $my_path = $row['path'];
  404. $result_disabled_ext_all = false;
  405. if ($row['item_type'] == 'quiz') {
  406. // Check results_disabled in quiz table.
  407. $my_path = Database::escape_string($my_path);
  408. $sql = "SELECT results_disabled
  409. FROM $TBL_QUIZ
  410. WHERE c_id = $course_id AND id ='" . $my_path . "'";
  411. $res_result_disabled = Database::query($sql);
  412. $row_result_disabled = Database::fetch_row($res_result_disabled);
  413. if (Database::num_rows($res_result_disabled) > 0 &&
  414. (int) $row_result_disabled[0] === 1
  415. ) {
  416. $result_disabled_ext_all = true;
  417. }
  418. }
  419. // Check if there are interactions below
  420. $extend_this_attempt = 0;
  421. $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
  422. $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
  423. $extend_attempt_link = '';
  424. if ($inter_num > 0 || $objec_num > 0) {
  425. if (!empty($extendAttemptId) && $extendAttemptId == $row['iv_id']) {
  426. // The extend button for this attempt has been clicked.
  427. $extend_this_attempt = 1;
  428. $extend_attempt_link = Display::url(
  429. Display::return_icon('visible.gif', get_lang('HideAttemptView')),
  430. api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix
  431. );
  432. } else {
  433. // Same case if fold_attempt_id is set, so not implemented explicitly.
  434. // The extend button for this attempt has not been clicked.
  435. $extend_attempt_link = Display::url(
  436. Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
  437. api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
  438. );
  439. }
  440. }
  441. if (($counter % 2) == 0) {
  442. $oddclass = 'row_odd';
  443. } else {
  444. $oddclass = 'row_even';
  445. }
  446. $extend_link = '';
  447. if ($inter_num > 1) {
  448. $extend_link = Display::url(
  449. Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
  450. api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
  451. );
  452. }
  453. $lesson_status = $row['mystatus'];
  454. $score = $row['myscore'];
  455. $subtotal_time = $row['mytime'];
  456. while ($tmp_row = Database :: fetch_array($result)) {
  457. $subtotal_time += $tmp_row['mytime'];
  458. }
  459. $title = $row['mytitle'];
  460. // Selecting the exe_id from stats attempts tables in order to look the max score value.
  461. $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
  462. WHERE
  463. exe_exo_id="' . $row['path'] . '" AND
  464. exe_user_id="' . $user_id . '" AND
  465. orig_lp_id = "' . $lp_id . '" AND
  466. orig_lp_item_id = "' . $row['myid'] . '" AND
  467. exe_cours_id="' . $courseCode . '" AND
  468. status <> "incomplete" AND
  469. session_id = ' . $session_id . '
  470. ORDER BY exe_date DESC limit 1';
  471. $resultLastAttempt = Database::query($sql);
  472. $num = Database :: num_rows($resultLastAttempt);
  473. $id_last_attempt = null;
  474. if ($num > 0) {
  475. while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
  476. $id_last_attempt = $rowLA['exe_id'];
  477. }
  478. }
  479. if ($score == 0) {
  480. $maxscore = $row['mymaxscore'];
  481. } else {
  482. if ($row['item_type'] == 'sco') {
  483. if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
  484. $maxscore = $row['myviewmaxscore'];
  485. } elseif ($row['myviewmaxscore'] === '') {
  486. $maxscore = 0;
  487. } else {
  488. $maxscore = $row['mymaxscore'];
  489. }
  490. } else {
  491. if ($row['item_type'] == 'quiz') {
  492. // Get score and total time from last attempt of a exercise en lp.
  493. $sql = "SELECT score
  494. FROM $TBL_LP_ITEM_VIEW
  495. WHERE
  496. c_id = $course_id AND
  497. lp_item_id = '" . (int) $my_id . "' AND
  498. lp_view_id = '" . (int) $my_lp_view_id . "'
  499. ORDER BY view_count DESC limit 1";
  500. $res_score = Database::query($sql);
  501. $row_score = Database::fetch_array($res_score);
  502. $sql = "SELECT SUM(total_time) as total_time
  503. FROM $TBL_LP_ITEM_VIEW
  504. WHERE
  505. c_id = $course_id AND
  506. lp_item_id = '" . (int) $my_id . "' AND
  507. lp_view_id = '" . (int) $my_lp_view_id . "'";
  508. $res_time = Database::query($sql);
  509. $row_time = Database::fetch_array($res_time);
  510. if (Database::num_rows($res_score) > 0 &&
  511. Database::num_rows($res_time) > 0
  512. ) {
  513. $score = (float) $row_score['score'];
  514. $subtotal_time = (int) $row_time['total_time'];
  515. } else {
  516. $score = 0;
  517. $subtotal_time = 0;
  518. }
  519. // Selecting the max score from an attempt.
  520. $sql = "SELECT SUM(t.ponderation) as maxscore
  521. FROM (
  522. SELECT distinct question_id, marks, ponderation
  523. FROM $tbl_stats_attempts as at INNER JOIN $tbl_quiz_questions as q
  524. ON (q.id = at.question_id AND q.c_id = $course_id
  525. )
  526. WHERE exe_id ='$id_last_attempt' ) as t";
  527. $result = Database::query($sql);
  528. $row_max_score = Database :: fetch_array($result);
  529. $maxscore = $row_max_score['maxscore'];
  530. } else {
  531. $maxscore = $row['mymaxscore'];
  532. }
  533. }
  534. }
  535. $time_for_total = $subtotal_time;
  536. $time = learnpathItem :: getScormTimeFromParameter('js', $subtotal_time);
  537. if (empty($title)) {
  538. $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
  539. }
  540. if (in_array($row['item_type'], $chapterTypes)) {
  541. $title = Security::remove_XSS($title);
  542. $output .= '<tr class="'.$oddclass.'">
  543. <td>'.$extend_link.'</td>
  544. <td colspan="4">
  545. <h4>'.$title.'</h4>
  546. </td>
  547. <td colspan="2">'.learnpathitem::humanize_status($lesson_status).'</td>
  548. <td colspan="2"></td>
  549. <td colspan="2"></td>
  550. <td></td>
  551. </tr>';
  552. } else {
  553. $correct_test_link = '-';
  554. if ($row['item_type'] == 'quiz') {
  555. $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . $origin;
  556. $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
  557. WHERE
  558. exe_exo_id="' . $row['path'] . '" AND
  559. exe_user_id="' . $user_id . '" AND
  560. orig_lp_id = "' . $lp_id . '" AND
  561. orig_lp_item_id = "' . $row['myid'] . '" AND
  562. exe_cours_id="' . $courseCode. '" AND
  563. status <> "incomplete" AND
  564. session_id = ' . $session_id . '
  565. ORDER BY exe_date DESC ';
  566. $resultLastAttempt = Database::query($sql);
  567. $num = Database :: num_rows($resultLastAttempt);
  568. if ($num > 0) {
  569. if ($extendedAttempt == 1 &&
  570. $lp_id == $my_lp_id &&
  571. $lp_item_id == $my_id
  572. ) {
  573. $correct_test_link = Display::url(
  574. Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')),
  575. api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id
  576. );
  577. } else {
  578. $correct_test_link = Display::url(
  579. Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttemptsByExercise')),
  580. api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id
  581. );
  582. }
  583. }
  584. }
  585. $title = Security::remove_XSS($title);
  586. if ($lp_id == $my_lp_id && false) {
  587. $output .= '<tr class =' . $oddclass . '>
  588. <td>' . $extend_link . '</td>
  589. <td colspan="4">' . $title . '</td>
  590. <td colspan="2">&nbsp;</td>
  591. <td colspan="2">&nbsp;</td>
  592. <td colspan="2">&nbsp;</td>
  593. <td>' . $correct_test_link . '</td>
  594. </tr>';
  595. $output .= '</tr>';
  596. } else {
  597. if ($lp_id == $my_lp_id && $lp_item_id == $my_id) {
  598. $output .= "<tr class='$oddclass'>";
  599. } else {
  600. $output .= "<tr class='$oddclass'>";
  601. }
  602. /*if (($is_allowed_to_edit || api_is_drh()) && isset($_GET['lp_id']) && isset($course_code)) {
  603. $lp = new learnpath($course_code, $_GET['lp_id'], api_get_user_id());
  604. $lp->set_course_int_id($course_id);
  605. $item_path_url = $lp->get_link('http', $my_id, false);
  606. $item_path_url .= "&width=600";
  607. $title = Display::url($title, $item_path_url, array('class' => 'ajax'));
  608. }*/
  609. $scoreItem = null;
  610. if ($row['item_type'] == 'quiz') {
  611. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  612. $scoreItem .= Display::return_icon(
  613. 'invisible.gif',
  614. get_lang('ResultsHiddenByExerciseSetting')
  615. );
  616. } else {
  617. $scoreItem .= show_score($score, $maxscore, false);
  618. }
  619. } else {
  620. $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore);
  621. }
  622. $output .= '<td>'.$extend_link.'</td>
  623. <td colspan="4">' . $title . '</td>
  624. <td colspan="2">' . learnpathitem::humanize_status($lesson_status) .'</td>
  625. <td colspan="2">'.$scoreItem.'</td>
  626. <td colspan="2">'.$time.'</td>
  627. <td>'.$correct_test_link.'</td>';
  628. $output .= '</tr>';
  629. }
  630. if (!empty($export_csv)) {
  631. $temp = array();
  632. $temp[] = api_html_entity_decode($title, ENT_QUOTES);
  633. $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES);
  634. if ($row['item_type'] == 'quiz') {
  635. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  636. $temp[] = '/';
  637. } else {
  638. $temp[] = ($score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  639. }
  640. } else {
  641. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  642. }
  643. $temp[] = $time;
  644. $csv_content[] = $temp;
  645. }
  646. }
  647. $counter++;
  648. if ($extend_this_attempt OR $extend_all) {
  649. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  650. foreach ($list1 as $id => $interaction) {
  651. if (($counter % 2) == 0) {
  652. $oddclass = 'row_odd';
  653. } else {
  654. $oddclass = 'row_even';
  655. }
  656. $output .= '<tr class="'.$oddclass.'">
  657. <td></td>
  658. <td></td>
  659. <td></td>
  660. <td>'.$interaction['order_id'].'</td>
  661. <td>'.$interaction['id'].'</td>
  662. <td colspan="2">' . $interaction['type'].'</td>
  663. <td>'.urldecode($interaction['student_response']).'</td>
  664. <td>'.$interaction['result'].'</td>
  665. <td>'.$interaction['latency'].'</td>
  666. <td>'.$interaction['time'].'</td>
  667. <td></td>
  668. </tr>';
  669. $counter++;
  670. }
  671. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  672. foreach ($list2 as $id => $interaction) {
  673. if (($counter % 2) == 0) {
  674. $oddclass = 'row_odd';
  675. } else {
  676. $oddclass = 'row_even';
  677. }
  678. $output .= '<tr class="'.$oddclass.'">
  679. <td></td>
  680. <td></td>
  681. <td></td>
  682. <td>' . $interaction['order_id'] . '</td>
  683. <td colspan="2">'.$interaction['objective_id'] . '</td>
  684. <td colspan="2">' . $interaction['status'] . '</td>
  685. <td>' . $interaction['score_raw'].'</td>
  686. <td>' . $interaction['score_max'] .'</td>
  687. <td>' . $interaction['score_min'].'</td>
  688. <td></td>
  689. </tr>';
  690. $counter++;
  691. }
  692. }
  693. // Attempts listing by exercise.
  694. if ($lp_id == $my_lp_id && $lp_item_id== $my_id && $extendedAttempt) {
  695. // Get attempts of a exercise.
  696. if (!empty($lp_id) && !empty($lp_item_id) && $row['item_type'] === 'quiz') {
  697. $sql = "SELECT path FROM $TBL_LP_ITEM
  698. WHERE
  699. c_id = $course_id AND
  700. id = '$lp_item_id' AND
  701. lp_id = '$lp_id'";
  702. $res_path = Database::query($sql);
  703. $row_path = Database::fetch_array($res_path);
  704. if (Database::num_rows($res_path) > 0) {
  705. $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
  706. WHERE
  707. exe_exo_id="' . (int) $row_path['path'] . '" AND
  708. status <> "incomplete" AND
  709. exe_user_id="' . $user_id . '" AND
  710. orig_lp_id = "' . (int) $lp_id . '" AND
  711. orig_lp_item_id = "' . (int) $lp_item_id . '" AND
  712. exe_cours_id="' . $courseCode . '" AND
  713. session_id = ' . $session_id . '
  714. ORDER BY exe_date';
  715. $res_attempts = Database::query($sql);
  716. $num_attempts = Database::num_rows($res_attempts);
  717. if ($num_attempts > 0) {
  718. $n = 1;
  719. while ($row_attempts = Database :: fetch_array($res_attempts)) {
  720. $my_score = $row_attempts['exe_result'];
  721. $my_maxscore = $row_attempts['exe_weighting'];
  722. $my_exe_id = $row_attempts['exe_id'];
  723. $my_orig_lp = $row_attempts['orig_lp_id'];
  724. $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
  725. $my_exo_exe_id = $row_attempts['exe_exo_id'];
  726. $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC');
  727. $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC');
  728. if ($mktime_start_date && $mktime_exe_date) {
  729. $mytime = ((int) $mktime_exe_date - (int) $mktime_start_date);
  730. $time_attemp = learnpathItem :: getScormTimeFromParameter('js', $mytime);
  731. $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
  732. } else {
  733. $time_attemp = ' - ';
  734. }
  735. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  736. $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  737. } else {
  738. // Show only float when need it
  739. if ($my_score == 0) {
  740. $view_score = show_score(0, $my_maxscore, false);
  741. } else {
  742. if ($my_maxscore == 0) {
  743. $view_score = $my_score;
  744. } else {
  745. $view_score = show_score($my_score, $my_maxscore, false);
  746. }
  747. }
  748. }
  749. $my_lesson_status = $row_attempts['status'];
  750. if ($my_lesson_status == '') {
  751. $my_lesson_status = learnpathitem::humanize_status('completed');
  752. } elseif ($my_lesson_status == 'incomplete') {
  753. $my_lesson_status = learnpathitem::humanize_status('incomplete');
  754. }
  755. $output .= '<tr class="' . $oddclass . '" >
  756. <td></td>
  757. <td>' . $extend_attempt_link . '</td>
  758. <td colspan="3">' . get_lang('Attempt').' '. $n.'</td>
  759. <td colspan="2">' . $my_lesson_status . '</td>
  760. <td colspan="2">'.$view_score . '</td>
  761. <td colspan="2">'.$time_attemp . '</td>';
  762. if ($origin != 'tracking') {
  763. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  764. $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></td>';
  765. } else {
  766. $output .= '<td><a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $courseCode . '" target="_parent">
  767. <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></a></td>';
  768. }
  769. } else {
  770. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  771. $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>';
  772. } else {
  773. $output .= '<td><a href="../exercice/exercise_show.php?cidReq=' . $courseCode . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent">
  774. <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
  775. }
  776. }
  777. $output .= '</tr>';
  778. $n++;
  779. }
  780. }
  781. $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
  782. }
  783. }
  784. }
  785. }
  786. $total_time += $time_for_total;
  787. // QUIZZ IN LP
  788. $a_my_id = array();
  789. if (!empty($my_lp_id)) {
  790. $a_my_id[] = $my_lp_id;
  791. }
  792. }
  793. }
  794. // NOT Extend all "left green cross"
  795. if (!empty($a_my_id)) {
  796. if ($extendedAttempt) {
  797. // "Right green cross" extended
  798. $total_score = self::get_avg_student_score(
  799. $user_id,
  800. $course_id,
  801. $a_my_id,
  802. $session_id,
  803. false,
  804. false
  805. );
  806. } else {
  807. // "Left green cross" extended
  808. $total_score = self::get_avg_student_score(
  809. $user_id,
  810. $course_id,
  811. $a_my_id,
  812. $session_id,
  813. false,
  814. true
  815. );
  816. }
  817. } else {
  818. // Extend all "left green cross"
  819. $total_score = self::get_avg_student_score(
  820. $user_id,
  821. $course_id,
  822. array($lp_id),
  823. $session_id,
  824. false,
  825. false
  826. );
  827. }
  828. $total_time = learnpathItem::getScormTimeFromParameter('js', $total_time);
  829. $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
  830. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  831. $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  832. } else {
  833. if (is_numeric($total_score)) {
  834. $final_score = $total_score . '%';
  835. } else {
  836. $final_score = $total_score;
  837. }
  838. }
  839. $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id);
  840. if (($counter % 2) == 0) {
  841. $oddclass = 'row_odd';
  842. } else {
  843. $oddclass = 'row_even';
  844. }
  845. $output .= '<tr class="'.$oddclass.'">
  846. <td></td>
  847. <td colspan="4">
  848. <i>' . get_lang('AccomplishedStepsTotal') .'</i>
  849. </td>
  850. <td colspan="2">'.$progress.'%</td>
  851. <td colspan="2">
  852. ' . $final_score.'
  853. </td>
  854. <td colspan="2">' . $total_time . '</div><td></td>
  855. </tr>';
  856. $output .= "</table>";
  857. if (!empty($export_csv)) {
  858. $temp = array(
  859. '',
  860. '',
  861. '',
  862. ''
  863. );
  864. $csv_content[] = $temp;
  865. $temp = array(
  866. get_lang('AccomplishedStepsTotal'),
  867. '',
  868. $final_score,
  869. $total_time
  870. );
  871. $csv_content[] = $temp;
  872. ob_end_clean();
  873. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  874. exit;
  875. }
  876. return $output;
  877. }
  878. /**
  879. * @param int $userId
  880. *
  881. * @return array
  882. */
  883. public static function getStats($userId)
  884. {
  885. $assignedCourses = array();
  886. if (api_is_drh() && api_drh_can_access_all_session_content()) {
  887. $studentList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  888. 'drh_all',
  889. $userId,
  890. false,
  891. null,
  892. null,
  893. null,
  894. null,
  895. null,
  896. null,
  897. null,
  898. array(),
  899. array(),
  900. STUDENT
  901. );
  902. $students = array();
  903. foreach ($studentList as $studentData) {
  904. $students[] = $studentData['user_id'];
  905. }
  906. $teacherList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  907. 'drh_all',
  908. $userId,
  909. false,
  910. null,
  911. null,
  912. null,
  913. null,
  914. null,
  915. null,
  916. null,
  917. array(),
  918. array(),
  919. COURSEMANAGER
  920. );
  921. $teachers = array();
  922. foreach ($teacherList as $teacherData) {
  923. $teachers[] = $teacherData['user_id'];
  924. }
  925. $humanResources = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  926. 'drh_all',
  927. $userId,
  928. false,
  929. null,
  930. null,
  931. null,
  932. null,
  933. null,
  934. null,
  935. null,
  936. array(),
  937. array(),
  938. DRH
  939. );
  940. $humanResourcesList = array();
  941. foreach ($humanResources as $item) {
  942. $humanResourcesList[] = $item['user_id'];
  943. }
  944. $platformCourses = SessionManager::getAllCoursesFollowedByUser(
  945. $userId,
  946. null,
  947. null,
  948. null,
  949. null,
  950. null
  951. );
  952. $courses = array();
  953. foreach ($platformCourses as $course) {
  954. $courses[$course['code']] = $course['code'];
  955. }
  956. $sessions = SessionManager::get_sessions_followed_by_drh($userId);
  957. } else {
  958. $studentList = UserManager::getUsersFollowedByUser(
  959. $userId,
  960. STUDENT,
  961. false,
  962. false,
  963. false,
  964. null,
  965. null,
  966. null,
  967. null,
  968. null,
  969. null,
  970. COURSEMANAGER
  971. );
  972. $students = array();
  973. foreach ($studentList as $studentData) {
  974. $students[] = $studentData['user_id'];
  975. }
  976. $teacherList = UserManager::getUsersFollowedByUser(
  977. $userId,
  978. COURSEMANAGER,
  979. false,
  980. false,
  981. false,
  982. null,
  983. null,
  984. null,
  985. null,
  986. null,
  987. null,
  988. COURSEMANAGER
  989. );
  990. $teachers = array();
  991. foreach ($teacherList as $teacherData) {
  992. $teachers[] = $teacherData['user_id'];
  993. }
  994. $humanResources = UserManager::getUsersFollowedByUser(
  995. $userId,
  996. DRH,
  997. false,
  998. false,
  999. false,
  1000. null,
  1001. null,
  1002. null,
  1003. null,
  1004. null,
  1005. null,
  1006. COURSEMANAGER
  1007. );
  1008. $humanResourcesList = array();
  1009. foreach ($humanResources as $item) {
  1010. $humanResourcesList[] = $item['user_id'];
  1011. }
  1012. $platformCourses = CourseManager::getCoursesFollowedByUser(
  1013. $userId,
  1014. COURSEMANAGER,
  1015. null,
  1016. null,
  1017. null,
  1018. null,
  1019. false,
  1020. null,
  1021. null,
  1022. true
  1023. );
  1024. foreach ($platformCourses as $course) {
  1025. $assignedCourses[$course['code']] = $course['code'];
  1026. }
  1027. $platformCourses = CourseManager::getCoursesFollowedByUser(
  1028. $userId,
  1029. COURSEMANAGER
  1030. );
  1031. foreach ($platformCourses as $course) {
  1032. $courses[$course['code']] = $course['code'];
  1033. }
  1034. $sessions = SessionManager::getSessionsFollowedByUser(
  1035. $userId,
  1036. COURSEMANAGER
  1037. );
  1038. }
  1039. return array(
  1040. 'drh' => $humanResourcesList,
  1041. 'teachers' => $teachers,
  1042. 'students' => $students,
  1043. 'courses' => $courses,
  1044. 'sessions' => $sessions,
  1045. 'assignedCourses' => $assignedCourses
  1046. );
  1047. }
  1048. /**
  1049. * Calculates the time spent on the platform by a user
  1050. * @param int|array User id
  1051. * @param string type of time filter: 'last_week' or 'custom'
  1052. * @param strgin start date date('Y-m-d H:i:s')
  1053. * @param strgin end date date('Y-m-d H:i:s')
  1054. * @return timestamp $nb_seconds
  1055. */
  1056. public static function get_time_spent_on_the_platform(
  1057. $userId,
  1058. $timeFilter = 'last_7_days',
  1059. $start_date = null,
  1060. $end_date = null
  1061. ) {
  1062. $tbl_track_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  1063. $condition_time = '';
  1064. if (is_array($userId)) {
  1065. $userList = array_map('intval', $userId);
  1066. $userCondition = " login_user_id IN ('".implode("','", $userList)."')";
  1067. } else {
  1068. $userCondition = " login_user_id = ".intval($userId);
  1069. }
  1070. if (empty($timeFilter)) {
  1071. $timeFilter = 'last_week';
  1072. }
  1073. $today = date('Y-m-d H:i:s');
  1074. switch ($timeFilter) {
  1075. case 'last_7_days':
  1076. $new_date = date('Y-m-d H:i:s', strtotime('-7 day'));
  1077. $condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
  1078. break;
  1079. case 'last_30_days':
  1080. $new_date = date('Y-m-d H:i:s', strtotime('-30 day'));
  1081. $condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
  1082. break;
  1083. case 'custom':
  1084. if (!empty($start_date) && !empty($end_date)) {
  1085. $start_date = Database::escape_string($start_date);
  1086. $end_date = Database::escape_string($end_date);
  1087. $condition_time = ' AND (login_date >= "'.$start_date.'" AND logout_date <= "'.$end_date.'" ) ';
  1088. }
  1089. break;
  1090. }
  1091. $sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff
  1092. FROM '.$tbl_track_login.'
  1093. WHERE '.$userCondition.$condition_time;
  1094. $rs = Database::query($sql);
  1095. $row = Database::fetch_array($rs, 'ASSOC');
  1096. $diff = $row['diff'];
  1097. if ($diff >= 0) {
  1098. return $diff;
  1099. } else {
  1100. return -1;
  1101. }
  1102. }
  1103. /**
  1104. * Calculates the time spent on the course
  1105. * @param integer $user_id
  1106. * @param string $course_code
  1107. * @param int Session id (optional)
  1108. *
  1109. * @return int Time in seconds
  1110. */
  1111. public static function get_time_spent_on_the_course($user_id, $course_code, $session_id = 0)
  1112. {
  1113. $course_code = Database::escape_string($course_code);
  1114. $session_id = intval($session_id);
  1115. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1116. if (is_array($user_id)) {
  1117. $user_id = array_map('intval', $user_id);
  1118. $condition_user = " AND user_id IN (".implode(',',$user_id).") ";
  1119. } else {
  1120. $user_id = intval($user_id);
  1121. $condition_user = " AND user_id = '$user_id' ";
  1122. }
  1123. $sql = "SELECT SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds
  1124. FROM $tbl_track_course
  1125. WHERE
  1126. UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) AND
  1127. course_code='$course_code' AND
  1128. session_id = '$session_id' $condition_user";
  1129. $rs = Database::query($sql);
  1130. $row = Database::fetch_array($rs);
  1131. return $row['nb_seconds'];
  1132. }
  1133. /**
  1134. * Get first connection date for a student
  1135. * @param int $student_id
  1136. *
  1137. * @return string|bool Date format long without day or false if there are no connections
  1138. */
  1139. public static function get_first_connection_date($student_id)
  1140. {
  1141. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  1142. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  1143. WHERE login_user_id = ' . intval($student_id) . '
  1144. ORDER BY login_date ASC LIMIT 0,1';
  1145. $rs = Database::query($sql);
  1146. if (Database::num_rows($rs)>0) {
  1147. if ($first_login_date = Database::result($rs, 0, 0)) {
  1148. return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1149. }
  1150. }
  1151. return false;
  1152. }
  1153. /**
  1154. * Get las connection date for a student
  1155. * @param int $student_id
  1156. * @param bool $warning_message Show a warning message (optional)
  1157. * @param bool $return_timestamp True for returning results in timestamp (optional)
  1158. * @return string|int|bool Date format long without day, false if there are no connections or
  1159. * timestamp if parameter $return_timestamp is true
  1160. */
  1161. public static function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false)
  1162. {
  1163. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  1164. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  1165. WHERE login_user_id = ' . intval($student_id) . '
  1166. ORDER BY login_date DESC LIMIT 0,1';
  1167. $rs = Database::query($sql);
  1168. if (Database::num_rows($rs) > 0) {
  1169. if ($last_login_date = Database::result($rs, 0, 0)) {
  1170. $last_login_date = api_get_local_time($last_login_date);
  1171. if ($return_timestamp) {
  1172. return api_strtotime($last_login_date,'UTC');
  1173. } else {
  1174. if (!$warning_message) {
  1175. return api_format_date($last_login_date, DATE_FORMAT_SHORT);
  1176. } else {
  1177. $timestamp = api_strtotime($last_login_date,'UTC');
  1178. $currentTimestamp = time();
  1179. //If the last connection is > than 7 days, the text is red
  1180. //345600 = 7 days in seconds
  1181. if ($currentTimestamp - $timestamp > 604800) {
  1182. return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
  1183. } else {
  1184. return api_format_date($last_login_date, DATE_FORMAT_SHORT);
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. return false;
  1191. }
  1192. /**
  1193. * Get las connection date for a student
  1194. * @param array $studentList Student id array
  1195. * @param int $days
  1196. * @param bool $getCount
  1197. * @return int
  1198. */
  1199. public static function getInactiveUsers($studentList, $days, $getCount = true)
  1200. {
  1201. if (empty($studentList)) {
  1202. return 0;
  1203. }
  1204. $days = intval($days);
  1205. $date = api_get_utc_datetime(strtotime($days.' days ago'));
  1206. $studentList = array_map('intval', $studentList);
  1207. $tbl_track_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  1208. $select = " SELECT login_user_id ";
  1209. if ($getCount) {
  1210. $select = " SELECT count(DISTINCT login_user_id) as count";
  1211. }
  1212. $sql = "$select
  1213. FROM $tbl_track_login
  1214. WHERE
  1215. login_user_id IN (' ". implode("','", $studentList) . "' ) AND
  1216. login_date < '$date'
  1217. ";
  1218. $rs = Database::query($sql);
  1219. if (Database::num_rows($rs) > 0) {
  1220. if ($getCount) {
  1221. $count = Database::fetch_array($rs);
  1222. return $count['count'];
  1223. }
  1224. return Database::store_result($rs, 'ASSOC');
  1225. }
  1226. return false;
  1227. }
  1228. /**
  1229. * Get first user's connection date on the course
  1230. * @param int User id
  1231. * @param string Course code
  1232. * @param int Session id (optional, default=0)
  1233. * @return string|bool Date with format long without day or false if there is no date
  1234. */
  1235. public static function get_first_connection_date_on_the_course(
  1236. $student_id,
  1237. $course_code,
  1238. $session_id = 0,
  1239. $convert_date = true
  1240. ) {
  1241. // protect data
  1242. $student_id = intval($student_id);
  1243. $course_code = Database::escape_string($course_code);
  1244. $session_id = intval($session_id);
  1245. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1246. $sql = 'SELECT login_course_date FROM '.$tbl_track_login.'
  1247. WHERE user_id = '.$student_id.'
  1248. AND course_code = "'.$course_code.'"
  1249. AND session_id = '.$session_id.'
  1250. ORDER BY login_course_date ASC LIMIT 0,1';
  1251. $rs = Database::query($sql);
  1252. if (Database::num_rows($rs) > 0) {
  1253. if ($first_login_date = Database::result($rs, 0, 0)) {
  1254. if ($convert_date) {
  1255. return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT);
  1256. } else {
  1257. return $first_login_date;
  1258. }
  1259. }
  1260. }
  1261. return false;
  1262. }
  1263. /**
  1264. * Get last user's connection date on the course
  1265. * @param int User id
  1266. * @param string Course code
  1267. * @param int Session id (optional, default=0)
  1268. * @return string|bool Date with format long without day or false if there is no date
  1269. */
  1270. public static function get_last_connection_date_on_the_course(
  1271. $student_id,
  1272. $course_code,
  1273. $session_id = 0,
  1274. $convert_date = true
  1275. ) {
  1276. // protect data
  1277. $student_id = intval($student_id);
  1278. $course_code = Database::escape_string($course_code);
  1279. $session_id = intval($session_id);
  1280. $tbl_track_e_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1281. $sql = 'SELECT access_date
  1282. FROM '.$tbl_track_e_access.'
  1283. WHERE access_user_id = '.$student_id.' AND
  1284. access_cours_code = "'.$course_code.'" AND
  1285. access_session_id = '.$session_id.'
  1286. ORDER BY access_date DESC
  1287. LIMIT 0,1';
  1288. $rs = Database::query($sql);
  1289. if (Database::num_rows($rs) > 0) {
  1290. if ($last_login_date = Database::result($rs, 0, 0)) {
  1291. if (empty($last_login_date) || $last_login_date == '0000-00-00 00:00:00') {
  1292. return false;
  1293. }
  1294. //$last_login_date_timestamp = api_strtotime($last_login_date, 'UTC');
  1295. //see #5736
  1296. $last_login_date_timestamp = api_strtotime($last_login_date);
  1297. $now = time();
  1298. //If the last connection is > than 7 days, the text is red
  1299. //345600 = 7 days in seconds
  1300. if ($now - $last_login_date_timestamp > 604800) {
  1301. if ($convert_date) {
  1302. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
  1303. $icon = api_is_allowed_to_edit() ? '<a href="'.api_get_path(REL_CODE_PATH).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'" title="'.get_lang('RemindInactiveUser').'"><img src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" /> </a>': null;
  1304. return $icon. Display::label($last_login_date, 'warning');
  1305. } else {
  1306. return $last_login_date;
  1307. }
  1308. } else {
  1309. if ($convert_date) {
  1310. return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
  1311. } else {
  1312. return $last_login_date;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. return false;
  1318. }
  1319. /**
  1320. * Get count of the connections to the course during a specified period
  1321. * @param string Course code
  1322. * @param int Session id (optional)
  1323. * @param int Datetime from which to collect data (defaults to 0)
  1324. * @param int Datetime to which to collect data (defaults to now)
  1325. * @return int count connections
  1326. */
  1327. public static function get_course_connections_count($course_code, $session_id = 0, $start = 0, $stop = null)
  1328. {
  1329. if ($start < 0) {
  1330. $start = 0;
  1331. }
  1332. if (!isset($stop) or ($stop < 0)) {
  1333. $stop = api_get_utc_datetime();
  1334. }
  1335. $start = Database::escape_string($start);
  1336. $stop = Database::escape_string($stop);
  1337. $month_filter = " AND login_course_date > '$start' AND login_course_date < '$stop' ";
  1338. $course_code = Database::escape_string($course_code);
  1339. $session_id = intval($session_id);
  1340. $count = 0;
  1341. $tbl_track_e_course_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1342. $sql = "SELECT count(*) as count_connections
  1343. FROM $tbl_track_e_course_access
  1344. WHERE
  1345. course_code = '$course_code' AND
  1346. session_id = $session_id
  1347. $month_filter";
  1348. $rs = Database::query($sql);
  1349. if (Database::num_rows($rs)>0) {
  1350. $row = Database::fetch_object($rs);
  1351. $count = $row->count_connections;
  1352. }
  1353. return $count;
  1354. }
  1355. /**
  1356. * Get count courses per student
  1357. * @param int Student id
  1358. * @param bool Include sessions (optional)
  1359. * @return int count courses
  1360. */
  1361. public static function count_course_per_student($user_id, $include_sessions = true)
  1362. {
  1363. $user_id = intval($user_id);
  1364. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1365. $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1366. $sql = 'SELECT DISTINCT course_code
  1367. FROM ' . $tbl_course_rel_user . '
  1368. WHERE user_id = ' . $user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH;
  1369. $rs = Database::query($sql);
  1370. $nb_courses = Database::num_rows($rs);
  1371. if ($include_sessions) {
  1372. $sql = 'SELECT DISTINCT course_code
  1373. FROM ' . $tbl_session_course_rel_user . '
  1374. WHERE id_user = ' . $user_id;
  1375. $rs = Database::query($sql);
  1376. $nb_courses += Database::num_rows($rs);
  1377. }
  1378. return $nb_courses;
  1379. }
  1380. /**
  1381. * Gets the score average from all tests in a course by student
  1382. *
  1383. * @param $student_id
  1384. * @param $course_code
  1385. * @param int $exercise_id
  1386. * @param null $session_id
  1387. * @param int $active_filter 2 for consider all tests
  1388. * 1 for active <> -1
  1389. * 0 for active <> 0
  1390. * @param int $into_lp 1 for all exercises
  1391. * 0 for without LP
  1392. * @internal param \Student $mixed id
  1393. * @internal param \Course $string code
  1394. * @internal param \Exercise $int id (optional), filtered by exercise
  1395. * @internal param \Session $int id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered
  1396. * @return string value (number %) Which represents a round integer about the score average.
  1397. */
  1398. public static function get_avg_student_exercise_score(
  1399. $student_id,
  1400. $course_code,
  1401. $exercise_id = 0,
  1402. $session_id = null,
  1403. $active_filter = 1,
  1404. $into_lp = 0
  1405. ) {
  1406. $course_code = Database::escape_string($course_code);
  1407. $course_info = api_get_course_info($course_code);
  1408. if (!empty($course_info)) {
  1409. // table definition
  1410. $tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  1411. $tbl_stats_exercise = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1412. // Compose a filter based on optional exercise given
  1413. $condition_quiz = "";
  1414. if (!empty($exercise_id)) {
  1415. $exercise_id = intval($exercise_id);
  1416. $condition_quiz =" AND id = $exercise_id ";
  1417. }
  1418. // Compose a filter based on optional session id given
  1419. $condition_session = "";
  1420. if (isset($session_id)) {
  1421. $session_id = intval($session_id);
  1422. $condition_session = " AND session_id = $session_id ";
  1423. }
  1424. if ($active_filter == 1) {
  1425. $condition_active = 'AND active <> -1';
  1426. } elseif ($active_filter == 0) {
  1427. $condition_active = 'AND active <> 0';
  1428. } else {
  1429. $condition_active = '';
  1430. }
  1431. $condition_into_lp = '';
  1432. $select_lp_id = '';
  1433. if ($into_lp == 0) {
  1434. $condition_into_lp = 'AND orig_lp_id = 0 AND orig_lp_item_id = 0';
  1435. } else {
  1436. $select_lp_id = ', orig_lp_id as lp_id ';
  1437. }
  1438. $sql = "SELECT count(id) FROM $tbl_course_quiz
  1439. WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz ";
  1440. $count_quiz = Database::fetch_row(Database::query($sql));
  1441. if (!empty($count_quiz[0]) && !empty($student_id)) {
  1442. if (is_array($student_id)) {
  1443. $student_id = array_map('intval', $student_id);
  1444. $condition_user = " AND exe_user_id IN (".implode(',', $student_id).") ";
  1445. } else {
  1446. $student_id = intval($student_id);
  1447. $condition_user = " AND exe_user_id = '$student_id' ";
  1448. }
  1449. if (empty($exercise_id)) {
  1450. $sql = "SELECT id FROM $tbl_course_quiz
  1451. WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz";
  1452. $result = Database::query($sql);
  1453. $exercise_list = array();
  1454. $exercise_id = null;
  1455. if (Database::num_rows($result)) {
  1456. while ($row = Database::fetch_array($result)) {
  1457. $exercise_list[] = $row['id'];
  1458. }
  1459. }
  1460. if (!empty($exercise_list)) {
  1461. $exercise_id = implode("','",$exercise_list);
  1462. }
  1463. }
  1464. $count_quiz = Database::fetch_row(Database::query($sql));
  1465. $sql = "SELECT
  1466. SUM(exe_result/exe_weighting*100) as avg_score,
  1467. COUNT(*) as num_attempts
  1468. $select_lp_id
  1469. FROM $tbl_stats_exercise
  1470. WHERE
  1471. exe_exo_id IN ('".$exercise_id."')
  1472. $condition_user AND
  1473. status = '' AND
  1474. exe_cours_id = '$course_code'
  1475. $condition_session
  1476. $condition_into_lp
  1477. ORDER BY exe_date DESC";
  1478. $res = Database::query($sql);
  1479. $row = Database::fetch_array($res);
  1480. $quiz_avg_score = null;
  1481. if (!empty($row['avg_score'])) {
  1482. $quiz_avg_score = round($row['avg_score'],2);
  1483. }
  1484. if(!empty($row['num_attempts'])) {
  1485. $quiz_avg_score = round($quiz_avg_score / $row['num_attempts'], 2);
  1486. }
  1487. if (is_array($student_id)) {
  1488. $quiz_avg_score = round($quiz_avg_score / count($student_id), 2);
  1489. }
  1490. if ($into_lp == 0) {
  1491. return $quiz_avg_score;
  1492. } else {
  1493. if (!empty($row['lp_id'])) {
  1494. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  1495. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  1496. $sql = "SELECT lp.name
  1497. FROM $tbl_lp as lp, $tbl_course as c
  1498. WHERE
  1499. c.code = '$course_code' AND
  1500. lp.id = ".$row['lp_id']." AND
  1501. lp.c_id = c.id
  1502. LIMIT 1;
  1503. ";
  1504. $result = Database::query($sql);
  1505. $row_lp = Database::fetch_row($result);
  1506. $lp_name = $row_lp[0];
  1507. return array($quiz_avg_score, $lp_name);
  1508. } else {
  1509. return array($quiz_avg_score, null);
  1510. }
  1511. }
  1512. }
  1513. }
  1514. return null;
  1515. }
  1516. /**
  1517. * Get count student's exercise COMPLETED attempts
  1518. * @param $student_id
  1519. * @param $course_code
  1520. * @param $exercise_id
  1521. * @param int $lp_id
  1522. * @param int $lp_item_id
  1523. * @param int $session_id
  1524. * @param int $find_all_lp 0 = just LP specified
  1525. * 1 = LP specified or whitout LP,
  1526. * 2 = all rows
  1527. * @internal param \Student $int id
  1528. * @internal param \Course $string code
  1529. * @internal param \Exercise $int id
  1530. * @internal param \Learning $int path id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required.
  1531. * @internal param \Learning $int path item id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required.
  1532. * @return int count of attempts
  1533. */
  1534. public static function count_student_exercise_attempts(
  1535. $student_id,
  1536. $course_code,
  1537. $exercise_id,
  1538. $lp_id = 0,
  1539. $lp_item_id = 0,
  1540. $session_id = 0,
  1541. $find_all_lp = 0
  1542. ) {
  1543. $course_code = Database::escape_string($course_code);
  1544. $student_id = intval($student_id);
  1545. $exercise_id = intval($exercise_id);
  1546. $session_id = intval($session_id);
  1547. $lp_id = intval($lp_id);
  1548. $lp_item_id = intval($lp_item_id);
  1549. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1550. $sql = "SELECT COUNT(ex.exe_id) as essais FROM $tbl_stats_exercices AS ex
  1551. WHERE ex.exe_cours_id = '$course_code'
  1552. AND ex.exe_exo_id = $exercise_id
  1553. AND status = ''
  1554. AND exe_user_id= $student_id
  1555. AND session_id = $session_id ";
  1556. if ($find_all_lp == 1) {
  1557. $sql .= "AND (orig_lp_id = $lp_id OR orig_lp_id = 0)
  1558. AND (orig_lp_item_id = $lp_item_id OR orig_lp_item_id = 0)";
  1559. } elseif ($find_all_lp == 0) {
  1560. $sql .= "AND orig_lp_id = $lp_id
  1561. AND orig_lp_item_id = $lp_item_id";
  1562. }
  1563. $rs = Database::query($sql);
  1564. $row = Database::fetch_row($rs);
  1565. $count_attempts = $row[0];
  1566. return $count_attempts;
  1567. }
  1568. /**
  1569. * Get count student's exercise progress
  1570. * @param int user id
  1571. * @param string course code
  1572. * @param int session id
  1573. */
  1574. public static function get_exercise_student_progress($exercise_list, $user_id, $course_code, $session_id)
  1575. {
  1576. $course_code = Database::escape_string($course_code);
  1577. $user_id = intval($user_id);
  1578. $session_id = intval($session_id);
  1579. if (empty($exercise_list)) {
  1580. return '0%';
  1581. }
  1582. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1583. $exercise_list = array_keys($exercise_list);
  1584. $exercise_list = array_map('intval', $exercise_list);
  1585. $exercise_list_imploded = implode("' ,'", $exercise_list);
  1586. $sql = "SELECT COUNT(DISTINCT ex.exe_exo_id) FROM $tbl_stats_exercices AS ex
  1587. WHERE ex.exe_cours_id = '$course_code' AND
  1588. ex.session_id = $session_id AND
  1589. ex.exe_user_id = $user_id AND ex.exe_exo_id IN ('$exercise_list_imploded') ";
  1590. $rs = Database::query($sql);
  1591. $count = 0;
  1592. if ($rs) {
  1593. $row = Database::fetch_row($rs);
  1594. $count = $row[0];
  1595. }
  1596. $count = ($count != 0 ) ? 100*round(intval($count)/count($exercise_list), 2) .'%' : '0%';
  1597. return $count;
  1598. }
  1599. /**
  1600. * @param array $exercise_list
  1601. * @param int $user_id
  1602. * @param string $course_code
  1603. * @param int $session_id
  1604. * @return string
  1605. */
  1606. public static function get_exercise_student_average_best_attempt($exercise_list, $user_id, $course_code, $session_id)
  1607. {
  1608. $result = 0;
  1609. if (!empty($exercise_list)) {
  1610. foreach ($exercise_list as $exercise_data) {
  1611. $exercise_id = $exercise_data['id'];
  1612. $best_attempt = get_best_attempt_exercise_results_per_user($user_id, $exercise_id , $course_code, $session_id);
  1613. if (!empty($best_attempt)) {
  1614. $result += $best_attempt['exe_result']/$best_attempt['exe_weighting'];
  1615. }
  1616. }
  1617. $result = $result/ count($exercise_list);
  1618. $result = round($result, 2)*100;
  1619. }
  1620. return $result.'%';
  1621. }
  1622. /**
  1623. * get teacher progress by course and session
  1624. * @param int course id
  1625. * @param int session id
  1626. * @return array
  1627. */
  1628. static function get_teachers_progress_by_course($courseId, $sessionId)
  1629. {
  1630. $course = api_get_course_info_by_id($courseId);
  1631. $sessionId = intval($sessionId);
  1632. $courseId = intval($courseId);
  1633. //get teachers
  1634. $sql = "SELECT scu.id_session, scu.id_user, s.name
  1635. FROM session_rel_course_rel_user scu, session s
  1636. WHERE
  1637. scu.id_session = s.id
  1638. AND scu.status = 2
  1639. AND scu.visibility = 1
  1640. AND scu.course_code = '%s'
  1641. AND scu.id_session = %s";
  1642. $query = sprintf($sql,$course['code'], $sessionId);
  1643. $rs = Database::query($query);
  1644. $teachers = array();
  1645. while ($teacher = Database::fetch_array($rs,'ASSOC')) {
  1646. $teachers[] = $teacher;
  1647. }
  1648. $data = array();
  1649. foreach ($teachers as $teacher) {
  1650. //total documents added
  1651. $sql = "SELECT count(*) as total
  1652. FROM c_item_property
  1653. WHERE lastedit_type = 'DocumentAdded'
  1654. AND c_id = %s
  1655. AND insert_user_id = %s
  1656. AND id_session = %s";
  1657. $query = sprintf($sql,
  1658. $courseId,
  1659. $teacher['id_user'],
  1660. $teacher['id_session']
  1661. );
  1662. $rs = Database::query($query);
  1663. $totalDocuments = 0;
  1664. if ($rs) {
  1665. $row = Database::fetch_row($rs);
  1666. $totalDocuments = $row[0];
  1667. }
  1668. //total links added
  1669. $sql = "SELECT count(*) as total
  1670. FROM c_item_property
  1671. WHERE lastedit_type = 'LinkAdded'
  1672. AND c_id = %s
  1673. AND insert_user_id = %s
  1674. AND id_session = %s";
  1675. $query = sprintf($sql,
  1676. $courseId,
  1677. $teacher['id_user'],
  1678. $teacher['id_session']
  1679. );
  1680. $rs = Database::query($query);
  1681. $totalLinks = 0;
  1682. if ($rs) {
  1683. $row = Database::fetch_row($rs);
  1684. $totalLinks = $row[0];
  1685. }
  1686. //total forums added
  1687. $sql = "SELECT count(*) as total
  1688. FROM c_item_property
  1689. WHERE lastedit_type = 'ForumthreadVisible'
  1690. AND c_id = %s
  1691. AND insert_user_id = %s
  1692. AND id_session = %s";
  1693. $query = sprintf($sql,
  1694. $courseId,
  1695. $teacher['id_user'],
  1696. $teacher['id_session']
  1697. );
  1698. $rs = Database::query($query);
  1699. $totalForums = 0;
  1700. if ($rs) {
  1701. $row = Database::fetch_row($rs);
  1702. $totalForums = $row[0];
  1703. }
  1704. //total wikis added
  1705. $sql = "SELECT COUNT(DISTINCT(ref)) as total
  1706. FROM c_item_property
  1707. WHERE lastedit_type = 'WikiAdded'
  1708. AND c_id = %s
  1709. AND insert_user_id = %s
  1710. AND id_session = %s";
  1711. $query = sprintf($sql,
  1712. $courseId,
  1713. $teacher['id_user'],
  1714. $teacher['id_session']
  1715. );
  1716. $rs = Database::query($query);
  1717. $totalWikis = 0;
  1718. if ($rs) {
  1719. $row = Database::fetch_row($rs);
  1720. $totalWikis = $row[0];
  1721. }
  1722. //total works added
  1723. $sql = "SELECT COUNT(*) as total
  1724. FROM c_item_property
  1725. WHERE lastedit_type = 'DirectoryCreated'
  1726. AND tool = 'work'
  1727. AND c_id = %s
  1728. AND insert_user_id = %s
  1729. AND id_session = %s";
  1730. $query = sprintf($sql,
  1731. $courseId,
  1732. $teacher['id_user'],
  1733. $teacher['id_session']
  1734. );
  1735. $rs = Database::query($query);
  1736. $totalWorks = 0;
  1737. if ($rs) {
  1738. $row = Database::fetch_row($rs);
  1739. $totalWorks = $row[0];
  1740. }
  1741. //total announcements added
  1742. $sql = "SELECT COUNT(*) as total
  1743. FROM c_item_property
  1744. WHERE lastedit_type = 'AnnouncementAdded'
  1745. AND c_id = %s
  1746. AND insert_user_id = %s
  1747. AND id_session = %s";
  1748. $query = sprintf($sql,
  1749. $courseId,
  1750. $teacher['id_user'],
  1751. $teacher['id_session']
  1752. );
  1753. $rs = Database::query($query);
  1754. $totalAnnouncements = 0;
  1755. if ($rs) {
  1756. $row = Database::fetch_row($rs);
  1757. $totalAnnouncements = $row[0];
  1758. }
  1759. $tutor = get_user_info_by_id($teacher['id_user']);
  1760. $data[] = array(
  1761. 'course' => $course['title'],
  1762. 'session' => $teacher['name'],
  1763. 'tutor' => $tutor['username'] . ' - ' . $tutor['lastname'] . ' ' . $tutor['firstname'],
  1764. 'documents' => $totalDocuments,
  1765. 'links' => $totalLinks,
  1766. 'forums' => $totalForums,
  1767. 'works' => $totalWorks,
  1768. 'wikis' => $totalWikis,
  1769. 'announcements' => $totalAnnouncements,
  1770. );
  1771. }
  1772. return $data;
  1773. }
  1774. /**
  1775. * Returns the average student progress in the learning paths of the given
  1776. * course.
  1777. * @param int|array $student_id
  1778. * @param string $course_code
  1779. * @param array $lp_ids Limit average to listed lp ids
  1780. * @param int $session_id Session id (optional),
  1781. * if parameter $session_id is null(default) it'll return results including
  1782. * sessions, 0 = session is not filtered
  1783. * @param bool $return_array Will return an array of the type:
  1784. * [sum_of_progresses, number] if it is set to true
  1785. * @return double Average progress of the user in this course
  1786. */
  1787. public static function get_avg_student_progress(
  1788. $student_id,
  1789. $course_code = null,
  1790. $lp_ids = array(),
  1791. $session_id = null,
  1792. $return_array = false
  1793. ) {
  1794. $conditions = array();
  1795. $session_id = intval($session_id);
  1796. // Get the information of the course.
  1797. $course_info = api_get_course_info($course_code);
  1798. if (!empty($course_info)) {
  1799. $conditions[] = " c_id = {$course_info['real_id']} ";
  1800. }
  1801. // table definition
  1802. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  1803. // Compose a filter based on optional learning paths list given
  1804. $condition_lp = null;
  1805. if (!empty($lp_ids)) {
  1806. if (count($lp_ids) > 0) {
  1807. $lp_ids = array_map('intval', $lp_ids);
  1808. $conditions[] = " lp_view.lp_id IN(".implode(',', $lp_ids).") ";
  1809. }
  1810. }
  1811. // If there is at least one learning path and one student.
  1812. if (!empty($student_id)) {
  1813. if (is_array($student_id)) {
  1814. $student_id = array_map('intval', $student_id);
  1815. $conditions[] = " lp_view.user_id IN (".implode(',', $student_id).") ";
  1816. } else {
  1817. $student_id = intval($student_id);
  1818. $conditions[] = " lp_view.user_id = '$student_id' ";
  1819. }
  1820. if (!empty($session_id)) {
  1821. $conditions[] = " session_id = $session_id ";
  1822. }
  1823. $conditionToString = implode('AND', $conditions);
  1824. // Get last view for each student (in case of multi-attempt)
  1825. // Also filter on LPs of this session
  1826. $sql = " SELECT
  1827. MAX(view_count),
  1828. AVG(progress) average,
  1829. SUM(progress) sum_progress,
  1830. count(progress) count_progress
  1831. FROM $tbl_course_lp_view lp_view
  1832. WHERE
  1833. $conditionToString
  1834. GROUP BY lp_id";
  1835. $result = Database::query($sql);
  1836. $row = Database::fetch_array($result, 'ASSOC');
  1837. if (!$return_array) {
  1838. $avg_progress = round($row['average'], 1);
  1839. return $avg_progress;
  1840. } else {
  1841. return array($row['sum_progress'], $row['count_progress']);
  1842. }
  1843. }
  1844. }
  1845. /**
  1846. * This function gets:
  1847. * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores.
  1848. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores.
  1849. * 3. And finally it will return the average between 1. and 2.
  1850. * @todo improve performance, when loading 1500 users with 20 lps the script dies
  1851. * This function does not take the results of a Test out of a LP
  1852. *
  1853. * @param mixed $student_id Array of user ids or an user id
  1854. * @param string $course_code
  1855. * @param array $lp_ids List of LP ids
  1856. * @param int $session_id Session id (optional),
  1857. * if param $session_id is null(default) it'll return results
  1858. * including sessions, 0 = session is not filtered
  1859. * @param bool $return_array Returns an array of the
  1860. * type [sum_score, num_score] if set to true
  1861. * @param bool $get_only_latest_attempt_results get only the latest attempts or ALL attempts
  1862. *
  1863. * @return string Value (number %) Which represents a round integer explain in got in 3.
  1864. */
  1865. public static function get_avg_student_score(
  1866. $student_id,
  1867. $course_code,
  1868. $lp_ids = array(),
  1869. $session_id = null,
  1870. $return_array = false,
  1871. $get_only_latest_attempt_results = false
  1872. ) {
  1873. $debug = false;
  1874. if (empty($lp_ids)) {
  1875. $debug = false;
  1876. }
  1877. if ($debug) echo '<h1>Tracking::get_avg_student_score</h1>';
  1878. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1879. $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1880. $course = api_get_course_info($course_code);
  1881. if (!empty($course)) {
  1882. // Get course tables names
  1883. $tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  1884. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  1885. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  1886. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  1887. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1888. $course_id = $course['real_id'];
  1889. // Compose a filter based on optional learning paths list given
  1890. $condition_lp = "";
  1891. if (count($lp_ids) > 0) {
  1892. $condition_lp =" AND id IN(".implode(',',$lp_ids).") ";
  1893. }
  1894. // Compose a filter based on optional session id
  1895. $session_id = intval($session_id);
  1896. if (count($lp_ids) > 0) {
  1897. $condition_session = " AND session_id = $session_id ";
  1898. } else {
  1899. $condition_session = " WHERE session_id = $session_id ";
  1900. }
  1901. // Check the real number of LPs corresponding to the filter in the
  1902. // database (and if no list was given, get them all)
  1903. if (empty($session_id)) {
  1904. $sql = "SELECT DISTINCT(id), use_max_score FROM $lp_table
  1905. WHERE c_id = $course_id AND session_id = 0 $condition_lp ";
  1906. } else {
  1907. $sql = "SELECT DISTINCT(id), use_max_score FROM $lp_table
  1908. WHERE c_id = $course_id $condition_lp ";
  1909. }
  1910. $res_row_lp = Database::query($sql);
  1911. $count_row_lp = Database::num_rows($res_row_lp);
  1912. $lp_list = $use_max_score = array();
  1913. while ($row_lp = Database::fetch_array($res_row_lp)) {
  1914. $lp_list[] = $row_lp['id'];
  1915. $use_max_score[$row_lp['id']] = $row_lp['use_max_score'];
  1916. }
  1917. if ($debug) {
  1918. echo 'Use max score or not list '; var_dump($use_max_score);
  1919. }
  1920. // prepare filter on users
  1921. if (is_array($student_id)) {
  1922. array_walk($student_id, 'intval');
  1923. $condition_user1 =" AND user_id IN (".implode(',', $student_id).") ";
  1924. } else {
  1925. $condition_user1 =" AND user_id = $student_id ";
  1926. }
  1927. if ($count_row_lp > 0 && !empty($student_id)) {
  1928. // Getting latest LP result for a student
  1929. //@todo problem when a course have more than 1500 users
  1930. $sql = "SELECT MAX(view_count) as vc, id, progress, lp_id, user_id
  1931. FROM $lp_view_table
  1932. WHERE c_id = $course_id AND
  1933. lp_id IN (".implode(',',$lp_list).")
  1934. $condition_user1 AND
  1935. session_id = $session_id
  1936. GROUP BY lp_id, user_id";
  1937. if ($debug) echo $sql;
  1938. $rs_last_lp_view_id = Database::query($sql);
  1939. $global_result = 0;
  1940. if (Database::num_rows($rs_last_lp_view_id) > 0) {
  1941. // Cycle through each line of the results (grouped by lp_id, user_id)
  1942. while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
  1943. $count_items = 0;
  1944. $lp_partial_total = 0;
  1945. $list = array();
  1946. $lp_view_id = $row_lp_view['id'];
  1947. $lp_id = $row_lp_view['lp_id'];
  1948. $user_id = $row_lp_view['user_id'];
  1949. if ($debug) echo '<h2>LP id '.$lp_id.'</h2>';
  1950. if ($get_only_latest_attempt_results) {
  1951. //Getting lp_items done by the user
  1952. $sql = "SELECT DISTINCT lp_item_id
  1953. FROM $lp_item_view_table
  1954. WHERE
  1955. c_id = $course_id AND
  1956. lp_view_id = $lp_view_id
  1957. ORDER BY lp_item_id";
  1958. $res_lp_item = Database::query($sql);
  1959. while ($row_lp_item = Database::fetch_array($res_lp_item,'ASSOC')) {
  1960. $my_lp_item_id = $row_lp_item['lp_item_id'];
  1961. // Getting the most recent attempt
  1962. $sql = "SELECT lp_iv.id as lp_item_view_id,
  1963. lp_iv.score as score,
  1964. lp_i.max_score,
  1965. lp_iv.max_score as max_score_item_view,
  1966. lp_i.path,
  1967. lp_i.item_type,
  1968. lp_i.id as iid
  1969. FROM $lp_item_view_table as lp_iv
  1970. INNER JOIN $lp_item_table as lp_i
  1971. ON lp_i.id = lp_iv.lp_item_id AND
  1972. lp_iv.c_id = $course_id AND
  1973. lp_i.c_id = $course_id AND
  1974. (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
  1975. WHERE
  1976. lp_item_id = $my_lp_item_id AND
  1977. lp_view_id = $lp_view_id
  1978. ORDER BY view_count DESC
  1979. LIMIT 1";
  1980. $res_lp_item_result = Database::query($sql);
  1981. while ($row_max_score = Database::fetch_array($res_lp_item_result,'ASSOC')) {
  1982. $list[]= $row_max_score;
  1983. }
  1984. }
  1985. } else {
  1986. // For the currently analysed view, get the score and
  1987. // max_score of each item if it is a sco or a TOOL_QUIZ
  1988. $sql = "SELECT
  1989. lp_iv.id as lp_item_view_id,
  1990. lp_iv.score as score,
  1991. lp_i.max_score,
  1992. lp_iv.max_score as max_score_item_view,
  1993. lp_i.path,
  1994. lp_i.item_type,
  1995. lp_i.id as iid
  1996. FROM $lp_item_view_table as lp_iv
  1997. INNER JOIN $lp_item_table as lp_i
  1998. ON lp_i.id = lp_iv.lp_item_id AND
  1999. lp_iv.c_id = $course_id AND
  2000. lp_i.c_id = $course_id AND
  2001. (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
  2002. WHERE lp_view_id = $lp_view_id ";
  2003. if ($debug) echo $sql.'<br />';
  2004. $res_max_score = Database::query($sql);
  2005. while ($row_max_score = Database::fetch_array($res_max_score,'ASSOC')) {
  2006. $list[]= $row_max_score;
  2007. }
  2008. }
  2009. // Go through each scorable element of this view
  2010. $score_of_scorm_calculate = 0;
  2011. foreach ($list as $row_max_score) {
  2012. // Came from the original lp_item
  2013. $max_score = $row_max_score['max_score'];
  2014. // Came from the lp_item_view
  2015. $max_score_item_view = $row_max_score['max_score_item_view'];
  2016. $score = $row_max_score['score'];
  2017. if ($debug) echo '<h3>Item Type: ' .$row_max_score['item_type'].'</h3>';
  2018. if ($row_max_score['item_type'] == 'sco') {
  2019. /* Check if it is sco (easier to get max_score)
  2020. when there's no max score, we assume 100 as the max score,
  2021. as the SCORM 1.2 says that the value should always be between 0 and 100.
  2022. */
  2023. if ($max_score == 0 || is_null($max_score) || $max_score == '') {
  2024. // Chamilo style
  2025. if ($use_max_score[$lp_id]) {
  2026. $max_score = 100;
  2027. } else {
  2028. // Overwrites max score = 100 to use the one that came in the lp_item_view see BT#1613
  2029. $max_score = $max_score_item_view;
  2030. }
  2031. }
  2032. // Avoid division by zero errors
  2033. if (!empty($max_score)) {
  2034. $lp_partial_total += $score/$max_score;
  2035. }
  2036. if ($debug) echo '<b>$lp_partial_total, $score, $max_score '.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />';
  2037. } else {
  2038. // Case of a TOOL_QUIZ element
  2039. $item_id = $row_max_score['iid'];
  2040. $item_path = $row_max_score['path'];
  2041. $lp_item_view_id = $row_max_score['lp_item_view_id'];
  2042. // Get last attempt to this exercise through
  2043. // the current lp for the current user
  2044. $sql = "SELECT exe_id
  2045. FROM $tbl_stats_exercices
  2046. WHERE
  2047. exe_exo_id = '$item_path' AND
  2048. exe_user_id = $user_id AND
  2049. orig_lp_item_id = $item_id AND
  2050. orig_lp_item_view_id = $lp_item_view_id AND
  2051. exe_cours_id = '$course_code' AND
  2052. session_id = $session_id
  2053. ORDER BY exe_date DESC
  2054. LIMIT 1";
  2055. if ($debug) echo $sql .'<br />';
  2056. $result_last_attempt = Database::query($sql);
  2057. $num = Database :: num_rows($result_last_attempt);
  2058. if ($num > 0 ) {
  2059. $id_last_attempt = Database :: result($result_last_attempt, 0, 0);
  2060. if ($debug) echo $id_last_attempt.'<br />';
  2061. // Within the last attempt number tracking, get the sum of
  2062. // the max_scores of all questions that it was
  2063. // made of (we need to make this call dynamic because of random questions selection)
  2064. $sql = "SELECT SUM(t.ponderation) as maxscore FROM
  2065. (
  2066. SELECT DISTINCT
  2067. question_id,
  2068. marks,
  2069. ponderation
  2070. FROM $tbl_stats_attempts AS at
  2071. INNER JOIN $tbl_quiz_questions AS q
  2072. ON (q.id = at.question_id)
  2073. WHERE
  2074. exe_id ='$id_last_attempt' AND
  2075. q.c_id = $course_id
  2076. )
  2077. AS t";
  2078. if ($debug) echo '$sql: '.$sql.' <br />';
  2079. $res_max_score_bis = Database::query($sql);
  2080. $row_max_score_bis = Database::fetch_array($res_max_score_bis);
  2081. if (!empty($row_max_score_bis['maxscore'])) {
  2082. $max_score = $row_max_score_bis['maxscore'];
  2083. }
  2084. if (!empty($max_score) && floatval($max_score) > 0) {
  2085. $lp_partial_total += $score/$max_score;
  2086. }
  2087. if ($debug) echo '$lp_partial_total, $score, $max_score <b>'.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />';
  2088. }
  2089. }
  2090. if (in_array($row_max_score['item_type'], array('quiz','sco'))) {
  2091. // Normal way
  2092. if ($use_max_score[$lp_id]) {
  2093. $count_items++;
  2094. } else {
  2095. if ($max_score != '') {
  2096. $count_items++;
  2097. }
  2098. }
  2099. if ($debug) echo '$count_items: '.$count_items;
  2100. }
  2101. } //end for
  2102. $score_of_scorm_calculate += $count_items ? (($lp_partial_total / $count_items) * 100) : 0;
  2103. if ($debug) echo '<h3>$count_items '.$count_items.'</h3>';
  2104. if ($debug) echo '<h3>$score_of_scorm_calculate '.$score_of_scorm_calculate.'</h3>';
  2105. $global_result += $score_of_scorm_calculate;
  2106. if ($debug) echo '<h3>$global_result '.$global_result.'</h3>';
  2107. } // end while
  2108. }
  2109. $lp_with_quiz = 0;
  2110. foreach ($lp_list as $lp_id) {
  2111. // Check if LP have a score we assume that all SCO have an score
  2112. $sql = "SELECT count(id) as count
  2113. FROM $lp_item_table
  2114. WHERE
  2115. c_id = $course_id AND
  2116. (item_type = 'quiz' OR item_type = 'sco') AND
  2117. lp_id = ".$lp_id;
  2118. if ($debug) echo $sql;
  2119. $result_have_quiz = Database::query($sql);
  2120. if (Database::num_rows($result_have_quiz) > 0 ) {
  2121. $row = Database::fetch_array($result_have_quiz,'ASSOC');
  2122. if (is_numeric($row['count']) && $row['count'] != 0) {
  2123. $lp_with_quiz++;
  2124. }
  2125. }
  2126. }
  2127. if ($debug) echo '<h3>$lp_with_quiz '.$lp_with_quiz.' </h3>';
  2128. if ($debug) echo '<h3>Final return</h3>';
  2129. if ($lp_with_quiz != 0) {
  2130. if (!$return_array) {
  2131. $score_of_scorm_calculate = round(($global_result/$lp_with_quiz),2);
  2132. if ($debug) var_dump($score_of_scorm_calculate);
  2133. if (empty($lp_ids)) {
  2134. if ($debug) echo '<h2>All lps fix: '.$score_of_scorm_calculate.'</h2>';
  2135. }
  2136. return $score_of_scorm_calculate;
  2137. } else {
  2138. if ($debug) var_dump($global_result, $lp_with_quiz);
  2139. return array($global_result, $lp_with_quiz);
  2140. }
  2141. } else {
  2142. return '-';
  2143. }
  2144. }
  2145. }
  2146. return null;
  2147. }
  2148. /**
  2149. * This function gets:
  2150. * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores.
  2151. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores.
  2152. * 3. And finally it will return the average between 1. and 2.
  2153. * This function does not take the results of a Test out of a LP
  2154. *
  2155. * @param int|array Array of user ids or an user id
  2156. * @param string Course code
  2157. * @param array List of LP ids
  2158. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  2159. * @param bool Returns an array of the type [sum_score, num_score] if set to true
  2160. * @param bool get only the latest attempts or ALL attempts
  2161. * @return string Value (number %) Which represents a round integer explain in got in 3.
  2162. */
  2163. public static function getAverageStudentScore(
  2164. $student_id,
  2165. $course_code = null,
  2166. $lp_ids = array(),
  2167. $session_id = null
  2168. ) {
  2169. if (empty($student_id)) {
  2170. return 0;
  2171. }
  2172. $conditions = array();
  2173. if (!empty($course_code)) {
  2174. $course = api_get_course_info($course_code);
  2175. $courseId = $course['real_id'];
  2176. $conditions[] = " c_id = $courseId";
  2177. }
  2178. // Get course tables names
  2179. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2180. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2181. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2182. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2183. // Compose a filter based on optional learning paths list given
  2184. if (!empty($lp_ids) && count($lp_ids) > 0) {
  2185. $conditions[] = " id IN(".implode(',', $lp_ids).") ";
  2186. }
  2187. // Compose a filter based on optional session id
  2188. $session_id = intval($session_id);
  2189. if (!empty($session_id)) {
  2190. $conditions[] = " session_id = $session_id ";
  2191. }
  2192. if (is_array($student_id)) {
  2193. array_walk($student_id, 'intval');
  2194. $conditions[] =" lp_view.user_id IN (".implode(',', $student_id).") ";
  2195. } else {
  2196. $conditions[] =" lp_view.user_id = $student_id ";
  2197. }
  2198. $conditionsToString = implode('AND ', $conditions);
  2199. $sql = "SELECT SUM(lp_iv.score) sum_score,
  2200. SUM(lp_i.max_score) sum_max_score,
  2201. count(*) as count
  2202. FROM $lp_table as lp
  2203. INNER JOIN $lp_item_table as lp_i
  2204. ON lp.id = lp_id AND lp.c_id = lp_i.c_id
  2205. INNER JOIN $lp_view_table as lp_view
  2206. ON lp_view.lp_id = lp_i.lp_id AND lp_view.c_id = lp_i.c_id
  2207. INNER JOIN $lp_item_view_table as lp_iv
  2208. ON lp_i.id = lp_iv.lp_item_id AND lp_view.c_id = lp_iv.c_id AND lp_iv.lp_view_id = lp_view.id
  2209. WHERE (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') AND
  2210. $conditionsToString
  2211. ";
  2212. $result = Database::query($sql);
  2213. $row = Database::fetch_array($result, 'ASSOC');
  2214. if (empty($row['sum_max_score'])) {
  2215. return 0;
  2216. }
  2217. return ($row['sum_score'] / $row['sum_max_score'])*100;
  2218. }
  2219. /**
  2220. * This function gets time spent in learning path for a student inside a course
  2221. * @param int|array Student id(s)
  2222. * @param string Course code
  2223. * @param array Limit average to listed lp ids
  2224. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  2225. * @return int Total time
  2226. */
  2227. public static function get_time_spent_in_lp($student_id, $course_code, $lp_ids = array(), $session_id = null)
  2228. {
  2229. $course = CourseManager :: get_course_information($course_code);
  2230. $student_id = intval($student_id);
  2231. $total_time = 0;
  2232. if (!empty($course)) {
  2233. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2234. $t_lpv = Database :: get_course_table(TABLE_LP_VIEW);
  2235. $t_lpiv = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2236. $course_id = $course['real_id'];
  2237. // Compose a filter based on optional learning paths list given
  2238. $condition_lp = "";
  2239. if(count($lp_ids) > 0) {
  2240. $condition_lp =" AND id IN(".implode(',',$lp_ids).") ";
  2241. }
  2242. // Compose a filter based on optional session id
  2243. $condition_session = "";
  2244. $session_id = intval($session_id);
  2245. if (isset($session_id)) {
  2246. $condition_session = " AND session_id = $session_id ";
  2247. }
  2248. // Check the real number of LPs corresponding to the filter in the
  2249. // database (and if no list was given, get them all)
  2250. //$res_row_lp = Database::query("SELECT DISTINCT(id) FROM $lp_table $condition_lp $condition_session");
  2251. $res_row_lp = Database::query("SELECT DISTINCT(id) FROM $lp_table WHERE c_id = $course_id $condition_lp");
  2252. $count_row_lp = Database::num_rows($res_row_lp);
  2253. // calculates time
  2254. if ($count_row_lp > 0) {
  2255. while ($row_lp = Database::fetch_array($res_row_lp)) {
  2256. $lp_id = intval($row_lp['id']);
  2257. $sql = 'SELECT SUM(total_time)
  2258. FROM '.$t_lpiv.' AS item_view
  2259. INNER JOIN '.$t_lpv.' AS view
  2260. ON item_view.lp_view_id = view.id
  2261. WHERE
  2262. item_view.c_id = '.$course_id.' AND
  2263. view.c_id = '.$course_id.' AND
  2264. view.lp_id = '.$lp_id.'
  2265. AND view.user_id = '.$student_id.' AND
  2266. session_id = '.$session_id;
  2267. $rs = Database::query($sql);
  2268. if (Database :: num_rows($rs) > 0) {
  2269. $total_time += Database :: result($rs, 0, 0);
  2270. }
  2271. }
  2272. }
  2273. }
  2274. return $total_time;
  2275. }
  2276. /**
  2277. * This function gets last connection time to one learning path
  2278. * @param int|array Student id(s)
  2279. * @param string Course code
  2280. * @param int Learning path id
  2281. * @return int Total time
  2282. */
  2283. public static function get_last_connection_time_in_lp($student_id, $course_code, $lp_id, $session_id = 0)
  2284. {
  2285. $course = CourseManager :: get_course_information($course_code);
  2286. $student_id = intval($student_id);
  2287. $lp_id = intval($lp_id);
  2288. $last_time = 0;
  2289. $session_id = intval($session_id);
  2290. if (!empty($course)) {
  2291. $course_id = $course['real_id'];
  2292. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2293. $t_lpv = Database :: get_course_table(TABLE_LP_VIEW);
  2294. $t_lpiv = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2295. // Check the real number of LPs corresponding to the filter in the
  2296. // database (and if no list was given, get them all)
  2297. $res_row_lp = Database::query("SELECT id FROM $lp_table WHERE c_id = $course_id AND id = $lp_id ");
  2298. $count_row_lp = Database::num_rows($res_row_lp);
  2299. // calculates last connection time
  2300. if ($count_row_lp > 0) {
  2301. $sql = 'SELECT MAX(start_time)
  2302. FROM ' . $t_lpiv . ' AS item_view
  2303. INNER JOIN ' . $t_lpv . ' AS view
  2304. ON item_view.lp_view_id = view.id
  2305. WHERE
  2306. item_view.c_id = '.$course_id.' AND
  2307. view.c_id = '.$course_id.' AND
  2308. view.lp_id = '.$lp_id.'
  2309. AND view.user_id = '.$student_id.'
  2310. AND view.session_id = '.$session_id;
  2311. $rs = Database::query($sql);
  2312. if (Database :: num_rows($rs) > 0) {
  2313. $last_time = Database :: result($rs, 0, 0);
  2314. }
  2315. }
  2316. }
  2317. return $last_time;
  2318. }
  2319. /**
  2320. * gets the list of students followed by coach
  2321. * @param int Coach id
  2322. * @return array List of students
  2323. */
  2324. public static function get_student_followed_by_coach($coach_id)
  2325. {
  2326. $coach_id = intval($coach_id);
  2327. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2328. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  2329. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  2330. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  2331. $a_students = array ();
  2332. // At first, courses where $coach_id is coach of the course //
  2333. $sql = 'SELECT id_session, course_code
  2334. FROM ' . $tbl_session_course_user . '
  2335. WHERE id_user=' . $coach_id.' AND status=2';
  2336. if (api_is_multiple_url_enabled()) {
  2337. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  2338. $access_url_id = api_get_current_access_url_id();
  2339. if ($access_url_id != -1) {
  2340. $sql = 'SELECT scu.id_session, scu.course_code
  2341. FROM ' . $tbl_session_course_user . ' scu
  2342. INNER JOIN '.$tbl_session_rel_access_url.' sru
  2343. ON (scu.id_session=sru.session_id)
  2344. WHERE
  2345. scu.id_user=' . $coach_id.' AND
  2346. scu.status=2 AND
  2347. sru.access_url_id = '.$access_url_id;
  2348. }
  2349. }
  2350. $result = Database::query($sql);
  2351. while ($a_courses = Database::fetch_array($result)) {
  2352. $course_code = $a_courses["course_code"];
  2353. $id_session = $a_courses["id_session"];
  2354. $sql = "SELECT distinct srcru.id_user
  2355. FROM $tbl_session_course_user AS srcru, $tbl_session_user sru
  2356. WHERE
  2357. srcru.id_user = sru.id_user AND
  2358. sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  2359. srcru.id_session = sru.id_session AND
  2360. srcru.course_code='$course_code' AND
  2361. srcru.id_session='$id_session'";
  2362. $rs = Database::query($sql);
  2363. while ($row = Database::fetch_array($rs)) {
  2364. $a_students[$row['id_user']] = $row['id_user'];
  2365. }
  2366. }
  2367. // Then, courses where $coach_id is coach of the session //
  2368. $sql = 'SELECT session_course_user.id_user
  2369. FROM ' . $tbl_session_course_user . ' as session_course_user
  2370. INNER JOIN '.$tbl_session_user.' sru ON session_course_user.id_user = sru.id_user AND session_course_user.id_session = sru.id_session
  2371. INNER JOIN ' . $tbl_session_course . ' as session_course
  2372. ON session_course.course_code = session_course_user.course_code
  2373. AND session_course_user.id_session = session_course.id_session
  2374. INNER JOIN ' . $tbl_session . ' as session
  2375. ON session.id = session_course.id_session
  2376. AND session.id_coach = ' . $coach_id;
  2377. if (api_is_multiple_url_enabled()) {
  2378. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  2379. $access_url_id = api_get_current_access_url_id();
  2380. if ($access_url_id != -1){
  2381. $sql = 'SELECT session_course_user.id_user
  2382. FROM ' . $tbl_session_course_user . ' as session_course_user
  2383. INNER JOIN '.$tbl_session_user.' sru
  2384. ON session_course_user.id_user = sru.id_user AND
  2385. session_course_user.id_session = sru.id_session
  2386. INNER JOIN ' . $tbl_session_course . ' as session_course
  2387. ON session_course.course_code = session_course_user.course_code AND
  2388. session_course_user.id_session = session_course.id_session
  2389. INNER JOIN ' . $tbl_session . ' as session
  2390. ON session.id = session_course.id_session AND
  2391. session.id_coach = ' . $coach_id.'
  2392. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  2393. ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id;
  2394. }
  2395. }
  2396. $result = Database::query($sql);
  2397. while ($row = Database::fetch_array($result)) {
  2398. $a_students[$row['id_user']] = $row['id_user'];
  2399. }
  2400. return $a_students;
  2401. }
  2402. /**
  2403. * Get student followed by a coach inside a session
  2404. * @param int Session id
  2405. * @param int Coach id
  2406. * @return array students list
  2407. */
  2408. public static function get_student_followed_by_coach_in_a_session($id_session, $coach_id)
  2409. {
  2410. $coach_id = intval($coach_id);
  2411. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2412. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  2413. $a_students = array ();
  2414. // At first, courses where $coach_id is coach of the course //
  2415. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_session="' . $id_session . '" AND id_user=' . $coach_id.' AND status=2';
  2416. $result = Database::query($sql);
  2417. while ($a_courses = Database::fetch_array($result)) {
  2418. $course_code = $a_courses["course_code"];
  2419. $sql = "SELECT distinct srcru.id_user
  2420. FROM $tbl_session_course_user AS srcru
  2421. WHERE
  2422. course_code='$course_code' AND
  2423. id_session = '" . $id_session . "'";
  2424. $rs = Database::query($sql);
  2425. while ($row = Database::fetch_array($rs)) {
  2426. $a_students[$row['id_user']] = $row['id_user'];
  2427. }
  2428. }
  2429. // Then, courses where $coach_id is coach of the session
  2430. $sql = 'SELECT id_coach FROM ' . $tbl_session . '
  2431. WHERE id="' . $id_session.'" AND id_coach="' . $coach_id . '"';
  2432. $result = Database::query($sql);
  2433. //He is the session_coach so we select all the users in the session
  2434. if (Database::num_rows($result) > 0) {
  2435. $sql = 'SELECT DISTINCT srcru.id_user
  2436. FROM ' . $tbl_session_course_user . ' AS srcru
  2437. WHERE id_session="' . $id_session . '"';
  2438. $result = Database::query($sql);
  2439. while ($row = Database::fetch_array($result)) {
  2440. $a_students[$row['id_user']] = $row['id_user'];
  2441. }
  2442. }
  2443. return $a_students;
  2444. }
  2445. /**
  2446. * Check if a coach is allowed to follow a student
  2447. * @param int Coach id
  2448. * @param int Student id
  2449. * @return bool
  2450. */
  2451. public static function is_allowed_to_coach_student($coach_id, $student_id)
  2452. {
  2453. $coach_id = intval($coach_id);
  2454. $student_id = intval($student_id);
  2455. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2456. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  2457. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  2458. // At first, courses where $coach_id is coach of the course //
  2459. $sql = 'SELECT 1 FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id .' AND status=2';
  2460. $result = Database::query($sql);
  2461. if (Database::num_rows($result) > 0) {
  2462. return true;
  2463. }
  2464. // Then, courses where $coach_id is coach of the session
  2465. $sql = 'SELECT session_course_user.id_user
  2466. FROM ' . $tbl_session_course_user . ' as session_course_user
  2467. INNER JOIN ' . $tbl_session_course . ' as session_course
  2468. ON session_course.course_code = session_course_user.course_code
  2469. INNER JOIN ' . $tbl_session . ' as session
  2470. ON session.id = session_course.id_session
  2471. AND session.id_coach = ' . $coach_id . '
  2472. WHERE id_user = ' . $student_id;
  2473. $result = Database::query($sql);
  2474. if (Database::num_rows($result) > 0) {
  2475. return true;
  2476. }
  2477. return false;
  2478. }
  2479. /**
  2480. * Get courses followed by coach
  2481. * @param int Coach id
  2482. * @param int Session id (optional)
  2483. * @return array Courses list
  2484. */
  2485. public static function get_courses_followed_by_coach($coach_id, $id_session = null)
  2486. {
  2487. $coach_id = intval($coach_id);
  2488. if (!empty($id_session)) {
  2489. $id_session = intval($id_session);
  2490. }
  2491. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2492. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  2493. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  2494. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  2495. // At first, courses where $coach_id is coach of the course.
  2496. $sql = 'SELECT DISTINCT course_code
  2497. FROM ' . $tbl_session_course_user . '
  2498. WHERE id_user = ' . $coach_id.' AND status = 2';
  2499. if (api_is_multiple_url_enabled()) {
  2500. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  2501. $access_url_id = api_get_current_access_url_id();
  2502. if ($access_url_id != -1){
  2503. $sql = 'SELECT DISTINCT scu.course_code
  2504. FROM ' . $tbl_session_course_user . ' scu
  2505. INNER JOIN '.$tbl_course_rel_access_url.' cru
  2506. ON (scu.course_code = cru.course_code)
  2507. WHERE
  2508. scu.id_user=' . $coach_id.' AND
  2509. scu.status=2 AND
  2510. cru.access_url_id = '.$access_url_id;
  2511. }
  2512. }
  2513. if (!empty($id_session)) {
  2514. $sql .= ' AND id_session=' . $id_session;
  2515. }
  2516. $courseList = array();
  2517. $result = Database::query($sql);
  2518. while ($row = Database::fetch_array($result)) {
  2519. $courseList[$row['course_code']] = $row['course_code'];
  2520. }
  2521. // Then, courses where $coach_id is coach of the session
  2522. $sql = 'SELECT DISTINCT session_course.course_code
  2523. FROM ' . $tbl_session_course . ' as session_course
  2524. INNER JOIN ' . $tbl_session . ' as session
  2525. ON session.id = session_course.id_session
  2526. AND session.id_coach = ' . $coach_id . '
  2527. INNER JOIN ' . $tbl_course . ' as course
  2528. ON course.code = session_course.course_code';
  2529. if (api_is_multiple_url_enabled()) {
  2530. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  2531. $access_url_id = api_get_current_access_url_id();
  2532. if ($access_url_id != -1){
  2533. $sql = 'SELECT DISTINCT session_course.course_code
  2534. FROM ' . $tbl_session_course . ' as session_course
  2535. INNER JOIN ' . $tbl_session . ' as session
  2536. ON session.id = session_course.id_session
  2537. AND session.id_coach = ' . $coach_id . '
  2538. INNER JOIN ' . $tbl_course . ' as course
  2539. ON course.code = session_course.course_code
  2540. INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
  2541. ON (session_course.course_code = course_rel_url.course_code)';
  2542. }
  2543. }
  2544. if (!empty ($id_session)) {
  2545. $sql .= ' WHERE session_course.id_session=' . $id_session;
  2546. if (api_is_multiple_url_enabled())
  2547. $sql .= ' AND access_url_id = '.$access_url_id;
  2548. } else {
  2549. if (api_is_multiple_url_enabled())
  2550. $sql .= ' WHERE access_url_id = '.$access_url_id;
  2551. }
  2552. $result = Database::query($sql);
  2553. while ($row = Database::fetch_array($result)) {
  2554. $courseList[$row['course_code']] = $row['course_code'];
  2555. }
  2556. return $courseList;
  2557. }
  2558. /**
  2559. * Get sessions coached by user
  2560. * @param $coach_id
  2561. * @param int $start
  2562. * @param int $limit
  2563. * @param bool $getCount
  2564. * @param null $keyword
  2565. * @return mixed
  2566. */
  2567. public static function get_sessions_coached_by_user(
  2568. $coach_id,
  2569. $start = 0,
  2570. $limit = 0,
  2571. $getCount = false,
  2572. $keyword = null
  2573. ) {
  2574. // table definition
  2575. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  2576. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2577. $coach_id = intval($coach_id);
  2578. $select = " SELECT * FROM ";
  2579. if ($getCount) {
  2580. $select = " SELECT count(DISTINCT id) as count FROM ";
  2581. }
  2582. $limitCondition = null;
  2583. if (!empty($start) && !empty($limit)) {
  2584. $limitCondition = " LIMIT ".intval($start).", ".intval($limit);
  2585. }
  2586. $keywordCondition = null;
  2587. if (!empty($keyword)) {
  2588. $keyword = Database::escape_string($keyword);
  2589. $keywordCondition = " AND (name LIKE '%$keyword%' ) ";
  2590. }
  2591. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  2592. $access_url_id = api_get_current_access_url_id();
  2593. $sql = "
  2594. $select
  2595. (
  2596. SELECT DISTINCT id, name, date_start, date_end
  2597. FROM $tbl_session session INNER JOIN $tbl_session_rel_access_url session_rel_url
  2598. ON (session.id = session_rel_url.session_id)
  2599. WHERE id_coach = $coach_id AND access_url_id = $access_url_id $keywordCondition
  2600. UNION
  2601. SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  2602. FROM $tbl_session as session
  2603. INNER JOIN $tbl_session_course_user as session_course_user
  2604. ON session.id = session_course_user.id_session AND
  2605. session_course_user.id_user= $coach_id AND
  2606. session_course_user.status=2
  2607. INNER JOIN $tbl_session_rel_access_url session_rel_url
  2608. ON (session.id = session_rel_url.session_id)
  2609. WHERE access_url_id = $access_url_id $keywordCondition
  2610. ) as sessions $limitCondition
  2611. ";
  2612. $rs = Database::query($sql);
  2613. if ($getCount) {
  2614. $row = Database::fetch_array($rs);
  2615. return $row['count'];
  2616. }
  2617. while ($row = Database::fetch_array($rs)) {
  2618. $a_sessions[$row["id"]] = $row;
  2619. }
  2620. if (is_array($a_sessions)) {
  2621. foreach ($a_sessions as & $session) {
  2622. if ($session['date_start'] == '0000-00-00') {
  2623. $session['status'] = get_lang('SessionActive');
  2624. }
  2625. else {
  2626. $date_start = explode('-', $session['date_start']);
  2627. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  2628. $date_end = explode('-', $session['date_end']);
  2629. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  2630. if ($time_start < time() && time() < $time_end) {
  2631. $session['status'] = get_lang('SessionActive');
  2632. } else {
  2633. if (time() < $time_start) {
  2634. $session['status'] = get_lang('SessionFuture');
  2635. } else {
  2636. if (time() > $time_end) {
  2637. $session['status'] = get_lang('SessionPast');
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. return $a_sessions;
  2645. }
  2646. /**
  2647. * Get courses list from a session
  2648. * @param int Session id
  2649. * @return array Courses list
  2650. */
  2651. public static function get_courses_list_from_session($session_id)
  2652. {
  2653. $session_id = intval($session_id);
  2654. // table definition
  2655. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  2656. $sql = 'SELECT DISTINCT course_code
  2657. FROM ' . $tbl_session_course . '
  2658. WHERE id_session=' . $session_id;
  2659. $rs = Database::query($sql);
  2660. $a_courses = array ();
  2661. while ($row = Database::fetch_array($rs)) {
  2662. $a_courses[$row['course_code']] = $row;
  2663. }
  2664. return $a_courses;
  2665. }
  2666. /**
  2667. * Count the number of documents that an user has uploaded to a course
  2668. * @param int|array Student id(s)
  2669. * @param string Course code
  2670. * @param int Session id (optional), if param $session_id is null(default) return count of assignments including sessions, 0 = session is not filtered
  2671. * @return int Number of documents
  2672. */
  2673. public static function count_student_uploaded_documents($student_id, $course_code, $session_id = null)
  2674. {
  2675. // get the information of the course
  2676. $a_course = CourseManager::get_course_information($course_code);
  2677. if (!empty($a_course)) {
  2678. // table definition
  2679. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2680. $tbl_document = Database :: get_course_table(TABLE_DOCUMENT);
  2681. $course_id = $a_course['real_id'];
  2682. if (is_array($student_id)) {
  2683. $studentList = array_map('intval', $student_id);
  2684. $condition_user = " AND ip.insert_user_id IN ('".implode(',', $studentList)."') ";
  2685. } else {
  2686. $student_id = intval($student_id);
  2687. $condition_user = " AND ip.insert_user_id = '$student_id' ";
  2688. }
  2689. $condition_session = null;
  2690. if (isset($session_id)) {
  2691. $session_id = intval($session_id);
  2692. $condition_session = " AND pub.session_id = $session_id ";
  2693. }
  2694. $sql = "SELECT count(ip.tool) AS count
  2695. FROM $tbl_item_property ip INNER JOIN $tbl_document pub
  2696. ON ip.ref = pub.id
  2697. WHERE ip.c_id = $course_id AND
  2698. pub.c_id = $course_id AND
  2699. pub.filetype ='file' AND
  2700. ip.tool = 'document'
  2701. $condition_user $condition_session ";
  2702. $rs = Database::query($sql);
  2703. $row = Database::fetch_row($rs);
  2704. return $row['count'];
  2705. }
  2706. return null;
  2707. }
  2708. /**
  2709. * Count assignments per student
  2710. * @param int|array Student id(s)
  2711. * @param string Course code
  2712. * @param int Session id (optional), if param $session_id is null(default) return count of assignments including sessions, 0 = session is not filtered
  2713. * @return int Count of assignments
  2714. */
  2715. public static function count_student_assignments($student_id, $course_code = null, $session_id = null)
  2716. {
  2717. if (empty($student_id)) {
  2718. return 0;
  2719. }
  2720. $conditions = array();
  2721. // Get the information of the course
  2722. $a_course = CourseManager::get_course_information($course_code);
  2723. if (!empty($a_course)) {
  2724. $course_id = $a_course['real_id'];
  2725. $conditions[]= " ip.c_id = $course_id AND pub.c_id = $course_id ";
  2726. }
  2727. // table definition
  2728. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2729. $tbl_student_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  2730. if (is_array($student_id)) {
  2731. $studentList = array_map('intval', $student_id);
  2732. $conditions[]= " ip.insert_user_id IN ('".implode("','", $studentList)."') ";
  2733. } else {
  2734. $student_id = intval($student_id);
  2735. $conditions[]= " ip.insert_user_id = '$student_id' ";
  2736. }
  2737. if (isset($session_id)) {
  2738. $session_id = intval($session_id);
  2739. $conditions[]= " pub.session_id = $session_id ";
  2740. }
  2741. $conditionToString = implode('AND', $conditions);
  2742. $sql = "SELECT count(ip.tool) as count
  2743. FROM $tbl_item_property ip
  2744. INNER JOIN $tbl_student_publication pub ON ip.ref = pub.id
  2745. WHERE
  2746. ip.tool='work' AND
  2747. $conditionToString";
  2748. $rs = Database::query($sql);
  2749. $row = Database::fetch_array($rs, 'ASSOC');
  2750. return $row['count'];
  2751. }
  2752. /**
  2753. * Count messages per student inside forum tool
  2754. * @param int|array Student id
  2755. * @param string Course code
  2756. * @param int Session id (optional), if param $session_id is
  2757. * null(default) return count of messages including sessions, 0 = session is not filtered
  2758. * @return int Count of messages
  2759. */
  2760. public static function count_student_messages($student_id, $courseCode = null, $session_id = null)
  2761. {
  2762. if (empty($student_id)) {
  2763. return 0;
  2764. }
  2765. $courseInfo = api_get_course_info($courseCode);
  2766. $courseCondition = null;
  2767. $conditions = array();
  2768. if (!empty($courseInfo)) {
  2769. $course_id = $courseInfo['real_id'];
  2770. $conditions[]= " post.c_id = $course_id AND forum.c_id = $course_id ";
  2771. }
  2772. // Table definition.
  2773. $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST);
  2774. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  2775. if (is_array($student_id)) {
  2776. $studentList = array_map('intval', $student_id);
  2777. $conditions[]= " post.poster_id IN ('".implode("','", $studentList)."') ";
  2778. } else {
  2779. $student_id = intval($student_id);
  2780. $conditions[]= " post.poster_id = '$student_id' ";
  2781. }
  2782. if (isset($session_id)) {
  2783. $session_id = intval($session_id);
  2784. $conditions[]= " forum.session_id = $session_id";
  2785. }
  2786. $conditionsToString = implode('AND ', $conditions);
  2787. $sql = "SELECT count(poster_id) as count
  2788. FROM $tbl_forum_post post INNER JOIN $tbl_forum forum
  2789. ON forum.forum_id = post.forum_id
  2790. WHERE $conditionsToString";
  2791. $rs = Database::query($sql);
  2792. $row = Database::fetch_array($rs, 'ASSOC');
  2793. $count = $row['count'];
  2794. return $count;
  2795. }
  2796. /**
  2797. * This function counts the number of post by course
  2798. * @param string Course code
  2799. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  2800. * @return int The number of post by course
  2801. */
  2802. public static function count_number_of_posts_by_course($course_code, $session_id = null)
  2803. {
  2804. $a_course = CourseManager :: get_course_information($course_code);
  2805. if (!empty($a_course)) {
  2806. $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST);
  2807. $tbl_forums = Database :: get_course_table(TABLE_FORUM);
  2808. $condition_session = '';
  2809. if (isset($session_id)) {
  2810. $session_id = intval($session_id);
  2811. $condition_session = ' AND f.session_id = '. $session_id;
  2812. }
  2813. $course_id = $a_course['real_id'];
  2814. $sql = "SELECT count(*) FROM $tbl_posts p INNER JOIN $tbl_forums f
  2815. ON f.forum_id = p.forum_id
  2816. WHERE p.c_id = $course_id AND
  2817. f.c_id = $course_id
  2818. $condition_session
  2819. ";
  2820. $result = Database::query($sql);
  2821. $row = Database::fetch_row($result);
  2822. $count = $row[0];
  2823. return $count;
  2824. } else {
  2825. return null;
  2826. }
  2827. }
  2828. /**
  2829. * This function counts the number of threads by course
  2830. * @param string Course code
  2831. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  2832. * @return int The number of threads by course
  2833. */
  2834. public static function count_number_of_threads_by_course($course_code, $session_id = null)
  2835. {
  2836. $course_info = api_get_course_info($course_code);
  2837. if (empty($course_info)) {
  2838. return null;
  2839. }
  2840. $course_id = $course_info['real_id'];
  2841. $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  2842. $tbl_forums = Database :: get_course_table(TABLE_FORUM);
  2843. $condition_session = '';
  2844. if (isset($session_id)) {
  2845. $session_id = intval($session_id);
  2846. $condition_session = ' AND f.session_id = '. $session_id;
  2847. }
  2848. $sql = "SELECT count(*) FROM $tbl_threads t INNER JOIN $tbl_forums f ON f.forum_id = t.forum_id
  2849. WHERE t.c_id = $course_id AND f.c_id = $course_id $condition_session ";
  2850. $result = Database::query($sql);
  2851. if (Database::num_rows($result)) {
  2852. $row = Database::fetch_row($result);
  2853. $count = $row[0];
  2854. return $count;
  2855. } else {
  2856. return null;
  2857. }
  2858. }
  2859. /**
  2860. * This function counts the number of forums by course
  2861. * @param string Course code
  2862. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  2863. * @return int The number of forums by course
  2864. */
  2865. public static function count_number_of_forums_by_course($course_code, $session_id = null)
  2866. {
  2867. $course_info = api_get_course_info($course_code);
  2868. if (empty($course_info)) {
  2869. return null;
  2870. }
  2871. $course_id = $course_info['real_id'];
  2872. $condition_session = '';
  2873. if (isset($session_id)) {
  2874. $session_id = intval($session_id);
  2875. $condition_session = ' session_id = '. $session_id;
  2876. }
  2877. $tbl_forums = Database :: get_course_table(TABLE_FORUM);
  2878. $sql = "SELECT count(*) FROM $tbl_forums WHERE c_id = $course_id AND $condition_session";
  2879. $result = Database::query($sql);
  2880. if (Database::num_rows($result)) {
  2881. $row = Database::fetch_row($result);
  2882. $count = $row[0];
  2883. return $count;
  2884. } else {
  2885. return null;
  2886. }
  2887. }
  2888. /**
  2889. * This function counts the chat last connections by course in x days
  2890. * @param string Course code
  2891. * @param int Last x days
  2892. * @param int Session id (optional)
  2893. * @return int Chat last connections by course in x days
  2894. */
  2895. public static function chat_connections_during_last_x_days_by_course($course_code, $last_days, $session_id = 0)
  2896. {
  2897. $course_info = api_get_course_info($course_code);
  2898. if (empty($course_info)) {
  2899. return null;
  2900. }
  2901. $course_id = $course_info['real_id'];
  2902. //protect data
  2903. $last_days = intval($last_days);
  2904. $course_code = Database::escape_string($course_code);
  2905. $session_id = intval($session_id);
  2906. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  2907. $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
  2908. AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."' AND access_session_id='$session_id' ";
  2909. $result = Database::query($sql);
  2910. if (Database::num_rows($result)) {
  2911. $row = Database::fetch_row($result);
  2912. $count = $row[0];
  2913. return $count;
  2914. } else {
  2915. return null;
  2916. }
  2917. }
  2918. /**
  2919. * This function gets the last student's connection in chat
  2920. * @param int Student id
  2921. * @param string Course code
  2922. * @param int Session id (optional)
  2923. * @return string datetime formatted without day (e.g: February 23, 2010 10:20:50 )
  2924. */
  2925. public static function chat_last_connection($student_id, $course_code, $session_id = 0)
  2926. {
  2927. $student_id = intval($student_id);
  2928. $course_code= Database::escape_string($course_code);
  2929. $session_id = intval($session_id);
  2930. $date_time = '';
  2931. // table definition
  2932. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  2933. $sql = "SELECT access_date
  2934. FROM $tbl_stats_access
  2935. WHERE
  2936. access_tool='".TOOL_CHAT."' AND
  2937. access_user_id='$student_id' AND
  2938. access_cours_code = '$course_code' AND
  2939. access_session_id = '$session_id'
  2940. ORDER BY access_date DESC limit 1";
  2941. $rs = Database::query($sql);
  2942. if (Database::num_rows($rs) > 0) {
  2943. $row = Database::fetch_array($rs);
  2944. $date_time = api_convert_and_format_date($row['access_date'], null, date_default_timezone_get());
  2945. }
  2946. return $date_time;
  2947. }
  2948. /**
  2949. * Get count student's visited links
  2950. * @param int Student id
  2951. * @param string Course code
  2952. * @param int Session id (optional)
  2953. * @return int count of visited links
  2954. */
  2955. public static function count_student_visited_links($student_id, $course_code, $session_id = 0)
  2956. {
  2957. // protect datas
  2958. $student_id = intval($student_id);
  2959. $course_code = Database::escape_string($course_code);
  2960. $session_id = intval($session_id);
  2961. // table definition
  2962. $tbl_stats_links = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  2963. $sql = 'SELECT 1
  2964. FROM '.$tbl_stats_links.'
  2965. WHERE
  2966. links_user_id= '.$student_id.' AND
  2967. links_cours_id = "'.$course_code.'" AND
  2968. links_session_id = '.$session_id.' ';
  2969. $rs = Database::query($sql);
  2970. return Database::num_rows($rs);
  2971. }
  2972. /**
  2973. * Get count student downloaded documents
  2974. * @param int Student id
  2975. * @param string Course code
  2976. * @param int Session id (optional)
  2977. * @return int Count downloaded documents
  2978. */
  2979. public static function count_student_downloaded_documents($student_id, $course_code, $session_id = 0)
  2980. {
  2981. // protect datas
  2982. $student_id = intval($student_id);
  2983. $course_code = Database::escape_string($course_code);
  2984. $session_id = intval($session_id);
  2985. // table definition
  2986. $tbl_stats_documents = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  2987. $sql = 'SELECT 1
  2988. FROM ' . $tbl_stats_documents . '
  2989. WHERE down_user_id = '.$student_id.'
  2990. AND down_cours_id = "'.$course_code.'"
  2991. AND down_session_id = '.$session_id.' ';
  2992. $rs = Database::query($sql);
  2993. return Database::num_rows($rs);
  2994. }
  2995. /**
  2996. * Get course list inside a session from a student
  2997. * @param int Student id
  2998. * @param int Session id (optional)
  2999. * @return array Courses list
  3000. */
  3001. public static function get_course_list_in_session_from_student($user_id, $id_session = 0)
  3002. {
  3003. $user_id = intval($user_id);
  3004. $id_session = intval($id_session);
  3005. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  3006. $sql = 'SELECT course_code
  3007. FROM ' . $tbl_session_course_user . '
  3008. WHERE
  3009. id_user="' . $user_id . '" AND
  3010. id_session="' . $id_session . '"';
  3011. $result = Database::query($sql);
  3012. $a_courses = array ();
  3013. while ($row = Database::fetch_array($result)) {
  3014. $a_courses[$row['course_code']] = $row['course_code'];
  3015. }
  3016. return $a_courses;
  3017. }
  3018. /**
  3019. * Get inactives students in course
  3020. * @param string Course code
  3021. * @param string Since login course date (optional, default = 'never')
  3022. * @param int Session id (optional)
  3023. * @return array Inactives users
  3024. */
  3025. public static function get_inactives_students_in_course($course_code, $since = 'never', $session_id=0)
  3026. {
  3027. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  3028. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  3029. $table_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  3030. $inner = '';
  3031. if ($session_id!=0) {
  3032. $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user
  3033. ON stats_login.course_code = session_course_user.course_code
  3034. AND session_course_user.id_session = '.intval($session_id).'
  3035. AND session_course_user.id_user = stats_login.user_id ';
  3036. }
  3037. $sql = 'SELECT user_id, MAX(login_course_date) max_date FROM'.$tbl_track_login.' stats_login'.$inner.'
  3038. GROUP BY user_id
  3039. HAVING DATE_SUB( NOW(), INTERVAL '.$since.' DAY) > max_date ';
  3040. //HAVING DATE_ADD(max_date, INTERVAL '.$since.' DAY) < NOW() ';
  3041. if ($since == 'never') {
  3042. $sql = 'SELECT course_user.user_id FROM '.$table_course_rel_user.' course_user
  3043. LEFT JOIN '. $tbl_track_login.' stats_login
  3044. ON course_user.user_id = stats_login.user_id AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' '.
  3045. $inner.'
  3046. WHERE course_user.course_code = \''.Database::escape_string($course_code).'\'
  3047. AND stats_login.login_course_date IS NULL
  3048. GROUP BY course_user.user_id';
  3049. }
  3050. $rs = Database::query($sql);
  3051. $inactive_users = array();
  3052. while($user = Database::fetch_array($rs)) {
  3053. $inactive_users[] = $user['user_id'];
  3054. }
  3055. return $inactive_users;
  3056. }
  3057. /**
  3058. * Get count login per student
  3059. * @param int Student id
  3060. * @param string Course code
  3061. * @param int Session id (optional)
  3062. * @return int count login
  3063. */
  3064. public static function count_login_per_student($student_id, $course_code, $session_id = 0)
  3065. {
  3066. $student_id = intval($student_id);
  3067. $course_code = Database::escape_string($course_code);
  3068. $session_id = intval($session_id);
  3069. $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  3070. $sql = 'SELECT '.$student_id.'
  3071. FROM ' . $tbl_course_rel_user . '
  3072. WHERE access_user_id=' . $student_id . '
  3073. AND access_cours_code="' . $course_code . '" AND access_session_id = "'.$session_id.'" ';
  3074. $rs = Database::query($sql);
  3075. $nb_login = Database::num_rows($rs);
  3076. return $nb_login;
  3077. }
  3078. /**
  3079. * Get students followed by a human resources manager
  3080. * @param int Drh id
  3081. * @return array Student list
  3082. */
  3083. public static function get_student_followed_by_drh($hr_dept_id)
  3084. {
  3085. $hr_dept_id = intval($hr_dept_id);
  3086. $a_students = array();
  3087. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  3088. $sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user
  3089. WHERE hr_dept_id='.$hr_dept_id;
  3090. $rs = Database::query($sql);
  3091. while($user = Database :: fetch_array($rs)) {
  3092. $a_students[$user['user_id']] = $user['user_id'];
  3093. }
  3094. return $a_students;
  3095. }
  3096. /**
  3097. * Gets the average of test and scorm inside a learning path
  3098. * @param int User id
  3099. * @param string Course id
  3100. * @return float average of test
  3101. * @author isaac flores paz
  3102. * @deprecated get_avg_student_score should be use
  3103. */
  3104. public static function get_average_test_scorm_and_lp($user_id, $course_id)
  3105. {
  3106. //the score inside the Reporting table
  3107. $course_info = api_get_course_info($course_id);
  3108. $course_id = $course_info['real_id'];
  3109. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3110. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3111. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  3112. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  3113. $sql_type = "SELECT id, lp_type FROM $lp_table WHERE c_id = $course_id";
  3114. $rs_type=Database::query($sql_type);
  3115. $average_data=0;
  3116. $count_loop=0;
  3117. $average_data_sum = 0;
  3118. $lp_list = array();
  3119. while ($row_type = Database::fetch_array($rs_type)) {
  3120. $lp_list[] = $row_type['id'];
  3121. if ($row_type['lp_type']==1) {
  3122. //lp chamilo
  3123. $sql = "SELECT id FROM $lp_view_table WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  3124. $rs_last_lp_view_id = Database::query($sql);
  3125. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  3126. $sql_list_view="SELECT li.max_score,lv.user_id,liw.score,(liw.score/li.max_score) as sum_data
  3127. FROM $lp_item_table li
  3128. INNER JOIN $lp_view_table lv
  3129. ON li.lp_id=lv.lp_id
  3130. INNER JOIN $lp_item_view_table liw
  3131. ON liw.lp_item_id=li.id
  3132. WHERE li.c_id = $course_id AND
  3133. liw.c_id = $course_id AND
  3134. lv.c_id = $course_id AND
  3135. lv.user_id= $user_id AND
  3136. li.item_type = 'quiz' AND
  3137. liw.lp_view_id= $lp_view_id";
  3138. $sum=0;
  3139. $tot=0;
  3140. $rs_list_view1=Database::query($sql_list_view);
  3141. while ($row_list_view=Database::fetch_array($rs_list_view1)) {
  3142. $sum=$sum+$row_list_view['sum_data'];
  3143. $tot++;
  3144. }
  3145. if ($tot==0) {
  3146. $tot=1;
  3147. }
  3148. $average_data1=$sum/$tot;
  3149. } elseif ($row_type['lp_type']==2) {
  3150. //lp scorm
  3151. $sql = "SELECT id FROM $lp_view_table
  3152. WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  3153. $rs_last_lp_view_id = Database::query($sql);
  3154. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  3155. $sql_list_view = "SELECT li.max_score,lv.user_id,liw.score,((liw.score/li.max_score)*100) as sum_data
  3156. FROM $lp_item_table li
  3157. INNER JOIN $lp_view_table lv
  3158. ON li.lp_id=lv.lp_id
  3159. INNER JOIN $lp_item_view_table liw ON liw.lp_item_id=li.id
  3160. WHERE li.c_id = $course_id AND
  3161. liw.c_id = $course_id AND
  3162. lv.c_id = $course_id AND
  3163. lv.user_id= $user_id AND
  3164. (li.item_type = 'sco' OR li.item_type='quiz') AND
  3165. liw.lp_view_id = $lp_view_id";
  3166. $tot=0;
  3167. $sum=0;
  3168. $rs_list_view2=Database::query($sql_list_view);
  3169. while ($row_list_view=Database::fetch_array($rs_list_view2)) {
  3170. $sum=$sum+$row_list_view['sum_data'];
  3171. $tot++;
  3172. }
  3173. if ($tot==0) {
  3174. $tot=1;
  3175. }
  3176. $average_data2=$sum/$tot;
  3177. }
  3178. $average_data_sum = $average_data_sum+$average_data1+$average_data2;
  3179. $average_data2=0;
  3180. $average_data1=0;
  3181. $count_loop++;
  3182. }
  3183. //We only count the LP that have an exercise to get the average
  3184. $lp_with_quiz = 0;
  3185. foreach ($lp_list as $lp_id) {
  3186. //check if LP have a score
  3187. $sql = "SELECT count(id) as count FROM $lp_item_table
  3188. WHERE c_id = $course_id AND item_type = 'quiz' AND lp_id = ".$lp_id." ";
  3189. $result_have_quiz = Database::query($sql);
  3190. if (Database::num_rows($result_have_quiz) > 0 ) {
  3191. $row = Database::fetch_array($result_have_quiz,'ASSOC');
  3192. if (is_numeric($row['count']) && $row['count'] != 0) {
  3193. $lp_with_quiz++;
  3194. }
  3195. }
  3196. }
  3197. if ($lp_with_quiz > 0) {
  3198. $avg_student_score = round(($average_data_sum / $lp_with_quiz * 100), 2);
  3199. }
  3200. return $avg_student_score;
  3201. }
  3202. /**
  3203. * get count clicks about tools most used by course
  3204. * @param string Course code
  3205. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  3206. * @return array tools data
  3207. */
  3208. public static function get_tools_most_used_by_course($course_code, $session_id = null)
  3209. {
  3210. //protect data
  3211. $course_code = Database::escape_string($course_code);
  3212. $data = array();
  3213. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  3214. $condition_session = '';
  3215. if (isset($session_id)) {
  3216. $session_id = intval($session_id);
  3217. $condition_session = ' AND access_session_id = '. $session_id;
  3218. }
  3219. $sql = "SELECT access_tool, COUNT(DISTINCT access_user_id),count( access_tool ) as count_access_tool
  3220. FROM $TABLETRACK_ACCESS
  3221. WHERE
  3222. access_tool IS NOT NULL AND
  3223. access_tool != '' AND
  3224. access_cours_code = '$course_code'
  3225. $condition_session
  3226. GROUP BY access_tool
  3227. ORDER BY count_access_tool DESC
  3228. LIMIT 0, 3";
  3229. $rs = Database::query($sql);
  3230. if (Database::num_rows($rs) > 0) {
  3231. while ($row = Database::fetch_array($rs)) {
  3232. $data[] = $row;
  3233. }
  3234. }
  3235. return $data;
  3236. }
  3237. /**
  3238. * Get total clicks
  3239. * THIS FUNCTION IS NOT BEEN USED, IT WAS MEANT TO BE USE WITH track_e_course_access.date_from and track_e_course_access.date_to,
  3240. * BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES
  3241. * @param int User Id
  3242. * @param int Course Id
  3243. * @param int Session Id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  3244. * @param string Date from
  3245. * @param string Date to
  3246. * @return array Data
  3247. * @author César Perales cesar.perales@beeznest.com 2014-01-16
  3248. */
  3249. public static function get_total_clicks($userId, $courseId, $sessionId = 0, $date_from = '', $date_to = '')
  3250. {
  3251. $course = api_get_course_info_by_id($courseId);
  3252. $tables = array(
  3253. TABLE_STATISTIC_TRACK_E_LASTACCESS => array(
  3254. 'course' => 'access_cours_code',
  3255. 'session' => 'access_session_id',
  3256. 'user' => 'access_user_id',
  3257. 'start_date'=> 'access_date',
  3258. ),
  3259. TABLE_STATISTIC_TRACK_E_ACCESS => array(
  3260. 'course' => 'access_cours_code',
  3261. 'session' => 'access_session_id',
  3262. 'user' => 'access_user_id',
  3263. 'start_date'=> 'access_date',
  3264. ),
  3265. #TABLE_STATISTIC_TRACK_E_LOGIN, array(,, 'login_date', 'logout_date');
  3266. TABLE_STATISTIC_TRACK_E_DOWNLOADS => array(
  3267. 'course' => 'down_cours_id',
  3268. 'session' => 'down_session_id',
  3269. 'user' => 'down_user_id',
  3270. 'start_date'=> 'down_date',
  3271. ),
  3272. TABLE_STATISTIC_TRACK_E_LINKS => array(
  3273. 'course' => 'links_cours_id',
  3274. 'session' => 'links_session_id',
  3275. 'user' => 'links_user_id',
  3276. 'start_date'=> 'links_date',
  3277. ),
  3278. TABLE_STATISTIC_TRACK_E_ONLINE => array(
  3279. 'course' => 'course',
  3280. 'session' => 'session_id',
  3281. 'user' => 'login_user_id',
  3282. 'start_date'=> 'login_date',
  3283. ),
  3284. #TABLE_STATISTIC_TRACK_E_HOTPOTATOES,
  3285. /*TABLE_STATISTIC_TRACK_E_COURSE_ACCESS => array(
  3286. 'course' => 'course_code',
  3287. 'session' => 'session_id',
  3288. 'user' => 'user_id',
  3289. 'start_date'=> 'login_course_date',
  3290. 'end_date' => 'logout_course_date',
  3291. ),*/
  3292. TABLE_STATISTIC_TRACK_E_EXERCICES => array(
  3293. 'course' => 'exe_cours_id',
  3294. 'session' => 'session_id',
  3295. 'user' => 'exe_user_id',
  3296. 'start_date'=> 'exe_date',
  3297. ),
  3298. TABLE_STATISTIC_TRACK_E_ATTEMPT => array(
  3299. 'course' => 'course_code',
  3300. 'session' => 'session_id',
  3301. 'user' => 'user_id',
  3302. 'start_date'=> 'tms',
  3303. ),
  3304. #TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING,
  3305. #TABLE_STATISTIC_TRACK_E_DEFAULT,
  3306. TABLE_STATISTIC_TRACK_E_UPLOADS => array(
  3307. 'course' => 'upload_cours_id',
  3308. 'session' => 'upload_session_id',
  3309. 'user' => 'upload_user_id',
  3310. 'start_date'=> 'upload_date',
  3311. ),
  3312. #TABLE_STATISTIC_TRACK_E_HOTSPOT,
  3313. #TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY,
  3314. #TABLE_STATISTIC_TRACK_E_OPEN,
  3315. );
  3316. $error_sql = '';
  3317. foreach ($tables as $tableName => $fields) {
  3318. //If session is defined, add it to query
  3319. $where = '';
  3320. if (isset($sessionId) && !empty($sessionId)) {
  3321. $sessionField = $fields['session'];
  3322. $where .= " AND $sessionField = $sessionId";
  3323. }
  3324. //filter by date
  3325. if (!empty($date_from) && !empty($date_to)) {
  3326. $fieldStartDate = $fields['start_date'];
  3327. if (!isset($fields['end_date'])) {
  3328. $where .= sprintf(" AND ($fieldStartDate BETWEEN '%s' AND '%s' )", $date_from, $date_to) ;
  3329. } else {
  3330. $fieldEndDate = $fields['end_date'];
  3331. $where .= sprintf(" AND fieldStartDate >= '%s'
  3332. AND $fieldEndDate <= '%s'", $date_from, $date_to);
  3333. }
  3334. }
  3335. //query
  3336. $sql = "SELECT %s as user, count(*) as total
  3337. FROM %s
  3338. WHERE %s = '%s'
  3339. AND %s = %s
  3340. $where
  3341. GROUP BY %s";
  3342. $sql = sprintf($sql,
  3343. $fields['user'], //user field
  3344. $tableName, //FROM
  3345. $fields['course'], //course condition
  3346. $course['code'], //course condition
  3347. $fields['user'], //user condition
  3348. $userId, //user condition
  3349. $fields['user'] //GROUP BY
  3350. );
  3351. $rs = Database::query($sql);
  3352. //iterate query
  3353. if (Database::num_rows($rs) > 0) {
  3354. while ($row = Database::fetch_array($rs)) {
  3355. $data[$row['user']] = (isset($data[$row['user']])) ? $data[$row['user']] + $row[total]: $row['total'];
  3356. }
  3357. }
  3358. }
  3359. return $data;
  3360. }
  3361. /**
  3362. * get documents most downloaded by course
  3363. * @param string Course code
  3364. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  3365. * @param int Limit (optional, default = 0, 0 = without limit)
  3366. * @return array documents downloaded
  3367. */
  3368. public static function get_documents_most_downloaded_by_course($course_code, $session_id = null, $limit = 0)
  3369. {
  3370. //protect data
  3371. $course_code = Database::escape_string($course_code);
  3372. $data = array();
  3373. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  3374. $condition_session = '';
  3375. if (isset($session_id)) {
  3376. $session_id = intval($session_id);
  3377. $condition_session = ' AND down_session_id = '. $session_id;
  3378. }
  3379. $sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
  3380. FROM $TABLETRACK_DOWNLOADS
  3381. WHERE down_cours_id = '$course_code'
  3382. $condition_session
  3383. GROUP BY down_doc_path
  3384. ORDER BY count_down DESC
  3385. LIMIT 0, $limit";
  3386. $rs = Database::query($sql);
  3387. if (Database::num_rows($rs) > 0) {
  3388. while ($row = Database::fetch_array($rs)) {
  3389. $data[] = $row;
  3390. }
  3391. }
  3392. return $data;
  3393. }
  3394. /**
  3395. * get links most visited by course
  3396. * @param string Course code
  3397. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  3398. * @return array links most visited
  3399. */
  3400. public static function get_links_most_visited_by_course($course_code, $session_id = null)
  3401. {
  3402. $course_code = Database::escape_string($course_code);
  3403. $course_info = api_get_course_info($course_code);
  3404. $course_id = $course_info['real_id'];
  3405. $data = array();
  3406. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  3407. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  3408. $condition_session = '';
  3409. if (isset($session_id)) {
  3410. $session_id = intval($session_id);
  3411. $condition_session = ' AND cl.session_id = '.$session_id;
  3412. }
  3413. $sql = "SELECT cl.title, cl.url,count(DISTINCT sl.links_user_id), count(cl.title) as count_visits
  3414. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  3415. WHERE cl.c_id = $course_id AND
  3416. sl.links_link_id = cl.id
  3417. AND sl.links_cours_id = '$course_code'
  3418. $condition_session
  3419. GROUP BY cl.title, cl.url
  3420. ORDER BY count_visits DESC
  3421. LIMIT 0, 3";
  3422. $rs = Database::query($sql);
  3423. if (Database::num_rows($rs) > 0) {
  3424. while ($row = Database::fetch_array($rs)) {
  3425. $data[] = $row;
  3426. }
  3427. }
  3428. return $data;
  3429. }
  3430. /**
  3431. * Shows the user progress (when clicking in the Progress tab)
  3432. *
  3433. * @param int $user_id
  3434. * @param int $session_id
  3435. * @param string $extra_params
  3436. * @param bool $show_courses
  3437. *
  3438. * @return string
  3439. */
  3440. public static function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true, $showAllSessions = true)
  3441. {
  3442. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  3443. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  3444. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  3445. $tbl_access_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  3446. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  3447. $tbl_access_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  3448. $user_id = intval($user_id);
  3449. if (api_is_multiple_url_enabled()) {
  3450. $sql = "SELECT cu.course_code as code, title
  3451. FROM $tbl_course_user cu INNER JOIN $tbl_access_rel_course a
  3452. ON (a.course_code = cu.course_code)
  3453. INNER JOIN $tbl_course c ON (cu.course_code = c.code)
  3454. WHERE
  3455. user_id = $user_id AND
  3456. relation_type<> ".COURSE_RELATION_TYPE_RRHH." AND
  3457. access_url_id = ".api_get_current_access_url_id()."
  3458. ORDER BY title";
  3459. } else {
  3460. $sql = "SELECT course_code as code, title
  3461. FROM $tbl_course_user u
  3462. INNER JOIN $tbl_course c ON (course_code = c.code)
  3463. WHERE
  3464. u.user_id= $user_id AND
  3465. relation_type<>".COURSE_RELATION_TYPE_RRHH."
  3466. ORDER BY title";
  3467. }
  3468. $rs = Database::query($sql);
  3469. $courses = $course_in_session = $temp_course_in_session = array();
  3470. while($row = Database :: fetch_array($rs, 'ASSOC')) {
  3471. $courses[$row['code']] = $row['title'];
  3472. }
  3473. $orderBy = " ORDER BY name ";
  3474. $extraInnerJoin = null;
  3475. if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) {
  3476. $orderBy = " ORDER BY s.id, position ";
  3477. $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  3478. $extraInnerJoin = " INNER JOIN $tableSessionRelCourse src ON (cu.course_code = src.course_code AND src.id_session = $session_id) ";
  3479. }
  3480. // Get the list of sessions where the user is subscribed as student
  3481. if (api_is_multiple_url_enabled()) {
  3482. $sql = "SELECT DISTINCT cu.course_code, s.id as session_id, name
  3483. FROM $tbl_session_course_user cu
  3484. INNER JOIN $tbl_access_rel_session a
  3485. ON (a.session_id = cu.id_session)
  3486. INNER JOIN $tbl_session s ON (s.id = a.session_id)
  3487. $extraInnerJoin
  3488. WHERE
  3489. id_user = $user_id AND
  3490. access_url_id = ".api_get_current_access_url_id()."
  3491. $orderBy ";
  3492. } else {
  3493. $sql = "SELECT DISTINCT cu.course_code, s.id as session_id, name
  3494. FROM $tbl_session_course_user cu
  3495. INNER JOIN $tbl_session s ON (s.id = cu.id_session)
  3496. $extraInnerJoin
  3497. WHERE id_user = $user_id
  3498. $orderBy ";
  3499. }
  3500. $rs = Database::query($sql);
  3501. $simple_session_array = array();
  3502. while ($row = Database :: fetch_array($rs)) {
  3503. $course_info = CourseManager::get_course_information($row['course_code']);
  3504. $temp_course_in_session[$row['session_id']]['course_list'][$course_info['id']] = $course_info;
  3505. $temp_course_in_session[$row['session_id']]['name'] = $row['name'];
  3506. $simple_session_array[$row['session_id']] = $row['name'];
  3507. }
  3508. foreach ($simple_session_array as $my_session_id => $session_name) {
  3509. $course_list = $temp_course_in_session[$my_session_id]['course_list'];
  3510. $my_course_data = array();
  3511. foreach ($course_list as $course_data) {
  3512. $my_course_data[$course_data['id']] = $course_data['title'];
  3513. }
  3514. if (!SessionManager::orderCourseIsEnabled() && empty($session_id)) {
  3515. $my_course_data = utf8_sort($my_course_data);
  3516. }
  3517. $final_course_data = array();
  3518. foreach($my_course_data as $course_id => $value) {
  3519. $final_course_data[$course_id] = $course_list[$course_id];
  3520. }
  3521. $course_in_session[$my_session_id]['course_list'] = $final_course_data;
  3522. $course_in_session[$my_session_id]['name'] = $session_name;
  3523. }
  3524. $html = '';
  3525. // Course list
  3526. if ($show_courses) {
  3527. if (!empty($courses)) {
  3528. $html .= Display::page_subheader(
  3529. Display::return_icon('course.png', get_lang('MyCourses'), array(), ICON_SIZE_SMALL).' '.get_lang('MyCourses')
  3530. );
  3531. $html .= '<table class="data_table" width="100%">';
  3532. $html .= '<tr>
  3533. '.Display::tag('th', get_lang('Course'), array('width'=>'300px')).'
  3534. '.Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class'=>'head')).'
  3535. '.Display::tag('th', get_lang('Progress'), array('class'=>'head')).'
  3536. '.Display::tag('th', get_lang('Score').Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')),array('class'=>'head')).'
  3537. '.Display::tag('th', get_lang('LastConnexion'), array('class'=>'head')).'
  3538. '.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
  3539. </tr>';
  3540. foreach ($courses as $course_code => $course_title) {
  3541. $total_time_login = Tracking :: get_time_spent_on_the_course(
  3542. $user_id,
  3543. $course_code
  3544. );
  3545. $time = api_time_to_hms($total_time_login);
  3546. $progress = Tracking :: get_avg_student_progress(
  3547. $user_id,
  3548. $course_code
  3549. );
  3550. $percentage_score = Tracking :: get_avg_student_score(
  3551. $user_id,
  3552. $course_code,
  3553. array()
  3554. );
  3555. $last_connection = Tracking :: get_last_connection_date_on_the_course(
  3556. $user_id,
  3557. $course_code
  3558. );
  3559. if (is_null($progress)) {
  3560. $progress = '0%';
  3561. } else {
  3562. $progress = $progress.'%';
  3563. }
  3564. if ($course_code == $_GET['course'] && empty($_GET['session_id'])) {
  3565. $html .= '<tr class="row_odd" style="background-color:#FBF09D">';
  3566. } else {
  3567. $html .= '<tr class="row_even">';
  3568. }
  3569. $url = api_get_course_url($course_code, $session_id);
  3570. $course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET));
  3571. $html .= '<td>'.$course_url.'</td>';
  3572. $html .= '<td align="center">'.$time.'</td>';
  3573. $html .= '<td align="center">'.$progress.'</td>';
  3574. $html .= '<td align="center">';
  3575. if (is_numeric($percentage_score)) {
  3576. $html .= $percentage_score.'%';
  3577. } else {
  3578. $html .= '0%';
  3579. }
  3580. $html .= '</td>';
  3581. $html .= '<td align="center">'.$last_connection.'</td>';
  3582. $html .= '<td align="center">';
  3583. if ($course_code == $_GET['course'] && empty($_GET['session_id'])) {
  3584. $html .= '<a href="#">';
  3585. $html .= Display::return_icon('2rightarrow_na.gif', get_lang('Details'));
  3586. } else {
  3587. $html .= '<a href="'.api_get_self().'?course='.$course_code.$extra_params.'">';
  3588. $html .= Display::return_icon('2rightarrow.gif', get_lang('Details'));
  3589. }
  3590. $html .= '</a>';
  3591. $html .= '</td></tr>';
  3592. }
  3593. $html .= '</table>';
  3594. }
  3595. }
  3596. // Session list
  3597. if (!empty($course_in_session)) {
  3598. $main_session_graph = '';
  3599. //Load graphics only when calling to an specific session
  3600. $session_graph = array();
  3601. $all_exercise_graph_name_list = array();
  3602. $my_results = array();
  3603. $all_exercise_graph_list = array();
  3604. $all_exercise_start_time = array();
  3605. foreach ($course_in_session as $my_session_id => $session_data) {
  3606. $course_list = $session_data['course_list'];
  3607. $session_name = $session_data['name'];
  3608. $user_count = count(SessionManager::get_users_by_session($my_session_id));
  3609. $exercise_graph_name_list = array();
  3610. //$user_results = array();
  3611. $exercise_graph_list = array();
  3612. foreach ($course_list as $course_data) {
  3613. $exercise_list = get_all_exercises(
  3614. $course_data,
  3615. $my_session_id,
  3616. false,
  3617. null,
  3618. false,
  3619. 1
  3620. );
  3621. foreach ($exercise_list as $exercise_data) {
  3622. $exercise_obj = new Exercise($course_data['id']);
  3623. $exercise_obj->read($exercise_data['id']);
  3624. //Exercise is not necessary to be visible to show results check the result_disable configuration instead
  3625. //$visible_return = $exercise_obj->is_visible();
  3626. if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) {
  3627. $best_average = intval(
  3628. get_best_average_score_by_exercise(
  3629. $exercise_data['id'],
  3630. $course_data['code'],
  3631. $my_session_id,
  3632. $user_count
  3633. )
  3634. );
  3635. $exercise_graph_list[] = $best_average;
  3636. $all_exercise_graph_list[] = $best_average;
  3637. $user_result_data = get_best_attempt_by_user(
  3638. api_get_user_id(),
  3639. $exercise_data['id'],
  3640. $course_data['code'],
  3641. $my_session_id
  3642. );
  3643. $score = 0;
  3644. if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) {
  3645. $score = intval($user_result_data['exe_result']/$user_result_data['exe_weighting'] * 100);
  3646. }
  3647. $time = api_strtotime($exercise_data['start_time']) ? api_strtotime($exercise_data['start_time'], 'UTC') : 0;
  3648. $all_exercise_start_time[] = $time;
  3649. $my_results[] = $score;
  3650. if (count($exercise_list)<=10) {
  3651. $title = cut($course_data['title'], 30)." \n ".cut($exercise_data['title'], 30);
  3652. $exercise_graph_name_list[]= $title;
  3653. $all_exercise_graph_name_list[] = $title;
  3654. } else {
  3655. // if there are more than 10 results, space becomes difficult to find, so only show the title of the exercise, not the tool
  3656. $title = cut($exercise_data['title'], 30);
  3657. $exercise_graph_name_list[]= $title;
  3658. $all_exercise_graph_name_list[]= $title;
  3659. }
  3660. }
  3661. }
  3662. }
  3663. }
  3664. // Complete graph
  3665. if (!empty($my_results) && !empty($all_exercise_graph_list)) {
  3666. asort($all_exercise_start_time);
  3667. //Fix exams order
  3668. $final_all_exercise_graph_name_list = array();
  3669. $my_results_final = array();
  3670. $final_all_exercise_graph_list = array();
  3671. foreach ($all_exercise_start_time as $key => $time) {
  3672. $label_time = '';
  3673. if (!empty($time)) {
  3674. $label_time = date('d-m-y', $time);
  3675. }
  3676. $final_all_exercise_graph_name_list[] = $all_exercise_graph_name_list[$key].' '.$label_time;
  3677. $my_results_final[] = $my_results[$key];
  3678. $final_all_exercise_graph_list[] = $all_exercise_graph_list[$key];
  3679. }
  3680. $main_session_graph = self::generate_session_exercise_graph(
  3681. $final_all_exercise_graph_name_list,
  3682. $my_results_final,
  3683. $final_all_exercise_graph_list
  3684. );
  3685. }
  3686. $html .= Display::page_subheader(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL).' '.get_lang('Sessions'));
  3687. $html .= '<table class="data_table" width="100%">';
  3688. $html .= '<tr>
  3689. '.Display::tag('th', get_lang('Session'), array('width'=>'300px')).'
  3690. '.Display::tag('th', get_lang('PublishedExercises'), array('width'=>'300px')).'
  3691. '.Display::tag('th', get_lang('NewExercises'), array('class'=>'head')).'
  3692. '.Display::tag('th', get_lang('AverageExerciseResult'), array('class'=>'head')).'
  3693. '.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
  3694. </tr>';
  3695. foreach ($course_in_session as $my_session_id => $session_data) {
  3696. $course_list = $session_data['course_list'];
  3697. $session_name = $session_data['name'];
  3698. if ($showAllSessions == false) {
  3699. if (isset($session_id) && !empty($session_id)) {
  3700. if ($session_id != $my_session_id) {
  3701. continue;
  3702. }
  3703. }
  3704. }
  3705. $all_exercises = 0;
  3706. $all_unanswered_exercises_by_user = 0;
  3707. $all_average = 0;
  3708. $stats_array = array();
  3709. foreach($course_list as $course_data) {
  3710. //All exercises in the course @todo change for a real count
  3711. $exercises = get_all_exercises($course_data, $my_session_id);
  3712. $count_exercises = 0;
  3713. if (is_array($exercises) && !empty($exercises)) {
  3714. $count_exercises = count($exercises);
  3715. }
  3716. //Count of user results
  3717. //$done_exercises = get_count_exercises_attempted_by_course($course_data['code'], $my_session_id);
  3718. $done_exercises = null;
  3719. $answered_exercises = 0;
  3720. if (!empty($exercises)) {
  3721. foreach($exercises as $exercise_item) {
  3722. $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_data['code'], $my_session_id);
  3723. if ($attempts > 1) {
  3724. $answered_exercises++;
  3725. }
  3726. }
  3727. }
  3728. // Average
  3729. $average = get_average_score_by_course($course_data['code'], $my_session_id);
  3730. $all_exercises += $count_exercises;
  3731. $all_unanswered_exercises_by_user += $count_exercises - $answered_exercises;
  3732. //$all_done_exercise += $done_exercises;
  3733. $all_average += $average;
  3734. //$stats_array[$course_data['code']] = array('exercises'=>$count_exercises, 'unanswered_exercises_by_user'=>$answered_exercises,'done_exercises'=>$done_exercises, 'average'=>$average);
  3735. }
  3736. $all_average = $all_average / count($course_list);
  3737. if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
  3738. $html .= '<tr style="background-color:#FBF09D">';
  3739. } else {
  3740. $html .= '<tr>';
  3741. }
  3742. $url = api_get_path(WEB_CODE_PATH)."session/index.php?session_id={$my_session_id}";
  3743. $html .= Display::tag('td', Display::url($session_name, $url, array('target'=>SESSION_LINK_TARGET)));
  3744. $html .= Display::tag('td', $all_exercises);
  3745. $html .= Display::tag('td', $all_unanswered_exercises_by_user);
  3746. //$html .= Display::tag('td', $all_done_exercise);
  3747. $html .= Display::tag('td', convert_to_percentage($all_average));
  3748. if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
  3749. $icon = Display::url(Display::return_icon('2rightarrow_na.gif', get_lang('Details')), '?session_id='.$my_session_id);
  3750. } else {
  3751. $icon = Display::url(Display::return_icon('2rightarrow.gif', get_lang('Details')), '?session_id='.$my_session_id);
  3752. }
  3753. $html .= Display::tag('td', $icon);
  3754. $html .= '</tr>';
  3755. }
  3756. $html .= '</table><br />';
  3757. $html .= Display::div($main_session_graph, array('id'=>'session_graph','class'=>'chart-session', 'style'=>'position:relative; text-align: center;') );
  3758. // Checking selected session.
  3759. if (isset($_GET['session_id'])) {
  3760. $session_id_from_get = intval($_GET['session_id']);
  3761. $session_data = $course_in_session[$session_id_from_get];
  3762. $course_list = $session_data['course_list'];
  3763. $html .= Display::tag('h3',$session_data['name'].' - '.get_lang('CourseList'));
  3764. $html .= '<table class="data_table" width="100%">';
  3765. //'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).'
  3766. $html .= '
  3767. <tr>
  3768. <th width="300px">'.get_lang('Course').'</th>
  3769. '.Display::tag('th', get_lang('PublishedExercises'), array('class'=>'head')).'
  3770. '.Display::tag('th', get_lang('NewExercises'), array('class'=>'head')).'
  3771. '.Display::tag('th', get_lang('MyAverage'), array('class'=>'head')).'
  3772. '.Display::tag('th', get_lang('AverageExerciseResult'), array('class'=>'head')).'
  3773. '.Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class'=>'head')).'
  3774. '.Display::tag('th', get_lang('LPProgress') , array('class'=>'head')).'
  3775. '.Display::tag('th', get_lang('Score').Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px')), array('class'=>'head')).'
  3776. '.Display::tag('th', get_lang('LastConnexion'), array('class'=>'head')).'
  3777. '.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
  3778. </tr>';
  3779. foreach ($course_list as $course_data) {
  3780. $course_code = $course_data['code'];
  3781. $course_title = $course_data['title'];
  3782. //All exercises in the course @todo change for a real count
  3783. $exercises = get_all_exercises($course_data, $session_id_from_get);
  3784. $count_exercises = 0;
  3785. if (!empty($exercises)) {
  3786. $count_exercises = count($exercises);
  3787. }
  3788. //Count of user results
  3789. //$done_exercises = get_best_exercise_results_by_course($course_code, $session_id_from_get);
  3790. //From course exercises NOT from LP exercises!!!
  3791. //$done_exercises = get_count_exercises_attempted_by_course($course_code, $session_id_from_get);
  3792. $answered_exercises = 0;
  3793. foreach($exercises as $exercise_item) {
  3794. $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_code, $session_id_from_get);
  3795. if ($attempts > 1) {
  3796. $answered_exercises++;
  3797. }
  3798. }
  3799. $unanswered_exercises = $count_exercises - $answered_exercises;
  3800. // Average
  3801. $average = get_average_score_by_course($course_code, $session_id_from_get);
  3802. $my_average = get_average_score_by_course_by_user(api_get_user_id(), $course_code, $session_id_from_get);
  3803. $stats_array[$course_code] = array(
  3804. 'exercises' => $count_exercises,
  3805. 'unanswered_exercises_by_user' => $unanswered_exercises,
  3806. 'done_exercises' => $done_exercises,
  3807. 'average' => $average,
  3808. 'my_average' => $my_average
  3809. );
  3810. $weighting = 0;
  3811. $last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $course_code, $session_id_from_get);
  3812. $progress = Tracking :: get_avg_student_progress($user_id, $course_code,array(), $session_id_from_get);
  3813. $total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $course_code, $session_id_from_get);
  3814. $time = api_time_to_hms($total_time_login);
  3815. $percentage_score = Tracking :: get_avg_student_score($user_id, $course_code, array(), $session_id_from_get);
  3816. $courseCodeFromGet = isset($_GET['course']) ? $_GET['course'] : null;
  3817. if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) {
  3818. $html .= '<tr class="row_odd" style="background-color:#FBF09D" >';
  3819. } else {
  3820. $html .= '<tr class="row_even">';
  3821. }
  3822. $url = api_get_course_url($course_code, $session_id_from_get);
  3823. $course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET));
  3824. $html .= Display::tag('td', $course_url);
  3825. $html .= Display::tag('td', $stats_array[$course_code]['exercises']);
  3826. $html .= Display::tag('td', $stats_array[$course_code]['unanswered_exercises_by_user']);
  3827. //$html .= Display::tag('td', $stats_array[$course_code]['done_exercises']);
  3828. $html .= Display::tag('td', convert_to_percentage($stats_array[$course_code]['my_average']));
  3829. $html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '('.convert_to_percentage($stats_array[$course_code]['average']).')');
  3830. $html .= Display::tag('td', $time, array('align'=>'center'));
  3831. if (is_numeric($progress)) {
  3832. $progress = $progress.'%';
  3833. } else {
  3834. $progress = '0%';
  3835. }
  3836. //Progress
  3837. $html .= Display::tag('td', $progress, array('align'=>'center'));
  3838. if (is_numeric($percentage_score)) {
  3839. $percentage_score = $percentage_score.'%';
  3840. } else {
  3841. $percentage_score = '0%';
  3842. }
  3843. //Score
  3844. $html .= Display::tag('td', $percentage_score, array('align'=>'center'));
  3845. $html .= Display::tag('td', $last_connection, array('align'=>'center'));
  3846. if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) {
  3847. $details = '<a href="#">';
  3848. $details .=Display::return_icon('2rightarrow_na.gif', get_lang('Details'));
  3849. } else {
  3850. $details = '<a href="'.api_get_self().'?course='.$course_code.'&session_id='.$session_id_from_get.$extra_params.'">';
  3851. $details .= Display::return_icon('2rightarrow.gif', get_lang('Details'));
  3852. }
  3853. $details .= '</a>';
  3854. $html .= Display::tag('td', $details, array('align'=>'center'));
  3855. $html .= '</tr>';
  3856. }
  3857. $html .= '</table>';
  3858. if (!empty($session_graph[$session_id_from_get])) {
  3859. //$html .= Display::div($session_graph[$session_id_from_get], array('id'=>'session_graph','class'=>'chart-session', 'style'=>'position:relative; text-align: center;') );
  3860. }
  3861. }
  3862. }
  3863. return $html;
  3864. }
  3865. /**
  3866. * Shows the user detail progress (when clicking in the details link)
  3867. * @param int user id
  3868. * @param string course code
  3869. * @param int session id
  3870. * @return string html code
  3871. */
  3872. static function show_course_detail($user_id, $course_code, $session_id)
  3873. {
  3874. $html = '';
  3875. if (isset($course_code)) {
  3876. $user_id = intval($user_id);
  3877. $session_id = intval($session_id);
  3878. $course = Database::escape_string($course_code);
  3879. $course_info = CourseManager::get_course_information($course);
  3880. //$course_id = $course_info['real_id'];
  3881. //$session_name = api_get_session_name($session_id);
  3882. $html .= Display::page_subheader($course_info['title']);
  3883. $html .= '<table class="data_table" width="100%">';
  3884. //Course details
  3885. $html .= '
  3886. <tr>
  3887. <th class="head" style="color:#000">'.get_lang('Exercices').'</th>
  3888. <th class="head" style="color:#000">'.get_lang('Attempts').'</th>
  3889. <th class="head" style="color:#000">'.get_lang('BestAttempt').'</th>
  3890. <th class="head" style="color:#000">'.get_lang('Ranking').'</th>
  3891. <th class="head" style="color:#000">'.get_lang('BestResultInCourse').'</th>
  3892. <th class="head" style="color:#000">'.get_lang('Statistics').' '.Display :: return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent'), array('align' => 'absmiddle', 'hspace' => '3px')).'</th>
  3893. </tr>';
  3894. if (empty($session_id)) {
  3895. $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, STUDENT);
  3896. } else {
  3897. $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, 0);
  3898. }
  3899. //$exercise_list = get_all_exercises($course_info, $session_id, true);
  3900. // Show exercise results of invisible exercises? see BT#4091
  3901. $exercise_list = get_all_exercises(
  3902. $course_info,
  3903. $session_id,
  3904. false,
  3905. null,
  3906. false,
  3907. 1
  3908. );
  3909. $to_graph_exercise_result = array();
  3910. if (!empty($exercise_list)) {
  3911. $score = $weighting = $exe_id = 0;
  3912. foreach ($exercise_list as $exercices) {
  3913. $exercise_obj = new Exercise($course_info['real_id']);
  3914. $exercise_obj->read($exercices['id']);
  3915. $visible_return = $exercise_obj->is_visible();
  3916. $score = $weighting = $attempts = 0;
  3917. //Getting count of attempts by user
  3918. $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id);
  3919. $html .= '<tr class="row_even">';
  3920. $url = api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq={$course_info['code']}&id_session=$session_id&exerciseId={$exercices['id']}";
  3921. if ($visible_return['value'] == true) {
  3922. $exercices['title'] = Display::url($exercices['title'], $url, array('target'=>SESSION_LINK_TARGET));
  3923. }
  3924. $html .= Display::tag('td', $exercices['title']);
  3925. //Exercise configuration show results or show only score
  3926. if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) {
  3927. //For graphics
  3928. $best_exercise_stats = get_best_exercise_results_by_user($exercices['id'], $course_info['code'], $session_id);
  3929. $to_graph_exercise_result[$exercices['id']] = array('title'=>$exercices['title'], 'data'=>$best_exercise_stats);
  3930. $latest_attempt_url = '';
  3931. $best_score = $position = $percentage_score_result = '-';
  3932. $graph = $normal_graph = null;
  3933. //Getting best results
  3934. $best_score_data = get_best_attempt_in_course($exercices['id'], $course_info['code'], $session_id);
  3935. $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
  3936. if ($attempts > 0) {
  3937. $exercise_stat = get_best_attempt_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id);
  3938. if (!empty($exercise_stat)) {
  3939. //Always getting the BEST attempt
  3940. $score = $exercise_stat['exe_result'];
  3941. $weighting = $exercise_stat['exe_weighting'];
  3942. $exe_id = $exercise_stat['exe_id'];
  3943. $latest_attempt_url .= api_get_path(WEB_CODE_PATH).'exercice/result.php?id='.$exe_id.'&cidReq='.$course_info['code'].'&show_headers=1&id_session='.$session_id;
  3944. $percentage_score_result = Display::url(show_score($score, $weighting), $latest_attempt_url);
  3945. $my_score = 0;
  3946. if (!empty($weighting) && intval($weighting) != 0) {
  3947. $my_score = $score/$weighting;
  3948. }
  3949. //@todo this function slows the page
  3950. $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id, $user_list);
  3951. $graph = self::generate_exercise_result_thumbnail_graph($to_graph_exercise_result[$exercices['id']]);
  3952. $normal_graph = self::generate_exercise_result_graph($to_graph_exercise_result[$exercices['id']]);
  3953. }
  3954. }
  3955. $html .= Display::div($normal_graph, array('id'=>'main_graph_'.$exercices['id'],'class'=>'dialog', 'style'=>'display:none') );
  3956. if (empty($graph)) {
  3957. $graph = '-';
  3958. } else {
  3959. $graph = Display::url($graph, '#', array('id'=>$exercices['id'], 'class'=>'opener'));
  3960. }
  3961. $html .= Display::tag('td', $attempts, array('align'=>'center'));
  3962. $html .= Display::tag('td', $percentage_score_result, array('align'=>'center'));
  3963. $html .= Display::tag('td', $position, array('align'=>'center'));
  3964. $html .= Display::tag('td', $best_score, array('align'=>'center'));
  3965. $html .= Display::tag('td', $graph, array('align'=>'center'));
  3966. //$html .= Display::tag('td', $latest_attempt_url, array('align'=>'center', 'width'=>'25'));
  3967. } else {
  3968. // Exercise configuration NO results
  3969. $html .= Display::tag('td', $attempts, array('align'=>'center'));
  3970. $html .= Display::tag('td', '-', array('align'=>'center'));
  3971. $html .= Display::tag('td', '-', array('align'=>'center'));
  3972. $html .= Display::tag('td', '-', array('align'=>'center'));
  3973. $html .= Display::tag('td', '-', array('align'=>'center'));
  3974. }
  3975. $html .= '</tr>';
  3976. }
  3977. } else {
  3978. $html .= '<tr><td colspan="5" align="center">'.get_lang('NoEx').'</td></tr>';
  3979. }
  3980. $html .= '</table>';
  3981. //LP table results
  3982. $html .='<table class="data_table">';
  3983. $html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000'));
  3984. $html .= Display::tag('th', get_lang('LatencyTimeSpent'), array('class'=>'head', 'style'=>'color:#000'));
  3985. $html .= Display::tag('th', get_lang('Progress'), array('class'=>'head', 'style'=>'color:#000'));
  3986. $html .= Display::tag('th', get_lang('Score'), array('class'=>'head', 'style'=>'color:#000'));
  3987. $html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000'));
  3988. $html .= '</tr>';
  3989. $list = new LearnpathList(api_get_user_id(), $course_info['code'], $session_id, 'publicated_on ASC', true);
  3990. $lp_list = $list->get_flat_list();
  3991. if (!empty($lp_list) > 0) {
  3992. foreach($lp_list as $lp_id => $learnpath) {
  3993. $progress = Tracking::get_avg_student_progress($user_id, $course, array($lp_id), $session_id);
  3994. $last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $lp_id, $session_id);
  3995. $time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($lp_id), $session_id);
  3996. $percentage_score = Tracking::get_avg_student_score($user_id, $course, array($lp_id), $session_id);
  3997. if (is_numeric($percentage_score)) {
  3998. $percentage_score = $percentage_score.'%';
  3999. } else {
  4000. $percentage_score = '0%';
  4001. }
  4002. $time_spent_in_lp = api_time_to_hms($time_spent_in_lp);
  4003. $html .= '<tr class="row_even">';
  4004. $url = api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id=$lp_id&action=view";
  4005. $html .= Display::tag('td', Display::url($learnpath['lp_name'], $url, array('target'=>SESSION_LINK_TARGET)));
  4006. $html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center'));
  4007. if (is_numeric($progress)) {
  4008. $progress = $progress.'%';
  4009. }
  4010. $html .= Display::tag('td', $progress, array('align'=>'center'));
  4011. $html .= Display::tag('td', $percentage_score);
  4012. $last_connection = '-';
  4013. if (!empty($last_connection_in_lp)) {
  4014. $last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG);
  4015. }
  4016. $html .= Display::tag('td', $last_connection, array('align'=>'center','width'=>'180px'));
  4017. $html .= "</tr>";
  4018. }
  4019. } else {
  4020. $html .= '<tr>
  4021. <td colspan="4" align="center">
  4022. '.get_lang('NoLearnpath').'
  4023. </td>
  4024. </tr>';
  4025. }
  4026. $html .='</table>';
  4027. }
  4028. return $html;
  4029. }
  4030. /**
  4031. * Generates an histogram
  4032. *
  4033. * @param array list of exercise names
  4034. * @param array my results 0 to 100
  4035. * @param array average scores 0-100
  4036. */
  4037. static function generate_session_exercise_graph($names, $my_results, $average)
  4038. {
  4039. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  4040. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  4041. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  4042. $cache = new pCache();
  4043. // Dataset definition
  4044. $data_set = new pData();
  4045. // Dataset definition
  4046. $data_set->AddPoint($average, "Serie1");
  4047. $data_set->AddPoint($my_results, "Serie2");
  4048. $data_set->AddPoint($names, "Serie3");
  4049. $data_set->AddAllSeries();
  4050. $data_set->SetAbsciseLabelSerie('Serie3');
  4051. $data_set->SetSerieName(get_lang('AverageScore'),"Serie1");
  4052. $data_set->SetSerieName(get_lang('MyResults'), "Serie2");
  4053. //$data_set->SetYAxisName(get_lang("Percentage"));
  4054. $data_set->SetYAxisUnit("%");
  4055. // Initialise the graph
  4056. $main_width = 860;
  4057. $main_height = 500;
  4058. $y_label_angle = 50;
  4059. $data_set->RemoveSerie("Serie3");
  4060. $graph = new pChart($main_width, $main_height);
  4061. //See 3.2 BT#2797
  4062. $graph->setFixedScale(0,100);
  4063. $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
  4064. $graph->setGraphArea(65,50,$main_width-20, $main_height-140);
  4065. $graph->drawFilledRoundedRectangle(7,7,$main_width-7,$main_height-7,5,240,240,240);
  4066. $graph->drawRoundedRectangle(5,5,$main_width-5,$main_height -5,5,230,230,230);
  4067. $graph->drawGraphArea(255,255,255,TRUE);
  4068. //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0, SCALE_ADDALL
  4069. $graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_NORMAL ,150,150,150,TRUE,$y_label_angle,1, TRUE);
  4070. $graph->drawGrid(4,TRUE,230,230,230,70);
  4071. // Draw the 0 line
  4072. $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6);
  4073. $graph->drawTreshold(0,143,55,72,TRUE,TRUE);
  4074. // Draw the cubic curve graph
  4075. $graph->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription());
  4076. $graph->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),1,1,230,255,255);
  4077. // Finish the graph
  4078. $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
  4079. $graph->drawLegend($main_width - 150,70,$data_set->GetDataDescription(),255,255,255);
  4080. $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',11);
  4081. $graph->drawTitle(50, 30, get_lang('ExercisesInTimeProgressChart'), 50,50,50,$main_width-110, true);
  4082. // $main_graph = new pChart($main_width,$main_height);
  4083. $courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : null;
  4084. $graph_id = 'generate_session_exercise_graph'.$courseCode.'-'.intval($_GET['session_id']).'-'.api_get_user_id();
  4085. if ($cache->IsInCache($graph_id, $data_set->GetData())) {
  4086. //if (0) {
  4087. //if we already created the img
  4088. //echo 'in cache';
  4089. $img_file = $cache->GetHash($graph_id,$data_set->GetData());
  4090. } else {
  4091. $cache->WriteToCache($graph_id, $data_set->GetData(), $graph);
  4092. ob_start();
  4093. $graph->Stroke();
  4094. ob_end_clean();
  4095. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  4096. }
  4097. $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  4098. return $html;
  4099. }
  4100. /**
  4101. *
  4102. * Returns a thumbnail of the function generate_exercise_result_graph
  4103. * @param array attempts
  4104. */
  4105. static function generate_exercise_result_thumbnail_graph($attempts)
  4106. {
  4107. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  4108. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  4109. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  4110. $exercise_title = $attempts['title'];
  4111. $attempts = $attempts['data'];
  4112. $my_exercise_result_array = $exercise_result = array();
  4113. if (empty($attempts)) {
  4114. return null;
  4115. }
  4116. foreach ($attempts as $attempt) {
  4117. if (api_get_user_id() == $attempt['exe_user_id']) {
  4118. if ($attempt['exe_weighting'] != 0 ) {
  4119. $my_exercise_result_array[]= $attempt['exe_result']/$attempt['exe_weighting'];
  4120. }
  4121. } else {
  4122. if ($attempt['exe_weighting'] != 0 ) {
  4123. $exercise_result[]= $attempt['exe_result']/$attempt['exe_weighting'];
  4124. }
  4125. }
  4126. }
  4127. //Getting best result
  4128. rsort($my_exercise_result_array);
  4129. $my_exercise_result = 0;
  4130. if (isset($my_exercise_result_array[0])) {
  4131. $my_exercise_result = $my_exercise_result_array[0] *100;
  4132. }
  4133. $max = 100;
  4134. $pieces = 5 ;
  4135. $part = round($max / $pieces);
  4136. $x_axis = array();
  4137. $final_array = array();
  4138. $my_final_array = array();
  4139. for ($i=1; $i <=$pieces; $i++) {
  4140. $sum = 1;
  4141. if ($i == 1) {
  4142. $sum = 0;
  4143. }
  4144. $min = ($i-1)*$part + $sum;
  4145. $max = ($i)*$part;
  4146. $x_axis[]= $min." - ".$max;
  4147. $count = 0;
  4148. foreach($exercise_result as $result) {
  4149. $percentage = $result*100;
  4150. //echo $percentage.' - '.$min.' - '.$max."<br />";
  4151. if ($percentage >= $min && $percentage <= $max) {
  4152. //echo ' is > ';
  4153. $count++;
  4154. }
  4155. }
  4156. //echo '<br />';
  4157. $final_array[]= $count;
  4158. if ($my_exercise_result >= $min && $my_exercise_result <= $max) {
  4159. $my_final_array[] = 1;
  4160. } else {
  4161. $my_final_array[] = 0;
  4162. }
  4163. }
  4164. //Fix to remove the data of the user with my data
  4165. for($i = 0; $i<=count($my_final_array); $i++) {
  4166. if (!empty($my_final_array[$i])) {
  4167. $my_final_array[$i] = $final_array[$i] + 1; //Add my result
  4168. $final_array[$i] = 0;
  4169. }
  4170. }
  4171. $cache = new pCache();
  4172. // Dataset definition
  4173. $data_set = new pData();
  4174. $data_set->AddPoint($final_array,"Serie1");
  4175. $data_set->AddPoint($my_final_array,"Serie2");
  4176. //$data_set->AddPoint($x_axis,"Serie3");
  4177. $data_set->AddAllSeries();
  4178. // Initialise the graph
  4179. $main_width = 80;
  4180. $main_height = 35;
  4181. $thumbnail_graph = new pChart($main_width, $main_height);
  4182. $thumbnail_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
  4183. //$thumbnail_graph->setGraphArea(50,30,680,200);
  4184. $thumbnail_graph->drawFilledRoundedRectangle(2,2,$main_width-2,$main_height-2,2,230,230,230);
  4185. $thumbnail_graph->setGraphArea(5,5,$main_width-5,$main_height-5);
  4186. $thumbnail_graph->drawGraphArea(255,255,255);
  4187. //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0
  4188. $thumbnail_graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALLSTART0, 150,150,150,FALSE,0,1,TRUE);
  4189. $thumbnail_graph->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100);
  4190. // Finish the graph
  4191. $graph_id = 'thumbnail_exercise_result_graph_'.Security::remove_XSS($_GET['course']).'-'.intval($_GET['session_id']).'-'.api_get_user_id();
  4192. if ($cache->IsInCache($graph_id, $data_set->GetData())) {
  4193. //if (0) {
  4194. //if we already created the img
  4195. //echo 'in cache';
  4196. $img_file = $cache->GetHash($graph_id,$data_set->GetData());
  4197. } else {
  4198. $cache->WriteToCache($graph_id, $data_set->GetData(), $thumbnail_graph);
  4199. ob_start();
  4200. $thumbnail_graph->Stroke();
  4201. ob_end_clean();
  4202. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  4203. }
  4204. $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  4205. return $html;
  4206. }
  4207. /**
  4208. * Generates a big graph with the number of best results
  4209. * @param array
  4210. */
  4211. static function generate_exercise_result_graph($attempts)
  4212. {
  4213. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  4214. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  4215. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  4216. $exercise_title = strip_tags($attempts['title']);
  4217. $attempts = $attempts['data'];
  4218. $my_exercise_result_array = $exercise_result = array();
  4219. if (empty($attempts)) {
  4220. return null;
  4221. }
  4222. foreach ($attempts as $attempt) {
  4223. if (api_get_user_id() == $attempt['exe_user_id']) {
  4224. if ($attempt['exe_weighting'] != 0 ) {
  4225. $my_exercise_result_array[]= $attempt['exe_result']/$attempt['exe_weighting'];
  4226. }
  4227. } else {
  4228. if ($attempt['exe_weighting'] != 0 ) {
  4229. $exercise_result[]= $attempt['exe_result']/$attempt['exe_weighting'];
  4230. }
  4231. }
  4232. }
  4233. //Getting best result
  4234. rsort($my_exercise_result_array);
  4235. $my_exercise_result = 0;
  4236. if (isset($my_exercise_result_array[0])) {
  4237. $my_exercise_result = $my_exercise_result_array[0] *100;
  4238. }
  4239. $max = 100;
  4240. $pieces = 5 ;
  4241. $part = round($max / $pieces);
  4242. $x_axis = array();
  4243. $final_array = array();
  4244. $my_final_array = array();
  4245. for ($i=1; $i <=$pieces; $i++) {
  4246. $sum = 1;
  4247. if ($i == 1) {
  4248. $sum = 0;
  4249. }
  4250. $min = ($i-1)*$part + $sum;
  4251. $max = ($i)*$part;
  4252. $x_axis[]= $min." - ".$max;
  4253. $count = 0;
  4254. foreach($exercise_result as $result) {
  4255. $percentage = $result*100;
  4256. //echo $percentage.' - '.$min.' - '.$max."<br />";
  4257. if ($percentage >= $min && $percentage <= $max) {
  4258. //echo ' is > ';
  4259. $count++;
  4260. }
  4261. }
  4262. //echo '<br />';
  4263. $final_array[]= $count;
  4264. if ($my_exercise_result >= $min && $my_exercise_result <= $max) {
  4265. $my_final_array[] = 1;
  4266. } else {
  4267. $my_final_array[] = 0;
  4268. }
  4269. }
  4270. //Fix to remove the data of the user with my data
  4271. for($i = 0; $i<=count($my_final_array); $i++) {
  4272. if (!empty($my_final_array[$i])) {
  4273. $my_final_array[$i] = $final_array[$i] + 1; //Add my result
  4274. $final_array[$i] = 0;
  4275. }
  4276. }
  4277. $cache = new pCache();
  4278. // Dataset definition
  4279. $data_set = new pData();
  4280. $data_set->AddPoint($final_array,"Serie1");
  4281. $data_set->AddPoint($my_final_array,"Serie2");
  4282. $data_set->AddPoint($x_axis,"Serie3");
  4283. $data_set->AddAllSeries();
  4284. $data_set->SetAbsciseLabelSerie('Serie3');
  4285. $data_set->SetSerieName(get_lang('Score'),"Serie1");
  4286. $data_set->SetSerieName(get_lang('MyResults'),"Serie2");
  4287. $data_set->SetXAxisName(get_lang("Score"));
  4288. // Initialise the graph
  4289. $main_width = 500;
  4290. $main_height = 250;
  4291. $main_graph = new pChart($main_width,$main_height);
  4292. $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
  4293. $main_graph->setGraphArea(50,30, $main_width -20,$main_height -50);
  4294. $main_graph->drawFilledRoundedRectangle(10,10, $main_width- 10,$main_height -10,5,240,240,240);
  4295. $main_graph->drawRoundedRectangle(7,7,$main_width - 7,$main_height - 7,5,230,230,230);
  4296. $main_graph->drawGraphArea(255,255,255,TRUE);
  4297. //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0
  4298. $main_graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALLSTART0, 150,150,150,TRUE,0,1,TRUE);
  4299. $main_graph->drawGrid(4,TRUE,230,230,230,50);
  4300. // Draw the 0 line
  4301. $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6);
  4302. // $main_graph->drawTreshold(0,143,55,72,TRUE,TRUE);
  4303. // Draw the bar graph
  4304. $data_set->RemoveSerie("Serie3");
  4305. //$main_graph->drawBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
  4306. //$main_graph->drawStackedBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
  4307. $main_graph->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100);
  4308. // Finish the graph
  4309. $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
  4310. $main_graph->drawLegend($main_width - 120,$main_height -100,$data_set->GetDataDescription(),255,255,255);
  4311. $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
  4312. $main_graph->drawTitle(180,22,$exercise_title,50,50,50);
  4313. $graph_id = 'exercise_result_graph'.Security::remove_XSS($_GET['course']).'-'.intval($_GET['session_id']).'-'.api_get_user_id();
  4314. if ($cache->IsInCache($graph_id, $data_set->GetData())) {
  4315. //if (0) {
  4316. //if we already created the img
  4317. //echo 'in cache';
  4318. $img_file = $cache->GetHash($graph_id,$data_set->GetData());
  4319. } else {
  4320. $cache->WriteToCache($graph_id, $data_set->GetData(), $main_graph);
  4321. ob_start();
  4322. $main_graph->Stroke();
  4323. ob_end_clean();
  4324. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  4325. }
  4326. $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  4327. return $html;
  4328. }
  4329. /**
  4330. * @param FormValidator $form
  4331. * @return mixed
  4332. */
  4333. public static function setUserSearchForm($form)
  4334. {
  4335. global $_configuration;
  4336. $form->addElement('text', 'keyword', get_lang('Keyword'));
  4337. $form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive')));
  4338. if (isset($_configuration['save_user_last_login']) &&
  4339. $_configuration['save_user_last_login']
  4340. ) {
  4341. $form->addElement(
  4342. 'select',
  4343. 'sleeping_days',
  4344. get_lang('InactiveDays'),
  4345. array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120)
  4346. );
  4347. }
  4348. $form->addElement('button', 'submit', get_lang('Search'));
  4349. return $form;
  4350. }
  4351. /**
  4352. * Get the progress of a exercise
  4353. * @param int $sessionId The session ID (session.id)
  4354. * @param int $courseId The course ID (course.id)
  4355. * @param int $exerciseId The quiz ID (c_quiz.id)
  4356. * @param int $answer The answer status (0 = incorrect, 1 = correct, 2 = both)
  4357. * @param array $options An array of options you can pass to the query (limit, where and order)
  4358. * @return array An array with the data of exercise(s) progress
  4359. */
  4360. public static function get_exercise_progress(
  4361. $sessionId = 0,
  4362. $courseId = 0,
  4363. $exerciseId = 0,
  4364. $date_from = null,
  4365. $date_to = null,
  4366. $options = array()
  4367. ) {
  4368. $sessionId = intval($sessionId);
  4369. $courseId = intval($courseId);
  4370. $exerciseId = intval($exerciseId);
  4371. $date_from = Database::escape_string($date_from);
  4372. $date_to = Database::escape_string($date_to);
  4373. /*
  4374. * This method gets the data by blocks, as previous attempts at one single
  4375. * query made it take ages. The logic of query division is described below
  4376. */
  4377. // Get tables names
  4378. $tuser = Database::get_main_table(TABLE_MAIN_USER);
  4379. $tquiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4380. $tquiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
  4381. $tquiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  4382. $tquiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  4383. $ttrack_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  4384. $ttrack_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  4385. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  4386. $sessions = array();
  4387. $courses = array();
  4388. // if session ID is defined but course ID is empty, get all the courses
  4389. // from that session
  4390. if (!empty($sessionId) && empty($courseId)) {
  4391. // $courses is an array of course int id as index and course details hash as value
  4392. $courses = SessionManager::get_course_list_by_session_id($sessionId);
  4393. $sessions[$sessionId] = api_get_session_info($sessionId);
  4394. } elseif (empty($sessionId) && !empty($courseId)) {
  4395. // if, to the contrary, course is defined but not sessions, get the sessions that include this course
  4396. // $sessions is an array like: [0] => ('id' => 3, 'name' => 'Session 35'), [1] => () etc;
  4397. $course = api_get_course_info_by_id($courseId);
  4398. $sessionsTemp = SessionManager::get_session_by_course($course['code']);
  4399. $courses[$courseId] = $course;
  4400. foreach ($sessionsTemp as $sessionItem) {
  4401. $sessions[$sessionItem['id']] = $sessionItem;
  4402. }
  4403. } elseif (!empty($courseId) && !empty($sessionId)) {
  4404. //none is empty
  4405. $course = api_get_course_info_by_id($courseId);
  4406. $courses[$courseId] = array($course['code']);
  4407. $courses[$courseId]['code'] = $course['code'];
  4408. $sessions[$sessionId] = api_get_session_info($sessionId);
  4409. } else {
  4410. //both are empty, not enough data, return an empty array
  4411. return array();
  4412. }
  4413. // Now we have two arrays of courses and sessions with enough data to proceed
  4414. // If no course could be found, we shouldn't return anything. Sessions can be empty (then we only return the pure-course-context results)
  4415. if (count($courses) < 1) {
  4416. return array();
  4417. }
  4418. $data = array();
  4419. // The following loop is less expensive than what it seems:
  4420. // - if a course was defined, then we only loop through sessions
  4421. // - if a session was defined, then we only loop through courses
  4422. // - if a session and a course were defined, then we only loop once
  4423. foreach ($courses as $courseIdx => $courseData) {
  4424. $where = '';
  4425. $whereParams = array();
  4426. $whereCourseCode = $courseData['code'];
  4427. $whereSessionParams = '';
  4428. if (count($sessions > 0)) {
  4429. foreach ($sessions as $sessionIdx => $sessionData) {
  4430. if (!empty($sessionIdx)) {
  4431. $whereSessionParams .= $sessionIdx.',';
  4432. }
  4433. }
  4434. $whereSessionParams = substr($whereSessionParams,0,-1);
  4435. }
  4436. if (!empty($exerciseId)) {
  4437. $exerciseId = intval($exerciseId);
  4438. $where .= ' AND q.id = %d ';
  4439. $whereParams[] = $exerciseId;
  4440. }
  4441. /*
  4442. * This feature has been disabled for now, to avoid having to
  4443. * join two very large tables
  4444. //2 = show all questions (wrong and correct answered)
  4445. if ($answer != 2) {
  4446. $answer = intval($answer);
  4447. //$where .= ' AND qa.correct = %d';
  4448. //$whereParams[] = $answer;
  4449. }
  4450. */
  4451. $limit = '';
  4452. if (!empty($options['limit'])) {
  4453. $limit = " LIMIT ".$options['limit'];
  4454. }
  4455. if (!empty($options['where'])) {
  4456. $where .= ' AND '.Database::escape_string($options['where']);
  4457. }
  4458. $order = '';
  4459. if (!empty($options['order'])) {
  4460. $order = " ORDER BY ".$options['order'];
  4461. }
  4462. if (!empty($date_to) && !empty($date_from)) {
  4463. $where .= sprintf(" AND (te.start_date BETWEEN '%s 00:00:00' AND '%s 23:59:59')", $date_from, $date_to);
  4464. }
  4465. $sql = "SELECT
  4466. te.session_id,
  4467. ta.id as attempt_id,
  4468. te.exe_user_id as user_id,
  4469. te.exe_id as exercise_attempt_id,
  4470. ta.question_id,
  4471. ta.answer as answer_id,
  4472. ta.tms as time,
  4473. te.exe_exo_id as quiz_id,
  4474. CONCAT ('c', q.c_id, '_e', q.id) as exercise_id,
  4475. q.title as quiz_title,
  4476. qq.description as description
  4477. FROM $ttrack_exercises te
  4478. INNER JOIN $ttrack_attempt ta ON ta.exe_id = te.exe_id
  4479. INNER JOIN $tquiz q ON q.id = te.exe_exo_id
  4480. INNER JOIN $tquiz_rel_question rq ON rq.exercice_id = q.id AND rq.c_id = q.c_id
  4481. INNER JOIN $tquiz_question qq
  4482. ON
  4483. qq.id = rq.question_id AND
  4484. qq.c_id = rq.c_id AND
  4485. qq.position = rq.question_order AND
  4486. ta.question_id = rq.question_id
  4487. WHERE
  4488. te.exe_cours_id = '$whereCourseCode' ".(empty($whereSessionParams)?'':"AND te.session_id IN ($whereSessionParams)")."
  4489. AND q.c_id = $courseIdx
  4490. $where $order $limit";
  4491. $sql_query = vsprintf($sql, $whereParams);
  4492. // Now browse through the results and get the data
  4493. $rs = Database::query($sql_query);
  4494. $userIds = array();
  4495. $questionIds = array();
  4496. $answerIds = array();
  4497. while ($row = Database::fetch_array($rs)) {
  4498. //only show if exercise is visible
  4499. if (api_get_item_visibility($courseData, 'quiz', $row['exercise_id'])) {
  4500. $userIds[$row['user_id']] = $row['user_id'];
  4501. $questionIds[$row['question_id']] = $row['question_id'];
  4502. $answerIds[$row['question_id']][$row['answer_id']] = $row['answer_id'];
  4503. $row['session'] = $sessions[$row['session_id']];
  4504. $data[] = $row;
  4505. }
  4506. }
  4507. // Now fill questions data. Query all questions and answers for this test to avoid
  4508. $sqlQuestions = "SELECT tq.c_id, tq.id as question_id, tq.question, tqa.id_auto,
  4509. tqa.answer, tqa.correct, tq.position, tqa.id_auto as answer_id
  4510. FROM $tquiz_question tq, $tquiz_answer tqa
  4511. WHERE
  4512. tqa.question_id = tq.id AND
  4513. tqa.c_id = tq.c_id AND
  4514. tq.c_id = $courseIdx AND
  4515. tq.id IN (".implode(',', $questionIds).")";
  4516. $resQuestions = Database::query($sqlQuestions);
  4517. $answer = array();
  4518. $question = array();
  4519. while ($rowQuestion = Database::fetch_assoc($resQuestions)) {
  4520. $questionId = $rowQuestion['question_id'];
  4521. $answerId = $rowQuestion['answer_id'];
  4522. $answer[$questionId][$answerId] = array(
  4523. 'position' => $rowQuestion['position'],
  4524. 'question' => $rowQuestion['question'],
  4525. 'answer' => $rowQuestion['answer'],
  4526. 'correct' => $rowQuestion['correct']
  4527. );
  4528. $question[$questionId]['question'] = $rowQuestion['question'];
  4529. }
  4530. // Now fill users data
  4531. $sqlUsers = "SELECT user_id, username, lastname, firstname
  4532. FROM $tuser
  4533. WHERE user_id IN (".implode(',',$userIds).")";
  4534. $resUsers = Database::query($sqlUsers);
  4535. while ($rowUser = Database::fetch_assoc($resUsers)) {
  4536. $users[$rowUser['user_id']] = $rowUser;
  4537. }
  4538. foreach ($data as $id => $row) {
  4539. $rowQuestId = $row['question_id'];
  4540. $rowAnsId = $row['answer_id'];
  4541. $data[$id]['session'] = $sessions[$row['session_id']]['name'];
  4542. $data[$id]['firstname'] = $users[$row['user_id']]['firstname'];
  4543. $data[$id]['lastname'] = $users[$row['user_id']]['lastname'];
  4544. $data[$id]['username'] = $users[$row['user_id']]['username'];
  4545. $data[$id]['answer'] = $answer[$rowQuestId][$rowAnsId]['answer'];
  4546. $data[$id]['correct'] = ($answer[$rowQuestId][$rowAnsId]['correct'] == 0 ? get_lang('No') : get_lang('Yes'));
  4547. $data[$id]['question'] = $question[$rowQuestId]['question'];
  4548. $data[$id]['question_id'] = $rowQuestId;
  4549. $data[$id]['description'] = $row['description'];
  4550. }
  4551. /*
  4552. The minimum expected array structure at the end is:
  4553. attempt_id,
  4554. session name,
  4555. exercise_id,
  4556. quiz_title,
  4557. username,
  4558. lastname,
  4559. firstname,
  4560. time,
  4561. question_id,
  4562. question,
  4563. answer,
  4564. */
  4565. }
  4566. return $data;
  4567. }
  4568. }
  4569. /**
  4570. * @todo move into a proper file
  4571. * @package chamilo.tracking
  4572. */
  4573. class TrackingCourseLog
  4574. {
  4575. /**
  4576. * @return mixed
  4577. */
  4578. public static function count_item_resources()
  4579. {
  4580. $session_id = api_get_session_id();
  4581. $course_id = api_get_course_int_id();
  4582. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  4583. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  4584. $sql = "SELECT count(tool) AS total_number_of_items
  4585. FROM $table_item_property track_resource, $table_user user
  4586. WHERE
  4587. track_resource.c_id = $course_id AND
  4588. track_resource.insert_user_id = user.user_id AND
  4589. id_session = $session_id ";
  4590. if (isset($_GET['keyword'])) {
  4591. $keyword = Database::escape_string(trim($_GET['keyword']));
  4592. $sql .= " AND (
  4593. user.username LIKE '%".$keyword."%' OR
  4594. lastedit_type LIKE '%".$keyword."%' OR
  4595. tool LIKE '%".$keyword."%'
  4596. )";
  4597. }
  4598. $sql .= " AND tool IN (
  4599. 'document',
  4600. 'learnpath',
  4601. 'quiz',
  4602. 'glossary',
  4603. 'link',
  4604. 'course_description',
  4605. 'announcement',
  4606. 'thematic',
  4607. 'thematic_advance',
  4608. 'thematic_plan'
  4609. )";
  4610. $res = Database::query($sql);
  4611. $obj = Database::fetch_object($res);
  4612. return $obj->total_number_of_items;
  4613. }
  4614. /**
  4615. * @param $from
  4616. * @param $number_of_items
  4617. * @param $column
  4618. * @param $direction
  4619. * @return array
  4620. */
  4621. public static function get_item_resources_data($from, $number_of_items, $column, $direction)
  4622. {
  4623. $session_id = api_get_session_id();
  4624. $course_id = api_get_course_int_id();
  4625. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  4626. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  4627. $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  4628. $session_id = intval($session_id);
  4629. $sql = "SELECT
  4630. tool as col0,
  4631. lastedit_type as col1,
  4632. ref as ref,
  4633. user.username as col3,
  4634. insert_date as col5,
  4635. visibility as col6,
  4636. user.user_id as user_id
  4637. FROM $table_item_property track_resource, $table_user user
  4638. WHERE
  4639. track_resource.c_id = $course_id AND
  4640. track_resource.insert_user_id = user.user_id AND
  4641. id_session = $session_id ";
  4642. if (isset($_GET['keyword'])) {
  4643. $keyword = Database::escape_string(trim($_GET['keyword']));
  4644. $sql .= " AND (
  4645. user.username LIKE '%".$keyword."%' OR
  4646. lastedit_type LIKE '%".$keyword."%' OR
  4647. tool LIKE '%".$keyword."%'
  4648. ) ";
  4649. }
  4650. $sql .= " AND tool IN (
  4651. 'document',
  4652. 'learnpath',
  4653. 'quiz',
  4654. 'glossary',
  4655. 'link',
  4656. 'course_description',
  4657. 'announcement',
  4658. 'thematic',
  4659. 'thematic_advance',
  4660. 'thematic_plan'
  4661. )";
  4662. if ($column == 0) {
  4663. $column = '0';
  4664. }
  4665. if ($column != '' && $direction != '') {
  4666. if ($column != 2 && $column != 4) {
  4667. $sql .= " ORDER BY col$column $direction";
  4668. }
  4669. } else {
  4670. $sql .= " ORDER BY col5 DESC ";
  4671. }
  4672. $from = intval($from);
  4673. $number_of_items = intval($number_of_items);
  4674. $sql .= " LIMIT $from, $number_of_items ";
  4675. $res = Database::query($sql);
  4676. $resources = array();
  4677. $thematic_tools = array('thematic', 'thematic_advance', 'thematic_plan');
  4678. while ($row = Database::fetch_array($res)) {
  4679. $ref = $row['ref'];
  4680. $table_name = TrackingCourseLog::get_tool_name_table($row['col0']);
  4681. $table_tool = Database :: get_course_table($table_name['table_name']);
  4682. $id = $table_name['id_tool'];
  4683. $recorset = false;
  4684. if (in_array($row['col0'], array('thematic_plan', 'thematic_advance'))) {
  4685. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  4686. $sql = "SELECT thematic_id FROM $table_tool WHERE c_id = $course_id AND id = $ref";
  4687. $rs_thematic = Database::query($sql);
  4688. if (Database::num_rows($rs_thematic)) {
  4689. $row_thematic = Database::fetch_array($rs_thematic);
  4690. $thematic_id = $row_thematic['thematic_id'];
  4691. $sql = "SELECT session.id, session.name, user.username
  4692. FROM $tbl_thematic t, $table_session session, $table_user user
  4693. WHERE
  4694. t.c_id = $course_id AND
  4695. t.session_id = session.id AND
  4696. session.id_coach = user.user_id AND
  4697. t.id = $thematic_id";
  4698. $recorset = Database::query($sql);
  4699. }
  4700. } else {
  4701. $sql = "SELECT session.id, session.name, user.username
  4702. FROM $table_tool tool, $table_session session, $table_user user
  4703. WHERE
  4704. tool.c_id = $course_id AND
  4705. tool.session_id = session.id AND
  4706. session.id_coach = user.user_id AND
  4707. tool.$id = $ref";
  4708. $recorset = Database::query($sql);
  4709. }
  4710. if (!empty($recorset)) {
  4711. $obj = Database::fetch_object($recorset);
  4712. $name_session = '';
  4713. $coach_name = '';
  4714. if (!empty($obj)) {
  4715. $name_session = $obj->name;
  4716. $coach_name = $obj->username;
  4717. }
  4718. $url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
  4719. $row[0] = '';
  4720. if ($row['col6'] != 2) {
  4721. if (in_array($row['col0'], $thematic_tools)) {
  4722. $exp_thematic_tool = explode('_', $row['col0']);
  4723. $thematic_tool_title = '';
  4724. if (is_array($exp_thematic_tool)) {
  4725. foreach ($exp_thematic_tool as $exp) {
  4726. $thematic_tool_title .= api_ucfirst($exp);
  4727. }
  4728. } else {
  4729. $thematic_tool_title = api_ucfirst($row['col0']);
  4730. }
  4731. $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&action=thematic_details">'.get_lang($thematic_tool_title).'</a>';
  4732. } else {
  4733. $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'">'.get_lang('Tool'.api_ucfirst($row['col0'])).'</a>';
  4734. }
  4735. } else {
  4736. $row[0] = api_ucfirst($row['col0']);
  4737. }
  4738. $row[1] = get_lang($row[1]);
  4739. $row[6] = api_convert_and_format_date($row['col5'], null, date_default_timezone_get());
  4740. $row[5] = '';
  4741. //@todo Improve this code please
  4742. switch ($table_name['table_name']) {
  4743. case 'document' :
  4744. $sql = "SELECT tool.title as title FROM $table_tool tool
  4745. WHERE c_id = $course_id AND id = $ref";
  4746. $rs_document = Database::query($sql);
  4747. $obj_document = Database::fetch_object($rs_document);
  4748. $row[5] = $obj_document->title;
  4749. break;
  4750. case 'announcement':
  4751. $sql = "SELECT title FROM $table_tool
  4752. WHERE c_id = $course_id AND id = $ref";
  4753. $rs_document = Database::query($sql);
  4754. $obj_document = Database::fetch_object($rs_document);
  4755. $row[5] = $obj_document->title;
  4756. break;
  4757. case 'glossary':
  4758. $sql = "SELECT name FROM $table_tool
  4759. WHERE c_id = $course_id AND glossary_id = $ref";
  4760. $rs_document = Database::query($sql);
  4761. $obj_document = Database::fetch_object($rs_document);
  4762. $row[5] = $obj_document->name;
  4763. break;
  4764. case 'lp':
  4765. $sql = "SELECT name
  4766. FROM $table_tool WHERE c_id = $course_id AND id = $ref";
  4767. $rs_document = Database::query($sql);
  4768. $obj_document = Database::fetch_object($rs_document);
  4769. $row[5] = $obj_document->name;
  4770. break;
  4771. case 'quiz':
  4772. $sql = "SELECT title FROM $table_tool
  4773. WHERE c_id = $course_id AND id = $ref";
  4774. $rs_document = Database::query($sql);
  4775. $obj_document = Database::fetch_object($rs_document);
  4776. $row[5] = $obj_document->title;
  4777. break;
  4778. case 'course_description':
  4779. $sql = "SELECT title FROM $table_tool
  4780. WHERE c_id = $course_id AND id = $ref";
  4781. $rs_document = Database::query($sql);
  4782. $obj_document = Database::fetch_object($rs_document);
  4783. $row[5] = $obj_document->title;
  4784. break;
  4785. case 'thematic':
  4786. $rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
  4787. if (Database::num_rows($rs) > 0) {
  4788. $obj = Database::fetch_object($rs);
  4789. $row[5] = $obj->title;
  4790. }
  4791. break;
  4792. case 'thematic_advance':
  4793. $rs = Database::query("SELECT content FROM $table_tool WHERE c_id = $course_id AND id = $ref");
  4794. if (Database::num_rows($rs) > 0) {
  4795. $obj = Database::fetch_object($rs);
  4796. $row[5] = $obj->content;
  4797. }
  4798. break;
  4799. case 'thematic_plan':
  4800. $rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
  4801. if (Database::num_rows($rs) > 0) {
  4802. $obj = Database::fetch_object($rs);
  4803. $row[5] = $obj->title;
  4804. }
  4805. break;
  4806. default:
  4807. break;
  4808. }
  4809. $row2 = $name_session;
  4810. if (!empty($coach_name)) {
  4811. $row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
  4812. }
  4813. $row[2] = $row2;
  4814. if (!empty($row['col3'])) {
  4815. $row['col3'] = Display::url(
  4816. $row['col3'],
  4817. api_get_path(WEB_CODE_PATH).'user/userInfo.php?'.api_get_cidreq().'&origin=tracking&uInfo='.$row['user_id']
  4818. );
  4819. $row[3] = $row['col3'];
  4820. $ip = TrackingUserLog::get_ip_from_user_event($row['user_id'], $row['col5'], true);
  4821. if (empty($ip)) {
  4822. $ip = get_lang('Unknown');
  4823. }
  4824. $row[4] = $ip;
  4825. }
  4826. $resources[] = $row;
  4827. }
  4828. }
  4829. return $resources;
  4830. }
  4831. /**
  4832. * @param string $tool
  4833. *
  4834. * @return array
  4835. */
  4836. public static function get_tool_name_table($tool)
  4837. {
  4838. switch ($tool) {
  4839. case 'document':
  4840. $table_name = TABLE_DOCUMENT;
  4841. $link_tool = 'document/document.php';
  4842. $id_tool = 'id';
  4843. break;
  4844. case 'learnpath':
  4845. $table_name = TABLE_LP_MAIN;
  4846. $link_tool = 'newscorm/lp_controller.php';
  4847. $id_tool = 'id';
  4848. break;
  4849. case 'quiz':
  4850. $table_name = TABLE_QUIZ_TEST;
  4851. $link_tool = 'exercice/exercice.php';
  4852. $id_tool = 'id';
  4853. break;
  4854. case 'glossary':
  4855. $table_name = TABLE_GLOSSARY;
  4856. $link_tool = 'glossary/index.php';
  4857. $id_tool = 'glossary_id';
  4858. break;
  4859. case 'link':
  4860. $table_name = TABLE_LINK;
  4861. $link_tool = 'link/link.php';
  4862. $id_tool = 'id';
  4863. break;
  4864. case 'course_description':
  4865. $table_name = TABLE_COURSE_DESCRIPTION;
  4866. $link_tool = 'course_description/';
  4867. $id_tool = 'id';
  4868. break;
  4869. case 'announcement':
  4870. $table_name = TABLE_ANNOUNCEMENT;
  4871. $link_tool = 'announcements/announcements.php';
  4872. $id_tool = 'id';
  4873. break;
  4874. case 'thematic':
  4875. $table_name = TABLE_THEMATIC;
  4876. $link_tool = 'course_progress/index.php';
  4877. $id_tool = 'id';
  4878. break;
  4879. case 'thematic_advance':
  4880. $table_name = TABLE_THEMATIC_ADVANCE;
  4881. $link_tool = 'course_progress/index.php';
  4882. $id_tool = 'id';
  4883. break;
  4884. case 'thematic_plan':
  4885. $table_name = TABLE_THEMATIC_PLAN;
  4886. $link_tool = 'course_progress/index.php';
  4887. $id_tool = 'id';
  4888. break;
  4889. default:
  4890. $table_name = $tool;
  4891. break;
  4892. }
  4893. return array(
  4894. 'table_name' => $table_name,
  4895. 'link_tool' => $link_tool,
  4896. 'id_tool' => $id_tool
  4897. );
  4898. }
  4899. public static function display_additional_profile_fields()
  4900. {
  4901. // getting all the extra profile fields that are defined by the platform administrator
  4902. $extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
  4903. // creating the form
  4904. $return = '<form action="courseLog.php" method="get" name="additional_profile_field_form" id="additional_profile_field_form">';
  4905. // the select field with the additional user profile fields (= this is where we select the field of which we want to see
  4906. // the information the users have entered or selected.
  4907. $return .= '<select name="additional_profile_field">';
  4908. $return .= '<option value="-">'.get_lang('SelectFieldToAdd').'</option>';
  4909. $extra_fields_to_show = 0;
  4910. foreach ($extra_fields as $key=>$field) {
  4911. // show only extra fields that are visible + and can be filtered, added by J.Montoya
  4912. if ($field[6]==1 && $field[8] == 1) {
  4913. if (isset($_GET['additional_profile_field']) && $field[0] == $_GET['additional_profile_field'] ) {
  4914. $selected = 'selected="selected"';
  4915. } else {
  4916. $selected = '';
  4917. }
  4918. $extra_fields_to_show++;
  4919. $return .= '<option value="'.$field[0].'" '.$selected.'>'.$field[3].'</option>';
  4920. }
  4921. }
  4922. $return .= '</select>';
  4923. // the form elements for the $_GET parameters (because the form is passed through GET
  4924. foreach ($_GET as $key=>$value){
  4925. if ($key <> 'additional_profile_field') {
  4926. $return .= '<input type="hidden" name="'.Security::remove_XSS($key).'" value="'.Security::remove_XSS($value).'" />';
  4927. }
  4928. }
  4929. // the submit button
  4930. $return .= '<button class="save" type="submit">'.get_lang('AddAdditionalProfileField').'</button>';
  4931. $return .= '</form>';
  4932. if ($extra_fields_to_show > 0) {
  4933. return $return;
  4934. } else {
  4935. return '';
  4936. }
  4937. }
  4938. /**
  4939. * This function gets all the information of a certrain ($field_id) additional profile field.
  4940. * It gets the information of all the users so that it can be displayed in the sortable table or in the csv or xls export
  4941. *
  4942. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  4943. * @since October 2009
  4944. * @version 1.8.7
  4945. */
  4946. public function get_addtional_profile_information_of_field($field_id)
  4947. {
  4948. // Database table definition
  4949. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  4950. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  4951. $sql = "SELECT user.user_id, field.field_value FROM $table_user user, $table_user_field_values field
  4952. WHERE user.user_id = field.user_id
  4953. AND field.field_id='".intval($field_id)."'";
  4954. $result = Database::query($sql);
  4955. while($row = Database::fetch_array($result)) {
  4956. $return[$row['user_id']][] = $row['field_value'];
  4957. }
  4958. return $return;
  4959. }
  4960. /**
  4961. * This function gets all the information of a certrain ($field_id)
  4962. * additional profile field for a specific list of users is more efficent
  4963. * than get_addtional_profile_information_of_field() function
  4964. * It gets the information of all the users so that it can be displayed
  4965. * in the sortable table or in the csv or xls export
  4966. *
  4967. * @author Julio Montoya <gugli100@gmail.com>
  4968. * @param int field id
  4969. * @param array list of user ids
  4970. * @return array
  4971. * @since Nov 2009
  4972. * @version 1.8.6.2
  4973. */
  4974. public function get_addtional_profile_information_of_field_by_user($field_id, $users)
  4975. {
  4976. // Database table definition
  4977. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  4978. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  4979. $result_extra_field = UserManager::get_extra_field_information($field_id);
  4980. if (!empty($users)) {
  4981. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_TAG ) {
  4982. foreach($users as $user_id) {
  4983. $user_result = UserManager::get_user_tags($user_id, $field_id);
  4984. $tag_list = array();
  4985. foreach($user_result as $item) {
  4986. $tag_list[] = $item['tag'];
  4987. }
  4988. $return[$user_id][] = implode(', ',$tag_list);
  4989. }
  4990. } else {
  4991. $new_user_array = array();
  4992. foreach($users as $user_id) {
  4993. $new_user_array[]= "'".$user_id."'";
  4994. }
  4995. $users = implode(',',$new_user_array);
  4996. //selecting only the necessary information NOT ALL the user list
  4997. $sql = "SELECT user.user_id, field.field_value FROM $table_user user INNER JOIN $table_user_field_values field
  4998. ON (user.user_id = field.user_id)
  4999. WHERE field.field_id=".intval($field_id)." AND user.user_id IN ($users)";
  5000. $result = Database::query($sql);
  5001. while($row = Database::fetch_array($result)) {
  5002. // get option value for field type double select by id
  5003. if (!empty($row['field_value'])) {
  5004. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_DOUBLE_SELECT) {
  5005. $id_double_select = explode(';',$row['field_value']);
  5006. if (is_array($id_double_select)) {
  5007. $value1 = $result_extra_field['options'][$id_double_select[0]]['option_value'];
  5008. $value2 = $result_extra_field['options'][$id_double_select[1]]['option_value'];
  5009. $row['field_value'] = ($value1.';'.$value2);
  5010. }
  5011. }
  5012. }
  5013. // get other value from extra field
  5014. $return[$row['user_id']][] = $row['field_value'];
  5015. }
  5016. }
  5017. }
  5018. return $return;
  5019. }
  5020. /**
  5021. * count the number of students in this course (used for SortableTable)
  5022. * Deprecated
  5023. */
  5024. public function count_student_in_course()
  5025. {
  5026. global $nbStudents;
  5027. return $nbStudents;
  5028. }
  5029. public function sort_users($a, $b)
  5030. {
  5031. return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  5032. }
  5033. public function sort_users_desc($a, $b)
  5034. {
  5035. return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  5036. }
  5037. /**
  5038. * Get number of users for sortable with pagination
  5039. * @return int
  5040. */
  5041. public static function get_number_of_users()
  5042. {
  5043. global $user_ids;
  5044. return count($user_ids);
  5045. }
  5046. /**
  5047. * Get data for users list in sortable with pagination
  5048. * @param $from
  5049. * @param $number_of_items
  5050. * @param $column
  5051. * @param $direction
  5052. * @return array
  5053. */
  5054. public static function get_user_data($from, $number_of_items, $column, $direction)
  5055. {
  5056. global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id, $_configuration;
  5057. $course_code = Database::escape_string($course_code);
  5058. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  5059. $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  5060. $access_url_id = api_get_current_access_url_id();
  5061. // get all users data from a course for sortable with limit
  5062. $condition_user = "";
  5063. if (is_array($user_ids)) {
  5064. $user_ids = array_map('intval', $user_ids);
  5065. $condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
  5066. } else {
  5067. $user_ids = intval($user_ids);
  5068. $condition_user = " WHERE user.user_id = $user_ids ";
  5069. }
  5070. if (!empty($_GET['user_keyword'])) {
  5071. $keyword = trim(Database::escape_string($_GET['user_keyword']));
  5072. $condition_user .= " AND (user.firstname LIKE '%".$keyword."%' OR user.lastname LIKE '%".$keyword."%' OR user.username LIKE '%".$keyword."%' OR user.email LIKE '%".$keyword."%' ) ";
  5073. }
  5074. if (api_is_multiple_url_enabled()) {
  5075. $url_table = ", ".$tbl_url_rel_user."as url_users";
  5076. $url_condition = " AND user.user_id = url_users.user_id AND access_url_id='$access_url_id'";
  5077. }
  5078. $sql = "SELECT user.user_id as user_id,
  5079. user.official_code as col0,
  5080. user.lastname as col1,
  5081. user.firstname as col2,
  5082. user.username as col3
  5083. FROM $tbl_user as user $url_table
  5084. $condition_user $url_condition";
  5085. if (!in_array($direction, array('ASC','DESC'))) {
  5086. $direction = 'ASC';
  5087. }
  5088. $column = intval($column);
  5089. $from = intval($from);
  5090. $number_of_items = intval($number_of_items);
  5091. $sql .= " ORDER BY col$column $direction ";
  5092. $sql .= " LIMIT $from,$number_of_items";
  5093. $res = Database::query($sql);
  5094. $users = array();
  5095. $t = time();
  5096. $course_info = api_get_course_info($course_code);
  5097. $total_surveys = 0;
  5098. $total_exercises = get_all_exercises($course_info, $session_id);
  5099. if (empty($session_id)) {
  5100. $survey_user_list = array();
  5101. $survey_list = survey_manager::get_surveys($course_code, $session_id);
  5102. $total_surveys = count($survey_list);
  5103. $survey_data = array();
  5104. foreach ($survey_list as $survey) {
  5105. $user_list = survey_manager::get_people_who_filled_survey($survey['survey_id'], false, $course_info['real_id']);
  5106. foreach ($user_list as $user_id) {
  5107. isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : $survey_user_list[$user_id] = 1;
  5108. }
  5109. }
  5110. }
  5111. while ($user = Database::fetch_array($res, 'ASSOC')) {
  5112. $user['official_code'] = $user['col0'];
  5113. $user['lastname'] = $user['col1'];
  5114. $user['firstname'] = $user['col2'];
  5115. $user['username'] = $user['col3'];
  5116. $user['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course_code, $session_id));
  5117. $avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id);
  5118. $avg_student_progress = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id);
  5119. if (empty($avg_student_progress)) {
  5120. $avg_student_progress=0;
  5121. }
  5122. $user['average_progress'] = $avg_student_progress.'%';
  5123. $total_user_exercise = Tracking::get_exercise_student_progress($total_exercises, $user['user_id'], $course_code, $session_id);
  5124. $user['exercise_progress'] = $total_user_exercise;
  5125. $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $course_code, $session_id);
  5126. $user['exercise_average_best_attempt'] = $total_user_exercise;
  5127. if (is_numeric($avg_student_score)) {
  5128. $user['student_score'] = $avg_student_score.'%';
  5129. } else {
  5130. $user['student_score'] = $avg_student_score;
  5131. }
  5132. $user['count_assignments'] = Tracking::count_student_assignments($user['user_id'], $course_code, $session_id);
  5133. $user['count_messages'] = Tracking::count_student_messages($user['user_id'], $course_code, $session_id);
  5134. $user['first_connection'] = Tracking::get_first_connection_date_on_the_course($user['user_id'], $course_code, $session_id);
  5135. $user['last_connection'] = Tracking::get_last_connection_date_on_the_course($user['user_id'], $course_code, $session_id);
  5136. // we need to display an additional profile field
  5137. $user['additional'] = '';
  5138. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  5139. if (isset($additional_user_profile_info[$user['user_id']]) && is_array($additional_user_profile_info[$user['user_id']])) {
  5140. $user['additional'] = implode(', ', $additional_user_profile_info[$user['user_id']]);
  5141. }
  5142. }
  5143. if (empty($session_id)) {
  5144. $user['survey'] = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0) .' / '.$total_surveys;
  5145. }
  5146. $user['link'] = '<center><a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  5147. // store columns in array $users
  5148. $is_western_name_order = api_is_western_name_order();
  5149. $user_row = array();
  5150. $user_row[]= $user['official_code']; //0
  5151. if ($is_western_name_order) {
  5152. $user_row[]= $user['firstname'];
  5153. $user_row[]= $user['lastname'];
  5154. } else {
  5155. $user_row[]= $user['lastname'];
  5156. $user_row[]= $user['firstname'];
  5157. }
  5158. $user_row[]= $user['username'];
  5159. $user_row[]= $user['time'];
  5160. $user_row[]= $user['average_progress'];
  5161. $user_row[]= $user['exercise_progress'];
  5162. $user_row[]= $user['exercise_average_best_attempt'];
  5163. $user_row[]= $user['student_score'];
  5164. $user_row[]= $user['count_assignments'];
  5165. $user_row[]= $user['count_messages'];
  5166. if (empty($session_id)) {
  5167. $user_row[]= $user['survey'];
  5168. }
  5169. $user_row[]= $user['first_connection'];
  5170. $user_row[]= $user['last_connection'];
  5171. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  5172. $user_row[]= $user['additional'];
  5173. }
  5174. $user_row[]= $user['link'];
  5175. $users[] = $user_row;
  5176. if ($export_csv) {
  5177. if (empty($session_id)) {
  5178. $user_row = array_map('strip_tags', $user_row);
  5179. unset($user_row[14]);
  5180. unset($user_row[15]);
  5181. } else {
  5182. $user_row = array_map('strip_tags', $user_row);
  5183. unset($user_row[13]);
  5184. unset($user_row[14]);
  5185. }
  5186. $csv_content[] = $user_row;
  5187. }
  5188. }
  5189. return $users;
  5190. }
  5191. }
  5192. /**
  5193. * @package chamilo.tracking
  5194. */
  5195. class TrackingUserLog
  5196. {
  5197. /**
  5198. * Displays the number of logins every month for a specific user in a specific course.
  5199. */
  5200. public function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
  5201. {
  5202. $MonthsLong = $GLOBALS['MonthsLong'];
  5203. // protected data
  5204. $user_id = intval($user_id);
  5205. $session_id = intval($session_id);
  5206. $course_id = Database::escape_string($course_id);
  5207. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  5208. $tempView = $view;
  5209. if(substr($view,0,1) == '1') {
  5210. $new_view = substr_replace($view,'0',0,1);
  5211. echo "
  5212. <tr>
  5213. <td valign='top'>
  5214. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font>" .
  5215. "<b>".get_lang('LoginsAndAccessTools')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".$user_id."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=10000'>".get_lang('ExportAsCSV')."</a>]
  5216. </td>
  5217. </tr>
  5218. ";
  5219. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LoginsDetails')."<br>";
  5220. $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
  5221. FROM $track_access_table
  5222. WHERE access_user_id = '$user_id'
  5223. AND access_cours_code = '$course_id'
  5224. AND access_session_id = '$session_id'
  5225. GROUP BY YEAR(access_date),MONTH(access_date)
  5226. ORDER BY YEAR(access_date),MONTH(access_date) ASC";
  5227. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  5228. //$results = getManyResults2Col($sql);
  5229. $results = getManyResults3Col($sql);
  5230. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  5231. echo "<tr>
  5232. <td class='secLine'>
  5233. ".get_lang('LoginsTitleMonthColumn')."
  5234. </td>
  5235. <td class='secLine'>
  5236. ".get_lang('LoginsTitleCountColumn')."
  5237. </td>
  5238. </tr>";
  5239. $total = 0;
  5240. if (is_array($results)) {
  5241. for($j = 0 ; $j < count($results) ; $j++) {
  5242. echo "<tr>";
  5243. echo "<td class='content'><a href='logins_details.php?uInfo=".$user_id."&reqdate=".$results[$j][0]."&view=".Security::remove_XSS($view)."'>".$MonthsLong[date('n', $results[$j][0])-1].' '.date('Y', $results[$j][0])."</a></td>";
  5244. echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
  5245. echo"</tr>";
  5246. $total = $total + $results[$j][1];
  5247. }
  5248. echo "<tr>";
  5249. echo "<td>".get_lang('Total')."</td>";
  5250. echo "<td align='right' class='content'>".$total."</td>";
  5251. echo"</tr>";
  5252. } else {
  5253. echo "<tr>";
  5254. echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
  5255. echo"</tr>";
  5256. }
  5257. echo "</table>";
  5258. echo "</td></tr>";
  5259. } else {
  5260. $new_view = substr_replace($view,'1',0,1);
  5261. echo "
  5262. <tr>
  5263. <td valign='top'>
  5264. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".$user_id."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LoginsAndAccessTools')."</a>
  5265. </td>
  5266. </tr>
  5267. ";
  5268. }
  5269. }
  5270. /**
  5271. * Displays the exercise results for a specific user in a specific course.
  5272. * @todo remove globals
  5273. */
  5274. public function display_exercise_tracking_info($view, $user_id, $course_id)
  5275. {
  5276. global $TBL_TRACK_HOTPOTATOES, $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong;
  5277. if(substr($view,1,1) == '1') {
  5278. $new_view = substr_replace($view,'0',1,1);
  5279. echo "<tr>
  5280. <td valign='top'>
  5281. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ExercicesResults')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=01000'>".get_lang('ExportAsCSV')."</a>]
  5282. </td>
  5283. </tr>";
  5284. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('ExercicesDetails')."<br />";
  5285. $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  5286. FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
  5287. WHERE te.exe_cours_id = '".Database::escape_string($course_id)."'
  5288. AND te.exe_user_id = '".Database::escape_string($user_id)."'
  5289. AND te.exe_exo_id = ce.id
  5290. ORDER BY ce.title ASC, te.exe_date ASC";
  5291. $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  5292. FROM $TBL_TRACK_HOTPOTATOES AS te
  5293. WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_cours_id = '".Database::escape_string($course_id)."'
  5294. ORDER BY te.exe_cours_id ASC, te.exe_date ASC";
  5295. $hpresults = getManyResultsXCol($hpsql, 4);
  5296. $NoTestRes = 0;
  5297. $NoHPTestRes = 0;
  5298. echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
  5299. $results = getManyResultsXCol($sql, 4);
  5300. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
  5301. echo "
  5302. <tr bgcolor='#E6E6E6'>
  5303. <td>
  5304. ".get_lang('ExercicesTitleExerciceColumn')."
  5305. </td>
  5306. <td>
  5307. ".get_lang('Date')."
  5308. </td>
  5309. <td>
  5310. ".get_lang('ExercicesTitleScoreColumn')."
  5311. </td>
  5312. </tr>";
  5313. if (is_array($results)) {
  5314. for($i = 0; $i < sizeof($results); $i++) {
  5315. $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
  5316. echo "<tr>\n";
  5317. echo "<td class='content'>".$results[$i][0]."</td>\n";
  5318. echo "<td class='content'>".$display_date."</td>\n";
  5319. echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
  5320. echo "</tr>\n";
  5321. }
  5322. } else {
  5323. // istvan begin
  5324. $NoTestRes = 1;
  5325. }
  5326. // The Result of Tests
  5327. if(is_array($hpresults)) {
  5328. for($i = 0; $i < sizeof($hpresults); $i++) {
  5329. $title = GetQuizName($hpresults[$i][0],'');
  5330. if ($title == '')
  5331. $title = basename($hpresults[$i][0]);
  5332. $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
  5333. ?>
  5334. <tr>
  5335. <td class="content"><?php echo $title; ?></td>
  5336. <td class="content" align="center"><?php echo $display_date; ?></td>
  5337. <td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?>
  5338. </td>
  5339. </tr>
  5340. <?php }
  5341. } else {
  5342. $NoHPTestRes = 1;
  5343. }
  5344. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  5345. echo "<tr>\n";
  5346. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>\n";
  5347. echo "</tr>\n";
  5348. }
  5349. echo "</table>";
  5350. echo "</td>\n</tr>\n";
  5351. } else {
  5352. $new_view = substr_replace($view,'1',1,1);
  5353. echo "
  5354. <tr>
  5355. <td valign='top'>
  5356. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".get_lang('ExercicesResults')."</a>
  5357. </td>
  5358. </tr>";
  5359. }
  5360. }
  5361. /**
  5362. * Displays the student publications for a specific user in a specific course.
  5363. * @todo remove globals
  5364. */
  5365. public function display_student_publications_tracking_info($view, $user_id, $course_id)
  5366. {
  5367. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong, $_course;
  5368. if (substr($view,2,1) == '1') {
  5369. $new_view = substr_replace($view,'0',2,1);
  5370. echo "<tr>
  5371. <td valign='top'>
  5372. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('WorkUploads')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00100'>".get_lang('ExportAsCSV')."</a>]
  5373. </td>
  5374. </tr>";
  5375. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('WorksDetails')."<br>";
  5376. $sql = "SELECT u.upload_date, w.title, w.author,w.url
  5377. FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
  5378. WHERE u.upload_work_id = w.id
  5379. AND u.upload_user_id = '".Database::escape_string($user_id)."'
  5380. AND u.upload_cours_id = '".Database::escape_string($course_id)."'
  5381. ORDER BY u.upload_date DESC";
  5382. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  5383. $results = getManyResultsXCol($sql,4);
  5384. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  5385. echo "<tr>
  5386. <td class='secLine' width='40%'>
  5387. ".get_lang('WorkTitle')."
  5388. </td>
  5389. <td class='secLine' width='30%'>
  5390. ".get_lang('WorkAuthors')."
  5391. </td>
  5392. <td class='secLine' width='30%'>
  5393. ".get_lang('Date')."
  5394. </td>
  5395. </tr>";
  5396. if (is_array($results)) {
  5397. for($j = 0 ; $j < count($results) ; $j++) {
  5398. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  5399. $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
  5400. echo "<tr>";
  5401. echo "<td class='content'>"
  5402. ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
  5403. ."</td>";
  5404. echo "<td class='content'>".$results[$j][2]."</td>";
  5405. echo "<td class='content'>".$beautifulDate."</td>";
  5406. echo"</tr>";
  5407. }
  5408. } else {
  5409. echo "<tr>";
  5410. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
  5411. echo"</tr>";
  5412. }
  5413. echo "</table>";
  5414. echo "</td></tr>";
  5415. } else {
  5416. $new_view = substr_replace($view,'1',2,1);
  5417. echo "
  5418. <tr>
  5419. <td valign='top'>
  5420. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('WorkUploads')."</a>
  5421. </td>
  5422. </tr>
  5423. ";
  5424. }
  5425. }
  5426. /**
  5427. * Displays the links followed for a specific user in a specific course.
  5428. * @todo remove globals
  5429. */
  5430. public function display_links_tracking_info($view, $user_id, $course_id)
  5431. {
  5432. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  5433. if (substr($view,3,1) == '1') {
  5434. $new_view = substr_replace($view,'0',3,1);
  5435. echo "
  5436. <tr>
  5437. <td valign='top'>
  5438. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('LinksAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00010'>".get_lang('ExportAsCSV')."</a>]
  5439. </td>
  5440. </tr>
  5441. ";
  5442. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LinksDetails')."<br>";
  5443. $sql = "SELECT cl.title, cl.url
  5444. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  5445. WHERE sl.links_link_id = cl.id
  5446. AND sl.links_cours_id = '".Database::escape_string($course_id)."'
  5447. AND sl.links_user_id = '".Database::escape_string($user_id)."'
  5448. GROUP BY cl.title, cl.url";
  5449. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  5450. $results = getManyResults2Col($sql);
  5451. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  5452. echo "<tr>
  5453. <td class='secLine'>
  5454. ".get_lang('LinksTitleLinkColumn')."
  5455. </td>
  5456. </tr>";
  5457. if (is_array($results)) {
  5458. for($j = 0 ; $j < count($results) ; $j++) {
  5459. echo "<tr>";
  5460. echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
  5461. echo"</tr>";
  5462. }
  5463. } else {
  5464. echo "<tr>";
  5465. echo "<td ><center>".get_lang('NoResult')."</center></td>";
  5466. echo"</tr>";
  5467. }
  5468. echo "</table>";
  5469. echo "</td></tr>";
  5470. } else {
  5471. $new_view = substr_replace($view,'1',3,1);
  5472. echo "
  5473. <tr>
  5474. <td valign='top'>
  5475. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LinksAccess')."</a>
  5476. </td>
  5477. </tr>
  5478. ";
  5479. }
  5480. }
  5481. /**
  5482. * Displays the documents downloaded for a specific user in a specific course.
  5483. * @param string kind of view inside tracking info
  5484. * @param int User id
  5485. * @param string Course code
  5486. * @param int Session id (optional, default = 0)
  5487. * @return void
  5488. */
  5489. public static function display_document_tracking_info($view, $user_id, $course_id, $session_id = 0) {
  5490. // protect data
  5491. $user_id = intval($user_id);
  5492. $course_id = Database::escape_string($course_id);
  5493. $session_id = intval($session_id);
  5494. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  5495. if(substr($view,4,1) == '1') {
  5496. $new_view = substr_replace($view,'0',4,1);
  5497. echo "
  5498. <tr>
  5499. <td valign='top'>
  5500. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('DocumentsAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00001'>".get_lang('ExportAsCSV')."</a>]
  5501. </td>
  5502. </tr>
  5503. ";
  5504. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('DocumentsDetails')."<br>";
  5505. $sql = "SELECT down_doc_path
  5506. FROM $downloads_table
  5507. WHERE down_cours_id = '".$course_id."'
  5508. AND down_user_id = '$user_id'
  5509. AND down_session_id = '$session_id'
  5510. GROUP BY down_doc_path";
  5511. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  5512. $results = getManyResults1Col($sql);
  5513. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
  5514. echo "<tr>
  5515. <td class='secLine'>
  5516. ".get_lang('DocumentsTitleDocumentColumn')."
  5517. </td>
  5518. </tr>";
  5519. if (is_array($results)) {
  5520. for($j = 0 ; $j < count($results) ; $j++) {
  5521. echo "<tr>";
  5522. echo "<td class='content'>".$results[$j]."</td>";
  5523. echo"</tr>";
  5524. }
  5525. } else {
  5526. echo "<tr>";
  5527. echo "<td><center>".get_lang('NoResult')."</center></td>";
  5528. echo"</tr>";
  5529. }
  5530. echo "</table>";
  5531. echo "</td></tr>";
  5532. } else {
  5533. $new_view = substr_replace($view,'1',4,1);
  5534. echo "
  5535. <tr>
  5536. <td valign='top'>
  5537. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('DocumentsAccess')."</a>
  5538. </td>
  5539. </tr>
  5540. ";
  5541. }
  5542. }
  5543. /**
  5544. * Gets the IP of a given user, using the last login before the given date
  5545. * @param int User ID
  5546. * @param string Datetime
  5547. * @param bool Whether to return the IP as a link or just as an IP
  5548. * @param string If defined and return_as_link if true, will be used as the text to be shown as the link
  5549. * @return string IP address (or false on error)
  5550. * @assert (0,0) === false
  5551. */
  5552. public static function get_ip_from_user_event($user_id, $event_date, $return_as_link = false, $body_replace = null) {
  5553. if (empty($user_id) or empty($event_date)) {
  5554. return false;
  5555. }
  5556. $table_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  5557. $sql_ip = "SELECT login_date, login_ip FROM $table_login WHERE login_user_id = $user_id AND login_date < '$event_date' ORDER BY login_date DESC LIMIT 1";
  5558. $ip = '';
  5559. $res_ip = Database::query($sql_ip);
  5560. if ($res_ip !== false && Database::num_rows($res_ip)>0) {
  5561. $row_ip = Database::fetch_row($res_ip);
  5562. if ($return_as_link) {
  5563. $ip = Display::url((empty($body_replace)?$row_ip[1]:$body_replace), 'http://www.whatsmyip.org/ip-geo-location/?ip='.$row_ip[1], array('title'=>get_lang('TraceIP'), 'target'=>'_blank'));
  5564. } else {
  5565. $ip = $row_ip[1];
  5566. }
  5567. }
  5568. return $ip;
  5569. }
  5570. }
  5571. /**
  5572. * @package chamilo.tracking
  5573. */
  5574. class TrackingUserLogCSV
  5575. {
  5576. /**
  5577. * Displays the number of logins every month for a specific user in a specific course.
  5578. */
  5579. public function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
  5580. {
  5581. $MonthsLong = $GLOBALS['MonthsLong'];
  5582. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  5583. // protected data
  5584. $user_id = intval($user_id);
  5585. $session_id = intval($session_id);
  5586. $course_id = Database::escape_string($course_id);
  5587. $tempView = $view;
  5588. if(substr($view,0,1) == '1')
  5589. {
  5590. $new_view = substr_replace($view,'0',0,1);
  5591. $title[1]= get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
  5592. $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
  5593. FROM $track_access_table
  5594. WHERE access_user_id = '$user_id'
  5595. AND access_cours_code = '".$course_id."'
  5596. AND access_session_id = '$session_id'
  5597. GROUP BY YEAR(access_date),MONTH(access_date)
  5598. ORDER BY YEAR(access_date),MONTH(access_date) ASC";
  5599. //$results = getManyResults2Col($sql);
  5600. $results = getManyResults3Col($sql);
  5601. $title_line= get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
  5602. $line='';
  5603. $total = 0;
  5604. if (is_array($results)) {
  5605. for($j = 0 ; $j < count($results) ; $j++) {
  5606. $line .= $results[$j][0].';'.$results[$j][1]."\n";
  5607. $total = $total + $results[$j][1];
  5608. }
  5609. $line .= get_lang('Total').";".$total."\n";
  5610. } else {
  5611. $line= get_lang('NoResult')."</center></td>";
  5612. }
  5613. } else {
  5614. $new_view = substr_replace($view,'1',0,1);
  5615. }
  5616. return array($title_line, $line);
  5617. }
  5618. /**
  5619. * Displays the exercise results for a specific user in a specific course.
  5620. * @todo remove globals
  5621. */
  5622. public function display_exercise_tracking_info($view, $user_id, $course_id)
  5623. {
  5624. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong;
  5625. if (substr($view,1,1) == '1') {
  5626. $new_view = substr_replace($view,'0',1,1);
  5627. $title[1]= get_lang('ExercicesDetails');
  5628. $line='';
  5629. $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  5630. FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
  5631. WHERE te.exe_cours_id = '$course_id'
  5632. AND te.exe_user_id = '$user_id'
  5633. AND te.exe_exo_id = ce.id
  5634. ORDER BY ce.title ASC, te.exe_date ASC";
  5635. $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  5636. FROM $TABLETRACK_HOTPOTATOES AS te
  5637. WHERE te.exe_user_id = '$user_id' AND te.exe_cours_id = '$course_id'
  5638. ORDER BY te.exe_cours_id ASC, te.exe_date ASC";
  5639. $hpresults = getManyResultsXCol($hpsql, 4);
  5640. $NoTestRes = 0;
  5641. $NoHPTestRes = 0;
  5642. $results = getManyResultsXCol($sql, 4);
  5643. $title_line=get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
  5644. if (is_array($results)) {
  5645. for($i = 0; $i < sizeof($results); $i++)
  5646. {
  5647. $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
  5648. $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
  5649. }
  5650. } else {
  5651. // istvan begin
  5652. $NoTestRes = 1;
  5653. }
  5654. // The Result of Tests
  5655. if (is_array($hpresults)) {
  5656. for($i = 0; $i < sizeof($hpresults); $i++) {
  5657. $title = GetQuizName($hpresults[$i][0],'');
  5658. if ($title == '')
  5659. $title = basename($hpresults[$i][0]);
  5660. $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
  5661. $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
  5662. }
  5663. } else {
  5664. $NoHPTestRes = 1;
  5665. }
  5666. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  5667. $line=get_lang('NoResult');
  5668. }
  5669. } else {
  5670. $new_view = substr_replace($view,'1',1,1);
  5671. }
  5672. return array($title_line, $line);
  5673. }
  5674. /**
  5675. * Displays the student publications for a specific user in a specific course.
  5676. * @todo remove globals
  5677. */
  5678. public function display_student_publications_tracking_info($view, $user_id, $course_id)
  5679. {
  5680. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong, $_course;
  5681. if (substr($view,2,1) == '1') {
  5682. $new_view = substr_replace($view,'0',2,1);
  5683. $sql = "SELECT u.upload_date, w.title, w.author, w.url
  5684. FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
  5685. WHERE u.upload_work_id = w.id
  5686. AND u.upload_user_id = '$user_id'
  5687. AND u.upload_cours_id = '$course_id'
  5688. ORDER BY u.upload_date DESC";
  5689. $results = getManyResultsXCol($sql,4);
  5690. $title[1]=get_lang('WorksDetails');
  5691. $line='';
  5692. $title_line=get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
  5693. if (is_array($results)) {
  5694. for($j = 0 ; $j < count($results) ; $j++) {
  5695. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  5696. $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
  5697. $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
  5698. }
  5699. } else {
  5700. $line= get_lang('NoResult');
  5701. }
  5702. } else {
  5703. $new_view = substr_replace($view,'1',2,1);
  5704. }
  5705. return array($title_line, $line);
  5706. }
  5707. /**
  5708. * Displays the links followed for a specific user in a specific course.
  5709. * @todo remove globals
  5710. */
  5711. public function display_links_tracking_info($view, $user_id, $course_id)
  5712. {
  5713. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  5714. $line = null;
  5715. if (substr($view,3,1) == '1') {
  5716. $new_view = substr_replace($view,'0',3,1);
  5717. $title[1]=get_lang('LinksDetails');
  5718. $sql = "SELECT cl.title, cl.url
  5719. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  5720. WHERE sl.links_link_id = cl.id
  5721. AND sl.links_cours_id = '$course_id'
  5722. AND sl.links_user_id = '$user_id'
  5723. GROUP BY cl.title, cl.url";
  5724. $results = getManyResults2Col($sql);
  5725. $title_line= get_lang('LinksTitleLinkColumn')."\n";
  5726. if (is_array($results)) {
  5727. for ($j = 0 ; $j < count($results) ; $j++) {
  5728. $line .= $results[$j][0]."\n";
  5729. }
  5730. } else {
  5731. $line=get_lang('NoResult');
  5732. }
  5733. } else {
  5734. $new_view = substr_replace($view,'1',3,1);
  5735. }
  5736. return array($title_line, $line);
  5737. }
  5738. /**
  5739. * Displays the documents downloaded for a specific user in a specific course.
  5740. * @param string kind of view inside tracking info
  5741. * @param int User id
  5742. * @param string Course code
  5743. * @param int Session id (optional, default = 0)
  5744. * @return void
  5745. */
  5746. public function display_document_tracking_info($view, $user_id, $course_id, $session_id = 0)
  5747. {
  5748. // protect data
  5749. $user_id = intval($user_id);
  5750. $course_id = Database::escape_string($course_id);
  5751. $session_id = intval($session_id);
  5752. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  5753. if (substr($view,4,1) == '1') {
  5754. $new_view = substr_replace($view,'0',4,1);
  5755. $title[1]= get_lang('DocumentsDetails');
  5756. $sql = "SELECT down_doc_path
  5757. FROM $downloads_table
  5758. WHERE down_cours_id = '$course_id'
  5759. AND down_user_id = '$user_id'
  5760. AND down_session_id = '$session_id'
  5761. GROUP BY down_doc_path";
  5762. $results = getManyResults1Col($sql);
  5763. $title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
  5764. $line = null;
  5765. if (is_array($results)) {
  5766. for ($j = 0 ; $j < count($results) ; $j++) {
  5767. $line .= $results[$j]."\n";
  5768. }
  5769. } else {
  5770. $line = get_lang('NoResult');
  5771. }
  5772. } else {
  5773. $new_view = substr_replace($view,'1',4,1);
  5774. }
  5775. return array($title_line, $line);
  5776. }
  5777. /**
  5778. * @param $userId
  5779. * @param $courseInfo
  5780. * @param int $sessionId
  5781. * @return array
  5782. */
  5783. public static function getToolInformation(
  5784. $userId,
  5785. $courseInfo,
  5786. $sessionId = 0
  5787. ) {
  5788. $csvContent = array();
  5789. $courseToolInformation = null;
  5790. $headerTool = array(
  5791. array(get_lang('Title')),
  5792. array(get_lang('CreatedAt')),
  5793. array(get_lang('UpdatedAt')),
  5794. );
  5795. $headerListForCSV = array();
  5796. foreach ($headerTool as $item) {
  5797. $headerListForCSV[] = $item[0];
  5798. }
  5799. $courseForumInformationArray = getForumCreatedByUser(
  5800. $userId,
  5801. $courseInfo['real_id'],
  5802. $sessionId
  5803. );
  5804. if (!empty($courseForumInformationArray)) {
  5805. $csvContent[] = array();
  5806. $csvContent[] = get_lang('Forums');
  5807. $csvContent[] = $headerListForCSV;
  5808. foreach ($courseForumInformationArray as $row) {
  5809. $csvContent[] = $row;
  5810. }
  5811. $courseToolInformation .= Display::page_subheader2(
  5812. get_lang('Forums')
  5813. );
  5814. $courseToolInformation .= Display::return_sortable_table(
  5815. $headerTool,
  5816. $courseForumInformationArray
  5817. );
  5818. }
  5819. $courseWorkInformationArray = getWorkCreatedByUser(
  5820. $userId,
  5821. $courseInfo['real_id'],
  5822. $sessionId
  5823. );
  5824. if (!empty($courseWorkInformationArray)) {
  5825. $csvContent[] = null;
  5826. $csvContent[] = get_lang('Works');
  5827. $csvContent[] = $headerListForCSV;
  5828. foreach ($courseWorkInformationArray as $row) {
  5829. $csvContent[] = $row;
  5830. }
  5831. $csvContent[] = null;
  5832. $courseToolInformation .= Display::page_subheader2(
  5833. get_lang('Works')
  5834. );
  5835. $courseToolInformation .= Display::return_sortable_table(
  5836. $headerTool,
  5837. $courseWorkInformationArray
  5838. );
  5839. }
  5840. $courseToolInformationTotal = null;
  5841. if (!empty($courseToolInformation)) {
  5842. $sessionTitle = null;
  5843. if (!empty($sessionId)) {
  5844. $sessionTitle = ' ('.api_get_session_name($sessionId).')';
  5845. }
  5846. $courseToolInformationTotal .= Display::page_subheader(
  5847. $courseInfo['title'].$sessionTitle
  5848. );
  5849. $courseToolInformationTotal .= $courseToolInformation;
  5850. }
  5851. return array(
  5852. 'array' => $csvContent,
  5853. 'html' => $courseToolInformationTotal
  5854. );
  5855. }
  5856. }