wiki.inc.php 273 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Editor\Connector;
  4. use Chamilo\CoreBundle\Component\Filesystem\Data;
  5. use ChamiloSession as Session;
  6. use MediaAlchemyst\Alchemyst;
  7. use MediaAlchemyst\DriversContainer;
  8. use Neutron\TemporaryFilesystem\Manager;
  9. use Neutron\TemporaryFilesystem\TemporaryFilesystem;
  10. use Symfony\Component\Filesystem\Filesystem;
  11. /**
  12. * Class Wiki
  13. * Functions library for the wiki tool
  14. * @author Juan Carlos Raña <herodoto@telefonica.net>
  15. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  16. * @author Julio Montoya <gugli100@gmail.com> using the pdf.lib.php library
  17. *
  18. * @package chamilo.wiki
  19. */
  20. class Wiki
  21. {
  22. public $tbl_wiki;
  23. public $tbl_wiki_discuss;
  24. public $tbl_wiki_mailcue;
  25. public $tbl_wiki_conf;
  26. public $session_id = null;
  27. public $course_id = null;
  28. public $condition_session = null;
  29. public $group_id;
  30. public $assig_user_id;
  31. public $groupfilter = 'group_id=0';
  32. public $courseInfo;
  33. public $charset;
  34. public $page;
  35. public $action;
  36. public $wikiData = [];
  37. public $url;
  38. /**
  39. * Constructor
  40. */
  41. public function __construct()
  42. {
  43. // Database table definition
  44. $this->tbl_wiki = Database::get_course_table(TABLE_WIKI);
  45. $this->tbl_wiki_discuss = Database::get_course_table(
  46. TABLE_WIKI_DISCUSS
  47. );
  48. $this->tbl_wiki_mailcue = Database::get_course_table(
  49. TABLE_WIKI_MAILCUE
  50. );
  51. $this->tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
  52. $this->session_id = api_get_session_id();
  53. $this->condition_session = api_get_session_condition($this->session_id);
  54. $this->course_id = api_get_course_int_id();
  55. $this->group_id = api_get_group_id();
  56. if (!empty($this->group_id)) {
  57. $this->groupfilter = ' group_id="'.$this->group_id.'"';
  58. }
  59. $this->courseInfo = api_get_course_info();
  60. $this->url = api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq();
  61. }
  62. /**
  63. * Check whether this title is already used
  64. * @param string $link
  65. *
  66. *
  67. * @return bool False if title is already taken
  68. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  69. **/
  70. public function checktitle($link)
  71. {
  72. $tbl_wiki = $this->tbl_wiki;
  73. $condition_session = $this->condition_session;
  74. $course_id = $this->course_id;
  75. $groupfilter = $this->groupfilter;
  76. $sql = 'SELECT * FROM '.$tbl_wiki.'
  77. WHERE
  78. c_id = '.$course_id.' AND
  79. reflink="'.Database::escape_string($link).'" AND
  80. '.$groupfilter.$condition_session.'';
  81. $result = Database::query($sql);
  82. $num = Database::num_rows($result);
  83. // the value has not been found and is this available
  84. if ($num == 0) {
  85. return true;
  86. } else {
  87. // the value has been found
  88. return false;
  89. }
  90. }
  91. /**
  92. * check wikilinks that has a page
  93. * @author Juan Carlos Raña <herodoto@telefonica.net>
  94. * @param string $input
  95. *
  96. * @return string
  97. **/
  98. public function links_to($input)
  99. {
  100. $input_array = preg_split(
  101. "/(\[\[|\]\])/",
  102. $input,
  103. -1,
  104. PREG_SPLIT_DELIM_CAPTURE
  105. );
  106. $all_links = [];
  107. foreach ($input_array as $key => $value) {
  108. if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' &&
  109. isset($input_array[$key + 1]) && $input_array[$key + 1] == ']]'
  110. ) {
  111. if (api_strpos($value, "|") !== false) {
  112. $full_link_array = explode("|", $value);
  113. $link = trim($full_link_array[0]);
  114. $title = trim($full_link_array[1]);
  115. } else {
  116. $link = trim($value);
  117. $title = trim($value);
  118. }
  119. unset($input_array[$key - 1]);
  120. unset($input_array[$key + 1]);
  121. //replace blank spaces by _ within the links. But to remove links at the end add a blank space
  122. $all_links[] = Database::escape_string(
  123. str_replace(' ', '_', $link)
  124. ).' ';
  125. }
  126. }
  127. $output = implode($all_links);
  128. return $output;
  129. }
  130. /**
  131. * detect and add style to external links
  132. * @author Juan Carlos Raña Trabado
  133. **/
  134. public function detect_external_link($input)
  135. {
  136. $exlink = 'href=';
  137. $exlinkStyle = 'class="wiki_link_ext" href=';
  138. $output = str_replace($exlink, $exlinkStyle, $input);
  139. return $output;
  140. }
  141. /**
  142. * detect and add style to anchor links
  143. * @author Juan Carlos Raña Trabado
  144. **/
  145. public function detect_anchor_link($input)
  146. {
  147. $anchorlink = 'href="#';
  148. $anchorlinkStyle = 'class="wiki_anchor_link" href="#';
  149. $output = str_replace($anchorlink, $anchorlinkStyle, $input);
  150. return $output;
  151. }
  152. /**
  153. * detect and add style to mail links
  154. * author Juan Carlos Raña Trabado
  155. **/
  156. public function detect_mail_link($input)
  157. {
  158. $maillink = 'href="mailto';
  159. $maillinkStyle = 'class="wiki_mail_link" href="mailto';
  160. $output = str_replace($maillink, $maillinkStyle, $input);
  161. return $output;
  162. }
  163. /**
  164. * detect and add style to ftp links
  165. * @author Juan Carlos Raña Trabado
  166. **/
  167. public function detect_ftp_link($input)
  168. {
  169. $ftplink = 'href="ftp';
  170. $ftplinkStyle = 'class="wiki_ftp_link" href="ftp';
  171. $output = str_replace($ftplink, $ftplinkStyle, $input);
  172. return $output;
  173. }
  174. /**
  175. * detect and add style to news links
  176. * @author Juan Carlos Raña Trabado
  177. **/
  178. public function detect_news_link($input)
  179. {
  180. $newslink = 'href="news';
  181. $newslinkStyle = 'class="wiki_news_link" href="news';
  182. $output = str_replace($newslink, $newslinkStyle, $input);
  183. return $output;
  184. }
  185. /**
  186. * detect and add style to irc links
  187. * @author Juan Carlos Raña Trabado
  188. **/
  189. public function detect_irc_link($input)
  190. {
  191. $irclink = 'href="irc';
  192. $irclinkStyle = 'class="wiki_irc_link" href="irc';
  193. $output = str_replace($irclink, $irclinkStyle, $input);
  194. return $output;
  195. }
  196. /**
  197. * This function allows users to have [link to a title]-style links like in most regular wikis.
  198. * It is true that the adding of links is probably the most anoying part of Wiki for the people
  199. * who know something about the wiki syntax.
  200. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  201. * Improvements [[]] and [[ | ]]by Juan Carlos Raña
  202. * Improvements internal wiki style and mark group by Juan Carlos Raña
  203. **/
  204. public function make_wiki_link_clickable($input)
  205. {
  206. $groupId = api_get_group_id();
  207. //now doubles brackets
  208. $input_array = preg_split(
  209. "/(\[\[|\]\])/",
  210. $input,
  211. -1,
  212. PREG_SPLIT_DELIM_CAPTURE
  213. );
  214. foreach ($input_array as $key => $value) {
  215. //now doubles brackets
  216. if (isset($input_array[$key - 1]) &&
  217. $input_array[$key - 1] == '[[' && $input_array[$key + 1] == ']]'
  218. ) {
  219. // now full wikilink
  220. if (api_strpos($value, "|") !== false) {
  221. $full_link_array = explode("|", $value);
  222. $link = trim(strip_tags($full_link_array[0]));
  223. $title = trim($full_link_array[1]);
  224. } else {
  225. $link = trim(strip_tags($value));
  226. $title = trim($value);
  227. }
  228. //if wikilink is homepage
  229. if ($link == 'index') {
  230. $title = get_lang('DefaultTitle');
  231. }
  232. if ($link == get_lang('DefaultTitle')) {
  233. $link = 'index';
  234. }
  235. // note: checkreflink checks if the link is still free. If it is not used then it returns true, if it is used, then it returns false. Now the title may be different
  236. if (self::checktitle(
  237. strtolower(str_replace(' ', '_', $link))
  238. )) {
  239. $link = api_html_entity_decode($link);
  240. $input_array[$key] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=addnew&title='.Security::remove_XSS($link).'&group_id='.$groupId.'" class="new_wiki_link">'.$title.'</a>';
  241. } else {
  242. $input_array[$key] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=showpage&title='.urlencode(strtolower(str_replace(' ', '_', $link))).'&group_id='.$groupId.'" class="wiki_link">'.$title.'</a>';
  243. }
  244. unset($input_array[$key - 1]);
  245. unset($input_array[$key + 1]);
  246. }
  247. }
  248. $output = implode('', $input_array);
  249. return $output;
  250. }
  251. /**
  252. * This function saves a change in a wiki page
  253. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  254. * @param array $values
  255. * @return language string saying that the changes are stored
  256. **/
  257. public function save_wiki($values)
  258. {
  259. $tbl_wiki = $this->tbl_wiki;
  260. $tbl_wiki_conf = $this->tbl_wiki_conf;
  261. $_course = $this->courseInfo;
  262. $time = api_get_utc_datetime();
  263. $session_id = api_get_session_id();
  264. $groupId = api_get_group_id();
  265. $userId = api_get_user_id();
  266. $groupInfo = GroupManager::get_group_properties($groupId);
  267. $course_id = api_get_course_int_id();
  268. $_clean = [
  269. 'task' => '',
  270. 'feedback1' => '',
  271. 'feedback2' => '',
  272. 'feedback3' => '',
  273. 'fprogress1' => '',
  274. 'fprogress2' => '',
  275. 'fprogress3' => '',
  276. 'max_text' => 0,
  277. 'max_version' => 0,
  278. 'delayedsubmit' => '',
  279. 'assignment' => 0
  280. ];
  281. $pageId = intval($values['page_id']);
  282. // NOTE: visibility, visibility_disc and ratinglock_disc changes
  283. // are not made here, but through the interce buttons
  284. // cleaning the variables
  285. if (api_get_setting('htmlpurifier_wiki') == 'true') {
  286. //$purifier = new HTMLPurifier();
  287. $values['content'] = Security::remove_XSS($values['content']);
  288. }
  289. $version = intval($values['version']) + 1;
  290. $linkTo = self::links_to($values['content']); //and check links content
  291. //cleaning config variables
  292. if (!empty($values['task'])) {
  293. $_clean['task'] = $values['task'];
  294. }
  295. if (!empty($values['feedback1']) ||
  296. !empty($values['feedback2']) ||
  297. !empty($values['feedback3'])
  298. ) {
  299. $_clean['feedback1'] = $values['feedback1'];
  300. $_clean['feedback2'] = $values['feedback2'];
  301. $_clean['feedback3'] = $values['feedback3'];
  302. $_clean['fprogress1'] = $values['fprogress1'];
  303. $_clean['fprogress2'] = $values['fprogress2'];
  304. $_clean['fprogress3'] = $values['fprogress3'];
  305. }
  306. if (isset($values['initstartdate']) && $values['initstartdate'] == 1) {
  307. $_clean['startdate_assig'] = $values['startdate_assig'];
  308. } else {
  309. $_clean['startdate_assig'] = null;
  310. }
  311. if (isset($values['initenddate']) && $values['initenddate'] == 1) {
  312. $_clean['enddate_assig'] = $values['enddate_assig'];
  313. } else {
  314. $_clean['enddate_assig'] = null;
  315. }
  316. if (isset($values['delayedsubmit'])) {
  317. $_clean['delayedsubmit'] = $values['delayedsubmit'];
  318. }
  319. if (!empty($values['max_text']) || !empty($values['max_version'])) {
  320. $_clean['max_text'] = $values['max_text'];
  321. $_clean['max_version'] = $values['max_version'];
  322. }
  323. $values['assignment'] = isset($values['assignment']) ? $values['assignment'] : 0;
  324. $values['page_id'] = isset($values['page_id']) ? $values['page_id'] : 0;
  325. $params = [
  326. 'c_id' => $course_id,
  327. 'addlock' => 1,
  328. 'visibility' => 1,
  329. 'visibility_disc' => 1,
  330. 'addlock_disc' => 1,
  331. 'ratinglock_disc' => 1,
  332. 'page_id' => $pageId,
  333. 'reflink' => trim($values['reflink']),
  334. 'title' => trim($values['title']),
  335. 'content' => $values['content'],
  336. 'user_id' => $userId,
  337. 'group_id' => $groupId,
  338. 'dtime' => $time,
  339. 'assignment' => $values['assignment'],
  340. 'comment' => $values['comment'],
  341. 'progress' => $values['progress'],
  342. 'version' => $version,
  343. 'linksto' => $linkTo,
  344. 'user_ip' => $_SERVER['REMOTE_ADDR'],
  345. 'session_id' => $session_id,
  346. 'page_id' => $values['page_id'],
  347. 'editlock' => 0,
  348. 'is_editing' => 0,
  349. 'time_edit' => $time,
  350. 'tag' => ''
  351. ];
  352. $id = Database::insert($tbl_wiki, $params);
  353. if ($id > 0) {
  354. $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
  355. Database::query($sql);
  356. // insert into item_property
  357. api_item_property_update(
  358. $_course,
  359. TOOL_WIKI,
  360. $id,
  361. 'WikiAdded',
  362. $userId,
  363. $groupInfo
  364. );
  365. if ($values['page_id'] == 0) {
  366. $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
  367. WHERE c_id = '.$course_id.' AND iid ="'.$id.'"';
  368. Database::query($sql);
  369. }
  370. }
  371. // Update wiki config
  372. if ($values['reflink'] == 'index' && $version == 1) {
  373. $params = [
  374. 'c_id' => $course_id,
  375. 'page_id' => $id,
  376. 'task' => $_clean['task'],
  377. 'feedback1' => $_clean['feedback1'],
  378. 'feedback2' => $_clean['feedback2'],
  379. 'feedback3' => $_clean['feedback3'],
  380. 'fprogress1' => $_clean['fprogress1'],
  381. 'fprogress2' => $_clean['fprogress2'],
  382. 'fprogress3' => $_clean['fprogress3'],
  383. 'max_text' => intval($_clean['max_text']),
  384. 'max_version' => intval($_clean['max_version']),
  385. 'startdate_assig' => $_clean['startdate_assig'],
  386. 'enddate_assig' => $_clean['enddate_assig'],
  387. 'delayedsubmit' => $_clean['delayedsubmit']
  388. ];
  389. Database::insert($tbl_wiki_conf, $params);
  390. } else {
  391. $params = [
  392. 'task' => $_clean['task'],
  393. 'feedback1' => $_clean['feedback1'],
  394. 'feedback2' => $_clean['feedback2'],
  395. 'feedback3' => $_clean['feedback3'],
  396. 'fprogress1' => $_clean['fprogress1'],
  397. 'fprogress2' => $_clean['fprogress2'],
  398. 'fprogress3' => $_clean['fprogress3'],
  399. 'max_text' => intval($_clean['max_text']),
  400. 'max_version' => intval($_clean['max_version']),
  401. 'startdate_assig' => $_clean['startdate_assig'],
  402. 'enddate_assig' => $_clean['enddate_assig'],
  403. 'delayedsubmit' => $_clean['delayedsubmit']
  404. ];
  405. Database::update(
  406. $tbl_wiki_conf,
  407. $params,
  408. ['page_id = ? AND c_id = ?' => [$pageId, $course_id]]
  409. );
  410. }
  411. api_item_property_update(
  412. $_course,
  413. 'wiki',
  414. $id,
  415. 'WikiAdded',
  416. $userId,
  417. $groupInfo
  418. );
  419. self::check_emailcue($_clean['reflink'], 'P', $time, $userId);
  420. $this->setWikiData($id);
  421. return get_lang('Saved');
  422. }
  423. /**
  424. * This function restore a wikipage
  425. * @author Juan Carlos Raña <herodoto@telefonica.net>
  426. * @return string Message of success (to be printed on screen)
  427. **/
  428. public function restore_wikipage(
  429. $r_page_id,
  430. $r_reflink,
  431. $r_title,
  432. $r_content,
  433. $r_group_id,
  434. $r_assignment,
  435. $r_progress,
  436. $c_version,
  437. $r_version,
  438. $r_linksto
  439. ) {
  440. $tbl_wiki = $this->tbl_wiki;
  441. $_course = $this->courseInfo;
  442. $r_user_id = api_get_user_id();
  443. $r_dtime = api_get_utc_datetime();
  444. $r_version = $r_version + 1;
  445. $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
  446. $session_id = api_get_session_id();
  447. $course_id = api_get_course_int_id();
  448. $groupInfo = GroupManager::get_group_properties($r_group_id);
  449. $params = [
  450. 'c_id' => $course_id,
  451. 'page_id' => $r_page_id,
  452. 'reflink' => $r_reflink,
  453. 'title' => $r_title,
  454. 'content' => $r_content,
  455. 'user_id' => $r_user_id,
  456. 'group_id' => $r_group_id,
  457. 'dtime' => $r_dtime,
  458. 'assignment' => $r_assignment,
  459. 'comment' => $r_comment,
  460. 'progress' => $r_progress,
  461. 'version' => $r_version,
  462. 'linksto' => $r_linksto,
  463. 'user_ip' => $_SERVER['REMOTE_ADDR'],
  464. 'session_id' => $session_id,
  465. ];
  466. $id = Database::insert($tbl_wiki, $params);
  467. if ($id) {
  468. $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
  469. Database::query($sql);
  470. api_item_property_update(
  471. $_course,
  472. 'wiki',
  473. $id,
  474. 'WikiAdded',
  475. api_get_user_id(),
  476. $groupInfo
  477. );
  478. self::check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id);
  479. }
  480. return get_lang('PageRestored');
  481. }
  482. /**
  483. * This function delete a wiki
  484. * @author Juan Carlos Raña <herodoto@telefonica.net>
  485. * @return string Message of success (to be printed)
  486. **/
  487. public function delete_wiki()
  488. {
  489. $tbl_wiki = $this->tbl_wiki;
  490. $tbl_wiki_discuss = $this->tbl_wiki_discuss;
  491. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  492. $tbl_wiki_conf = $this->tbl_wiki_conf;
  493. $conditionSession = $this->condition_session;
  494. $groupFilter = $this->groupfilter;
  495. $course_id = $this->course_id;
  496. $sql = "SELECT page_id FROM $tbl_wiki
  497. WHERE c_id = $course_id AND $groupFilter $conditionSession
  498. ORDER BY id DESC";
  499. $result = Database::query($sql);
  500. $pageList = Database::store_result($result);
  501. if ($pageList) {
  502. foreach ($pageList as $pageData) {
  503. $pageId = $pageData['page_id'];
  504. $sql = "DELETE FROM $tbl_wiki_conf
  505. WHERE c_id = $course_id AND page_id = $pageId";
  506. Database::query($sql);
  507. $sql = "DELETE FROM $tbl_wiki_discuss
  508. WHERE c_id = $course_id AND publication_id = $pageId";
  509. Database::query($sql);
  510. }
  511. }
  512. $sql = "DELETE FROM $tbl_wiki_mailcue
  513. WHERE c_id = $course_id AND $groupFilter $conditionSession ";
  514. Database::query($sql);
  515. $sql = "DELETE FROM $tbl_wiki
  516. WHERE c_id = $course_id AND $groupFilter $conditionSession ";
  517. Database::query($sql);
  518. return get_lang('WikiDeleted');
  519. }
  520. /**
  521. * This function saves a new wiki page.
  522. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  523. * @todo consider merging this with the function save_wiki into one single function.
  524. * @return string Message of success
  525. **/
  526. public function save_new_wiki($values)
  527. {
  528. $tbl_wiki = $this->tbl_wiki;
  529. $tbl_wiki_conf = $this->tbl_wiki_conf;
  530. $assig_user_id = $this->assig_user_id;
  531. $_clean = [];
  532. // cleaning the variables
  533. $_clean['assignment'] = '';
  534. if (isset($values['assignment'])) {
  535. $_clean['assignment'] = $values['assignment'];
  536. }
  537. // session_id
  538. $session_id = api_get_session_id();
  539. // Unlike ordinary pages of pages of assignments.
  540. // Allow create a ordinary page although there is a assignment with the same name
  541. if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) {
  542. $page = str_replace(
  543. ' ',
  544. '_',
  545. $values['title']."_uass".$assig_user_id
  546. );
  547. } else {
  548. $page = str_replace(' ', '_', $values['title']);
  549. }
  550. $_clean['reflink'] = $page;
  551. $_clean['title'] = trim($values['title']);
  552. $_clean['content'] = $values['content'];
  553. if (api_get_setting('htmlpurifier_wiki') === 'true') {
  554. $purifier = new HTMLPurifier();
  555. $_clean['content'] = $purifier->purify($_clean['content']);
  556. }
  557. //re-check after strip_tags if the title is empty
  558. if (empty($_clean['title']) || empty($_clean['reflink'])) {
  559. return false;
  560. }
  561. if ($_clean['assignment'] == 2) {
  562. //config by default for individual assignment (students)
  563. //Identifies the user as a creator, not the teacher who created
  564. $_clean['user_id'] = intval($assig_user_id);
  565. $_clean['visibility'] = 0;
  566. $_clean['visibility_disc'] = 0;
  567. $_clean['ratinglock_disc'] = 0;
  568. } else {
  569. $_clean['user_id'] = api_get_user_id();
  570. $_clean['visibility'] = 1;
  571. $_clean['visibility_disc'] = 1;
  572. $_clean['ratinglock_disc'] = 1;
  573. }
  574. $_clean['comment'] = $values['comment'];
  575. $_clean['progress'] = $values['progress'];
  576. $_clean['version'] = 1;
  577. $groupId = api_get_group_id();
  578. $groupInfo = GroupManager::get_group_properties($groupId);
  579. //check wikilinks
  580. $_clean['linksto'] = self::links_to($_clean['content']);
  581. // cleaning config variables
  582. $_clean['task'] = isset($values['task']) ? $values['task'] : '';
  583. $_clean['feedback1'] = isset($values['feedback1']) ? $values['feedback1'] : '';
  584. $_clean['feedback2'] = isset($values['feedback2']) ? $values['feedback2'] : '';
  585. $_clean['feedback3'] = isset($values['feedback3']) ? $values['feedback3'] : '';
  586. $_clean['fprogress1'] = isset($values['fprogress1']) ? $values['fprogress1'] : '';
  587. $_clean['fprogress2'] = isset($values['fprogress2']) ? $values['fprogress2'] : '';
  588. $_clean['fprogress3'] = isset($values['fprogress3']) ? $values['fprogress3'] : '';
  589. if (isset($values['initstartdate']) && $values['initstartdate'] == 1) {
  590. $_clean['startdate_assig'] = $values['startdate_assig'];
  591. } else {
  592. $_clean['startdate_assig'] = null;
  593. }
  594. if (isset($values['initenddate']) && $values['initenddate'] == 1) {
  595. $_clean['enddate_assig'] = $values['enddate_assig'];
  596. } else {
  597. $_clean['enddate_assig'] = null;
  598. }
  599. $_clean['delayedsubmit'] = isset($values['delayedsubmit']) ? $values['delayedsubmit'] : '';
  600. $_clean['max_text'] = isset($values['max_text']) ? $values['max_text'] : '';
  601. $_clean['max_version'] = isset($values['max_version']) ? $values['max_version'] : '';
  602. $course_id = api_get_course_int_id();
  603. // Filter no _uass
  604. if (api_strtoupper(trim($values['title'])) === 'INDEX') {
  605. Display::addFlash(
  606. Display::return_message(
  607. get_lang('GoAndEditMainPage'),
  608. 'warning',
  609. false
  610. )
  611. );
  612. } else {
  613. $var = $_clean['reflink'];
  614. $group_id = intval($_GET['group_id']);
  615. if (!self::checktitle($var)) {
  616. return get_lang('WikiPageTitleExist').
  617. '<a href="index.php?action=edit&title='.$var.'&group_id='.$group_id.'">'.
  618. $values['title'].'</a>';
  619. } else {
  620. $dtime = api_get_utc_datetime();
  621. $params = [
  622. 'c_id' => $course_id,
  623. 'reflink' => $_clean['reflink'],
  624. 'title' => $_clean['title'],
  625. 'content' => $_clean['content'],
  626. 'user_id' => $_clean['user_id'],
  627. 'group_id' => $groupId,
  628. 'dtime' => $dtime,
  629. 'visibility' => $_clean['visibility'],
  630. 'visibility_disc' => $_clean['visibility_disc'],
  631. 'ratinglock_disc' => $_clean['ratinglock_disc'],
  632. 'assignment' => $_clean['assignment'],
  633. 'comment' => $_clean['comment'],
  634. 'progress' => $_clean['progress'],
  635. 'version' => $_clean['version'],
  636. 'linksto' => $_clean['linksto'],
  637. 'user_ip' => $_SERVER['REMOTE_ADDR'],
  638. 'session_id' => $session_id,
  639. 'addlock_disc' => 1
  640. ];
  641. $id = Database::insert($tbl_wiki, $params);
  642. if ($id > 0) {
  643. $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
  644. Database::query($sql);
  645. //insert into item_property
  646. api_item_property_update(
  647. api_get_course_info(),
  648. TOOL_WIKI,
  649. $id,
  650. 'WikiAdded',
  651. api_get_user_id(),
  652. $groupInfo
  653. );
  654. $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
  655. WHERE c_id = '.$course_id.' AND id = "'.$id.'"';
  656. Database::query($sql);
  657. // insert wiki config
  658. $params = [
  659. 'c_id' => $course_id,
  660. 'page_id' => $id,
  661. 'task' => $_clean['task'],
  662. 'feedback1' => $_clean['feedback1'],
  663. 'feedback2' => $_clean['feedback2'],
  664. 'feedback3' => $_clean['feedback3'],
  665. 'fprogress1' => $_clean['fprogress1'],
  666. 'fprogress2' => $_clean['fprogress2'],
  667. 'fprogress3' => $_clean['fprogress3'],
  668. 'max_text' => $_clean['max_text'],
  669. 'max_version' => $_clean['max_version'],
  670. 'startdate_assig' => $_clean['startdate_assig'],
  671. 'enddate_assig' => $_clean['enddate_assig'],
  672. 'delayedsubmit' => $_clean['delayedsubmit']
  673. ];
  674. Database::insert($tbl_wiki_conf, $params);
  675. $this->setWikiData($id);
  676. self::check_emailcue(0, 'A');
  677. return get_lang('NewWikiSaved');
  678. }
  679. }
  680. }
  681. }
  682. /**
  683. * @param FormValidator $form
  684. * @param array $row
  685. */
  686. public function setForm($form, $row = [])
  687. {
  688. $toolBar = api_is_allowed_to_edit(null, true)
  689. ? [
  690. 'ToolbarSet' => 'Wiki',
  691. 'Width' => '100%',
  692. 'Height' => '400'
  693. ]
  694. : [
  695. 'ToolbarSet' => 'WikiStudent',
  696. 'Width' => '100%',
  697. 'Height' => '400',
  698. 'UserStatus' => 'student'
  699. ];
  700. $form->addHtmlEditor(
  701. 'content',
  702. get_lang('Content'),
  703. false,
  704. false,
  705. $toolBar
  706. );
  707. //$content
  708. $form->addElement('text', 'comment', get_lang('Comments'));
  709. $progress = ['', 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
  710. $form->addElement(
  711. 'select',
  712. 'progress',
  713. get_lang('Progress'),
  714. $progress
  715. );
  716. if ((api_is_allowed_to_edit(false, true) ||
  717. api_is_platform_admin()) &&
  718. isset($row['reflink']) && $row['reflink'] != 'index'
  719. ) {
  720. $form->addElement(
  721. 'advanced_settings',
  722. 'advanced_params',
  723. get_lang('AdvancedParameters')
  724. );
  725. $form->addElement(
  726. 'html',
  727. '<div id="advanced_params_options" style="display:none">'
  728. );
  729. $form->addHtmlEditor(
  730. 'task',
  731. get_lang('DescriptionOfTheTask'),
  732. false,
  733. false,
  734. [
  735. 'ToolbarSet' => 'wiki_task',
  736. 'Width' => '100%',
  737. 'Height' => '200',
  738. ]
  739. );
  740. $form->addElement('label', null, get_lang('AddFeedback'));
  741. $form->addElement('textarea', 'feedback1', get_lang('Feedback1'));
  742. $form->addElement(
  743. 'select',
  744. 'fprogress1',
  745. get_lang('FProgress'),
  746. $progress
  747. );
  748. $form->addElement('textarea', 'feedback2', get_lang('Feedback2'));
  749. $form->addElement(
  750. 'select',
  751. 'fprogress2',
  752. get_lang('FProgress'),
  753. $progress
  754. );
  755. $form->addElement('textarea', 'feedback3', get_lang('Feedback3'));
  756. $form->addElement(
  757. 'select',
  758. 'fprogress3',
  759. get_lang('FProgress'),
  760. $progress
  761. );
  762. $form->addElement(
  763. 'checkbox',
  764. 'initstartdate',
  765. null,
  766. get_lang('StartDate'),
  767. ['id' => 'start_date_toggle']
  768. );
  769. $style = "display:block";
  770. $row['initstartdate'] = 1;
  771. if (empty($row['startdate_assig'])) {
  772. $style = "display:none";
  773. $row['initstartdate'] = null;
  774. }
  775. $form->addElement(
  776. 'html',
  777. '<div id="start_date" style="'.$style.'">'
  778. );
  779. $form->addDatePicker('startdate_assig', '');
  780. $form->addElement('html', '</div>');
  781. $form->addElement(
  782. 'checkbox',
  783. 'initenddate',
  784. null,
  785. get_lang('EndDate'),
  786. ['id' => 'end_date_toggle']
  787. );
  788. $style = "display:block";
  789. $row['initenddate'] = 1;
  790. if (empty($row['enddate_assig'])) {
  791. $style = "display:none";
  792. $row['initenddate'] = null;
  793. }
  794. $form->addHtml('<div id="end_date" style="'.$style.'">');
  795. $form->addDatePicker('enddate_assig', '');
  796. $form->addHtml('</div>');
  797. $form->addElement(
  798. 'checkbox',
  799. 'delayedsubmit',
  800. null,
  801. get_lang('AllowLaterSends')
  802. );
  803. $form->addElement('text', 'max_text', get_lang('NMaxWords'));
  804. $form->addElement('text', 'max_version', get_lang('NMaxVersion'));
  805. $form->addElement(
  806. 'checkbox',
  807. 'assignment',
  808. null,
  809. get_lang('CreateAssignmentPage')
  810. );
  811. $form->addElement('html', '</div>');
  812. }
  813. $form->addElement('hidden', 'page_id');
  814. $form->addElement('hidden', 'reflink');
  815. $form->addElement('hidden', 'version');
  816. $form->addElement('hidden', 'wpost_id', api_get_unique_id());
  817. }
  818. /**
  819. * This function displays the form for adding a new wiki page.
  820. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  821. * @return string html code
  822. **/
  823. public function display_new_wiki_form()
  824. {
  825. $url = api_get_self().'?'.api_get_cidreq(
  826. ).'&action=addnew&group_id='.api_get_group_id();
  827. $form = new FormValidator('wiki_new', 'post', $url);
  828. $form->addElement('text', 'title', get_lang('Title'));
  829. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  830. self::setForm($form);
  831. $title = isset($_GET['title']) ? Security::remove_XSS(
  832. $_GET['title']
  833. ) : '';
  834. $form->setDefaults(['title' => $title]);
  835. $form->addElement('button', 'SaveWikiNew', get_lang('Save'));
  836. $form->display();
  837. if ($form->validate()) {
  838. $values = $form->exportValues();
  839. if (isset($values['startdate_assig']) &&
  840. isset($values['enddate_assig']) &&
  841. strtotime($values['startdate_assig']) > strtotime(
  842. $values['enddate_assig']
  843. )
  844. ) {
  845. Display::addFlash(
  846. Display::return_message(
  847. get_lang("EndDateCannotBeBeforeTheStartDate"),
  848. 'error',
  849. false
  850. )
  851. );
  852. } elseif (!self::double_post($_POST['wpost_id'])) {
  853. //double post
  854. } else {
  855. if (isset($values['assignment']) && $values['assignment'] == 1) {
  856. self::auto_add_page_users($values);
  857. }
  858. $return_message = self::save_new_wiki($values);
  859. if ($return_message == false) {
  860. Display::addFlash(
  861. Display::return_message(
  862. get_lang('NoWikiPageTitle'),
  863. 'error',
  864. false
  865. )
  866. );
  867. } else {
  868. Display::addFlash(
  869. Display::return_message(
  870. $return_message,
  871. 'confirmation',
  872. false
  873. )
  874. );
  875. }
  876. $wikiData = self::getWikiData();
  877. $redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq();
  878. header('Location: '.$redirectUrl);
  879. exit;
  880. }
  881. }
  882. }
  883. /**
  884. * This function displays a wiki entry
  885. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  886. * @author Juan Carlos Raña Trabado
  887. * @param string $newtitle
  888. * @return string html code
  889. **/
  890. public function display_wiki_entry($newtitle)
  891. {
  892. $tbl_wiki = $this->tbl_wiki;
  893. $tbl_wiki_conf = $this->tbl_wiki_conf;
  894. $condition_session = $this->condition_session;
  895. $groupfilter = $this->groupfilter;
  896. $page = $this->page;
  897. $session_id = api_get_session_id();
  898. $course_id = api_get_course_int_id();
  899. if ($newtitle) {
  900. $pageMIX = $newtitle; //display the page after it is created
  901. } else {
  902. $pageMIX = $page; //display current page
  903. }
  904. $filter = null;
  905. if (isset($_GET['view']) && $_GET['view']) {
  906. $_clean['view'] = Database::escape_string($_GET['view']);
  907. $filter = ' AND w.id="'.$_clean['view'].'"';
  908. }
  909. // First, check page visibility in the first page version
  910. $sql = 'SELECT * FROM '.$tbl_wiki.'
  911. WHERE
  912. c_id = '.$course_id.' AND
  913. reflink="'.Database::escape_string($pageMIX).'" AND
  914. '.$groupfilter.$condition_session.'
  915. ORDER BY id ASC';
  916. $result = Database::query($sql);
  917. $row = Database::fetch_array($result, 'ASSOC');
  918. $KeyVisibility = $row['visibility'];
  919. // second, show the last version
  920. $sql = 'SELECT * FROM '.$tbl_wiki.' w
  921. INNER JOIN '.$tbl_wiki_conf.' wc
  922. ON (wc.page_id = w.page_id AND wc.c_id = w.c_id)
  923. WHERE
  924. w.c_id = '.$course_id.' AND
  925. w.reflink = "'.Database::escape_string($pageMIX).'" AND
  926. w.session_id = '.$session_id.' AND
  927. w.'.$groupfilter.' '.$filter.'
  928. ORDER BY id DESC';
  929. $result = Database::query($sql);
  930. // we do not need a while loop since we are always displaying the last version
  931. $row = Database::fetch_array($result, 'ASSOC');
  932. //log users access to wiki (page_id)
  933. if (!empty($row['page_id'])) {
  934. Event::addEvent(LOG_WIKI_ACCESS, LOG_WIKI_PAGE_ID, $row['page_id']);
  935. }
  936. //update visits
  937. if ($row['id']) {
  938. $sql = 'UPDATE '.$tbl_wiki.' SET hits=(hits+1)
  939. WHERE c_id = '.$course_id.' AND id='.$row['id'].'';
  940. Database::query($sql);
  941. }
  942. $groupInfo = GroupManager::get_group_properties(api_get_group_id());
  943. // if both are empty and we are displaying the index page then we display the default text.
  944. if ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
  945. if (api_is_allowed_to_edit(false, true) ||
  946. api_is_platform_admin() ||
  947. GroupManager::is_user_in_group(api_get_user_id(), $groupInfo) ||
  948. api_is_allowed_in_course()
  949. ) {
  950. //Table structure for better export to pdf
  951. $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
  952. $default_table_for_content_End = '</td></tr></table>';
  953. $content = $default_table_for_content_Start.
  954. sprintf(
  955. get_lang('DefaultContent'),
  956. api_get_path(WEB_IMG_PATH)
  957. ).
  958. $default_table_for_content_End;
  959. $title = get_lang('DefaultTitle');
  960. } else {
  961. return Display::addFlash(
  962. Display::return_message(
  963. get_lang('WikiStandBy'),
  964. 'normal',
  965. false
  966. )
  967. );
  968. }
  969. } else {
  970. $content = Security::remove_XSS($row['content']);
  971. $title = Security::remove_XSS($row['title']);
  972. }
  973. //assignment mode: identify page type
  974. $icon_assignment = null;
  975. if ($row['assignment'] == 1) {
  976. $icon_assignment = Display::return_icon(
  977. 'wiki_assignment.png',
  978. get_lang('AssignmentDescExtra'),
  979. '',
  980. ICON_SIZE_SMALL
  981. );
  982. } elseif ($row['assignment'] == 2) {
  983. $icon_assignment = Display::return_icon(
  984. 'wiki_work.png',
  985. get_lang('AssignmentWork'),
  986. '',
  987. ICON_SIZE_SMALL
  988. );
  989. }
  990. // task mode
  991. $icon_task = null;
  992. if (!empty($row['task'])) {
  993. $icon_task = Display::return_icon(
  994. 'wiki_task.png',
  995. get_lang('StandardTask'),
  996. '',
  997. ICON_SIZE_SMALL
  998. );
  999. }
  1000. // Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
  1001. if ($KeyVisibility == "1" ||
  1002. api_is_allowed_to_edit(false, true) ||
  1003. api_is_platform_admin() ||
  1004. ($row['assignment'] == 2 && $KeyVisibility == "0" && (api_get_user_id() == $row['user_id'])) ||
  1005. api_is_allowed_in_course()
  1006. ) {
  1007. $actionsLeft = '';
  1008. // menu edit page
  1009. $editLink = '<a href="index.php?'.api_get_cidreq().'&action=edit&title='.api_htmlentities(urlencode($page)).'"'.self::is_active_navigation_tab('edit').'>'.
  1010. Display::return_icon(
  1011. 'edit.png',
  1012. get_lang('EditThisPage'),
  1013. '',
  1014. ICON_SIZE_MEDIUM
  1015. ).'</a>';
  1016. if (api_is_allowed_to_edit(false, true)) {
  1017. $actionsLeft .= $editLink;
  1018. } else {
  1019. if ((api_is_allowed_in_course() ||
  1020. GroupManager::is_user_in_group(
  1021. api_get_user_id(),
  1022. $groupInfo
  1023. ))
  1024. ) {
  1025. $actionsLeft .= $editLink;
  1026. } else {
  1027. $actionsLeft .= '';
  1028. }
  1029. }
  1030. $actionsRight = '';
  1031. $protect_page = null;
  1032. $lock_unlock_protect = null;
  1033. // page action: protecting (locking) the page
  1034. if (api_is_allowed_to_edit(false, true) ||
  1035. api_is_platform_admin()
  1036. ) {
  1037. if (self::check_protect_page() == 1) {
  1038. $protect_page = Display::return_icon(
  1039. 'lock.png',
  1040. get_lang('PageLockedExtra'),
  1041. '',
  1042. ICON_SIZE_MEDIUM
  1043. );
  1044. $lock_unlock_protect = 'unlock';
  1045. } else {
  1046. $protect_page = Display::return_icon(
  1047. 'unlock.png',
  1048. get_lang('PageUnlockedExtra'),
  1049. '',
  1050. ICON_SIZE_MEDIUM
  1051. );
  1052. $lock_unlock_protect = 'lock';
  1053. }
  1054. }
  1055. if ($row['id']) {
  1056. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_protect.'&title='.api_htmlentities(urlencode($page)).'">'.
  1057. $protect_page.'</a>';
  1058. }
  1059. $visibility_page = null;
  1060. $lock_unlock_visibility = null;
  1061. //page action: visibility
  1062. if (api_is_allowed_to_edit(false, true) ||
  1063. api_is_platform_admin()
  1064. ) {
  1065. if (self::check_visibility_page() == 1) {
  1066. $visibility_page = Display::return_icon(
  1067. 'visible.png',
  1068. get_lang('ShowPageExtra'),
  1069. '',
  1070. ICON_SIZE_MEDIUM
  1071. );
  1072. $lock_unlock_visibility = 'invisible';
  1073. } else {
  1074. $visibility_page = Display::return_icon(
  1075. 'invisible.png',
  1076. get_lang('HidePageExtra'),
  1077. '',
  1078. ICON_SIZE_MEDIUM
  1079. );
  1080. $lock_unlock_visibility = 'visible';
  1081. }
  1082. }
  1083. if ($row['id']) {
  1084. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_visibility.'&title='.api_htmlentities(urlencode($page)).'">'.
  1085. $visibility_page.'</a>';
  1086. }
  1087. //page action: notification
  1088. if (api_is_allowed_to_session_edit()) {
  1089. if (self::check_notify_page($page) == 1) {
  1090. $notify_page = Display::return_icon(
  1091. 'messagebox_info.png',
  1092. get_lang('NotifyByEmail'),
  1093. '',
  1094. ICON_SIZE_MEDIUM
  1095. );
  1096. $lock_unlock_notify_page = 'unlocknotify';
  1097. } else {
  1098. $notify_page = Display::return_icon(
  1099. 'mail.png',
  1100. get_lang('CancelNotifyByEmail'),
  1101. '',
  1102. ICON_SIZE_MEDIUM
  1103. );
  1104. $lock_unlock_notify_page = 'locknotify';
  1105. }
  1106. }
  1107. // Only available if row['id'] is set
  1108. if ($row['id']) {
  1109. if (api_is_allowed_to_session_edit(false, true) &&
  1110. api_is_allowed_to_edit() ||
  1111. GroupManager::is_user_in_group(
  1112. api_get_user_id(),
  1113. $groupInfo
  1114. )
  1115. ) {
  1116. // menu discuss page
  1117. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=discuss&title='.api_htmlentities(
  1118. urlencode($page)
  1119. ).'" '.self::is_active_navigation_tab('discuss').'>'.
  1120. Display::return_icon(
  1121. 'discuss.png',
  1122. get_lang('DiscussThisPage'),
  1123. '',
  1124. ICON_SIZE_MEDIUM
  1125. ).'</a>';
  1126. }
  1127. //menu history
  1128. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=history&title='.api_htmlentities(
  1129. urlencode($page)
  1130. ).'" '.self::is_active_navigation_tab('history').'>'.
  1131. Display::return_icon(
  1132. 'history.png',
  1133. get_lang('ShowPageHistory'),
  1134. '',
  1135. ICON_SIZE_MEDIUM
  1136. ).'</a>';
  1137. //menu linkspages
  1138. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'action=links&title='.api_htmlentities(
  1139. urlencode($page)
  1140. ).'" '.self::is_active_navigation_tab('links').'>'.
  1141. Display::return_icon(
  1142. 'what_link_here.png',
  1143. get_lang('LinksPages'),
  1144. '',
  1145. ICON_SIZE_MEDIUM
  1146. ).'</a>';
  1147. //menu delete wikipage
  1148. if (api_is_allowed_to_edit(false, true) ||
  1149. api_is_platform_admin()
  1150. ) {
  1151. $actionsRight .= '<a href="index.php?action=delete&'.api_get_cidreq().'&title='.api_htmlentities(
  1152. urlencode($page)
  1153. ).'"'.self::is_active_navigation_tab('delete').'>'.
  1154. Display::return_icon(
  1155. 'delete.png',
  1156. get_lang('DeleteThisPage'),
  1157. '',
  1158. ICON_SIZE_MEDIUM
  1159. ).'</a>';
  1160. }
  1161. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_notify_page.'&title='.api_htmlentities(
  1162. urlencode($page)
  1163. ).'">'.
  1164. $notify_page.'</a>';
  1165. // Page action: copy last version to doc area
  1166. if (api_is_allowed_to_edit(false, true) ||
  1167. api_is_platform_admin()
  1168. ) {
  1169. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export2doc&wiki_id='.$row['id'].'">'.
  1170. Display::return_icon(
  1171. 'export_to_documents.png',
  1172. get_lang('ExportToDocArea'),
  1173. '',
  1174. ICON_SIZE_MEDIUM
  1175. ).'</a>';
  1176. }
  1177. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf&wiki_id='.$row['id'].'">'.
  1178. Display::return_icon(
  1179. 'pdf.png',
  1180. get_lang('ExportToPDF'),
  1181. '',
  1182. ICON_SIZE_MEDIUM
  1183. ).'</a>';
  1184. $unoconv = api_get_configuration_value('unoconv.binaries');
  1185. if ($unoconv) {
  1186. $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).'wiki/index.php?action=export_to_doc_file&id='.$row['id'].'&'.api_get_cidreq().'">'.
  1187. Display::return_icon(
  1188. 'export_doc.png',
  1189. get_lang('ExportToDoc'),
  1190. [],
  1191. ICON_SIZE_MEDIUM
  1192. ).'</a>';
  1193. }
  1194. //export to print?>
  1195. <script>
  1196. function goprint() {
  1197. var a = window.open('', '', 'width=800,height=600');
  1198. a.document.open("text/html");
  1199. a.document.write($('#wikicontent .panel-heading').html());
  1200. a.document.write($('#wikicontent .panel-body').html());
  1201. a.document.close();
  1202. a.print();
  1203. }
  1204. </script>
  1205. <?php
  1206. $actionsRight .= Display::url(
  1207. Display::return_icon(
  1208. 'printer.png',
  1209. get_lang('Print'),
  1210. '',
  1211. ICON_SIZE_MEDIUM
  1212. ),
  1213. '#',
  1214. ['onclick' => "javascript: goprint();"]
  1215. );
  1216. }
  1217. echo Display::toolbarAction(
  1218. 'toolbar-wikistudent',
  1219. [$actionsLeft, $actionsRight]
  1220. );
  1221. if (self::wiki_exist($title)) {
  1222. $pageTitle = $icon_assignment.'&nbsp;'.
  1223. $icon_task.'&nbsp;'.api_htmlentities($title);
  1224. } else {
  1225. $pageTitle = api_htmlentities($title);
  1226. }
  1227. $pageWiki = self::make_wiki_link_clickable(
  1228. self::detect_external_link(
  1229. self::detect_anchor_link(
  1230. self::detect_mail_link(
  1231. self::detect_ftp_link(
  1232. self::detect_irc_link(
  1233. self::detect_news_link($content)
  1234. )
  1235. )
  1236. )
  1237. )
  1238. )
  1239. );
  1240. $footerWiki =
  1241. get_lang('Progress').': '.($row['progress'] * 10).'%&nbsp;&nbsp;&nbsp;'.
  1242. get_lang('Rating').': '.$row['score'].'&nbsp;&nbsp;&nbsp;'.
  1243. get_lang('Words').': '.self::word_count($content);
  1244. // wikicontent require to print wiki document
  1245. echo '<div id="wikicontent">'.Display::panel($pageWiki, $pageTitle, $footerWiki).'</div>';
  1246. } //end filter visibility
  1247. }
  1248. /**
  1249. * This function counted the words in a document. Thanks Adeel Khan
  1250. * @param string Document's text
  1251. * @return int Number of words
  1252. */
  1253. public function word_count($document)
  1254. {
  1255. $search = [
  1256. '@<script[^>]*?>.*?</script>@si',
  1257. '@<style[^>]*?>.*?</style>@siU',
  1258. '@<div id="player.[^>]*?>.*?</div>@',
  1259. '@<![\s\S]*?--[ \t\n\r]*>@'
  1260. ];
  1261. $document = preg_replace($search, '', $document);
  1262. # strip all html tags
  1263. $wc = strip_tags($document);
  1264. $wc = html_entity_decode(
  1265. $wc,
  1266. ENT_NOQUOTES,
  1267. 'UTF-8'
  1268. ); // TODO:test also old html_entity_decode(utf8_encode($wc))
  1269. # remove 'words' that don't consist of alphanumerical characters or punctuation. And fix accents and some letters
  1270. $pattern = "#[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@|á|é|í|ó|ú|à|è|ì|ò|ù|ä|ë|ï|ö|ü|Á|É|Í|Ó|Ú|À|È|Ò|Ù|Ä|Ë|Ï|Ö|Ü|â|ê|î|ô|û|Â|Ê|Î|Ô|Û|ñ|Ñ|ç|Ç)]+#";
  1271. $wc = trim(preg_replace($pattern, " ", $wc));
  1272. # remove one-letter 'words' that consist only of punctuation
  1273. $wc = trim(
  1274. preg_replace(
  1275. "#\s*[(\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]\s*#",
  1276. " ",
  1277. $wc
  1278. )
  1279. );
  1280. # remove superfluous whitespace
  1281. $wc = preg_replace("/\s\s+/", " ", $wc);
  1282. # split string into an array of words
  1283. $wc = explode(" ", $wc);
  1284. # remove empty elements
  1285. $wc = array_filter($wc);
  1286. # return the number of words
  1287. return count($wc);
  1288. }
  1289. /**
  1290. * This function checks if wiki title exist
  1291. */
  1292. public function wiki_exist($title)
  1293. {
  1294. $tbl_wiki = $this->tbl_wiki;
  1295. $groupfilter = $this->groupfilter;
  1296. $condition_session = $this->condition_session;
  1297. $course_id = api_get_course_int_id();
  1298. $sql = 'SELECT id FROM '.$tbl_wiki.'
  1299. WHERE
  1300. c_id = '.$course_id.' AND
  1301. title="'.Database::escape_string($title).'" AND
  1302. '.$groupfilter.$condition_session.'
  1303. ORDER BY id ASC';
  1304. $result = Database::query($sql);
  1305. $cant = Database::num_rows($result);
  1306. if ($cant > 0) {
  1307. return true;
  1308. } else {
  1309. return false;
  1310. }
  1311. }
  1312. /**
  1313. * Checks if this navigation tab has to be set to active
  1314. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1315. *
  1316. * @return string html code
  1317. */
  1318. public function is_active_navigation_tab($paramwk)
  1319. {
  1320. if (isset($_GET['action']) && $_GET['action'] == $paramwk) {
  1321. return ' class="active"';
  1322. }
  1323. }
  1324. /**
  1325. * Lock add pages
  1326. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1327. * return current database status of protect page and change it if get action
  1328. */
  1329. public function check_addnewpagelock()
  1330. {
  1331. $tbl_wiki = $this->tbl_wiki;
  1332. $condition_session = $this->condition_session;
  1333. $groupfilter = $this->groupfilter;
  1334. $course_id = api_get_course_int_id();
  1335. $sql = 'SELECT *
  1336. FROM '.$tbl_wiki.'
  1337. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  1338. ORDER BY id ASC';
  1339. $result = Database::query($sql);
  1340. $row = Database::fetch_array($result);
  1341. $status_addlock = $row['addlock'];
  1342. // Change status
  1343. if (api_is_allowed_to_edit(false, true) ||
  1344. api_is_platform_admin()
  1345. ) {
  1346. if (isset($_GET['actionpage'])) {
  1347. if ($_GET['actionpage'] == 'lockaddnew' && $status_addlock == 1) {
  1348. $status_addlock = 0;
  1349. }
  1350. if ($_GET['actionpage'] == 'unlockaddnew' && $status_addlock == 0) {
  1351. $status_addlock = 1;
  1352. }
  1353. $sql = 'UPDATE '.$tbl_wiki.' SET
  1354. addlock="'.Database::escape_string($status_addlock).'"
  1355. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session;
  1356. Database::query($sql);
  1357. }
  1358. $sql = 'SELECT *
  1359. FROM '.$tbl_wiki.'
  1360. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  1361. ORDER BY id ASC';
  1362. $result = Database::query($sql);
  1363. $row = Database::fetch_array($result);
  1364. }
  1365. return $row['addlock'];
  1366. }
  1367. /**
  1368. * Protect page
  1369. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1370. * return current database status of protect page and change it if get action
  1371. */
  1372. public function check_protect_page()
  1373. {
  1374. $tbl_wiki = $this->tbl_wiki;
  1375. $condition_session = $this->condition_session;
  1376. $groupfilter = $this->groupfilter;
  1377. $page = $this->page;
  1378. $course_id = api_get_course_int_id();
  1379. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1380. WHERE
  1381. c_id = '.$course_id.' AND
  1382. reflink="'.Database::escape_string($page).'" AND
  1383. '.$groupfilter.$condition_session.'
  1384. ORDER BY id ASC';
  1385. $result = Database::query($sql);
  1386. $row = Database::fetch_array($result);
  1387. $status_editlock = $row['editlock'];
  1388. $id = $row['page_id'];
  1389. // Change status
  1390. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  1391. if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lock' && $status_editlock == 0) {
  1392. $status_editlock = 1;
  1393. }
  1394. if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlock' && $status_editlock == 1) {
  1395. $status_editlock = 0;
  1396. }
  1397. $sql = 'UPDATE '.$tbl_wiki.' SET
  1398. editlock="'.Database::escape_string($status_editlock).'"
  1399. WHERE c_id = '.$course_id.' AND page_id="'.$id.'"';
  1400. Database::query($sql);
  1401. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1402. WHERE
  1403. c_id = '.$course_id.' AND
  1404. reflink="'.Database::escape_string($page).'" AND
  1405. '.$groupfilter.$condition_session.'
  1406. ORDER BY id ASC';
  1407. $result = Database::query($sql);
  1408. $row = Database::fetch_array($result);
  1409. }
  1410. //show status
  1411. return $row['editlock'];
  1412. }
  1413. /**
  1414. * Visibility page
  1415. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1416. * return current database status of visibility and change it if get action
  1417. */
  1418. public function check_visibility_page()
  1419. {
  1420. $tbl_wiki = $this->tbl_wiki;
  1421. $page = $this->page;
  1422. $condition_session = $this->condition_session;
  1423. $groupfilter = $this->groupfilter;
  1424. $course_id = api_get_course_int_id();
  1425. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1426. WHERE
  1427. c_id = '.$course_id.' AND
  1428. reflink="'.Database::escape_string($page).'" AND
  1429. '.$groupfilter.$condition_session.'
  1430. ORDER BY id ASC';
  1431. $result = Database::query($sql);
  1432. $row = Database::fetch_array($result);
  1433. $status_visibility = $row['visibility'];
  1434. //change status
  1435. if (api_is_allowed_to_edit(false, true) ||
  1436. api_is_platform_admin()
  1437. ) {
  1438. if (isset($_GET['actionpage']) &&
  1439. $_GET['actionpage'] == 'visible' &&
  1440. $status_visibility == 0
  1441. ) {
  1442. $status_visibility = 1;
  1443. }
  1444. if (isset($_GET['actionpage']) &&
  1445. $_GET['actionpage'] == 'invisible' &&
  1446. $status_visibility == 1
  1447. ) {
  1448. $status_visibility = 0;
  1449. }
  1450. $sql = 'UPDATE '.$tbl_wiki.' SET
  1451. visibility = "'.Database::escape_string($status_visibility).'"
  1452. WHERE
  1453. c_id = '.$course_id.' AND
  1454. reflink="'.Database::escape_string($page).'" AND
  1455. '.$groupfilter.$condition_session;
  1456. Database::query($sql);
  1457. // Although the value now is assigned to all (not only the first),
  1458. // these three lines remain necessary.
  1459. // They do that by changing the page state is
  1460. // made when you press the button and not have to wait to change his page
  1461. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1462. WHERE
  1463. c_id = '.$course_id.' AND
  1464. reflink="'.Database::escape_string($page).'" AND
  1465. '.$groupfilter.$condition_session.'
  1466. ORDER BY id ASC';
  1467. $result = Database::query($sql);
  1468. $row = Database::fetch_array($result);
  1469. }
  1470. if (empty($row['id'])) {
  1471. $row['visibility'] = 1;
  1472. }
  1473. //show status
  1474. return $row['visibility'];
  1475. }
  1476. /**
  1477. * Visibility discussion
  1478. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1479. * @return int current database status of discuss visibility
  1480. * and change it if get action page
  1481. */
  1482. public function check_visibility_discuss()
  1483. {
  1484. $tbl_wiki = $this->tbl_wiki;
  1485. $page = $this->page;
  1486. $condition_session = $this->condition_session;
  1487. $groupfilter = $this->groupfilter;
  1488. $course_id = api_get_course_int_id();
  1489. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1490. WHERE
  1491. c_id = '.$course_id.' AND
  1492. reflink="'.Database::escape_string($page).'" AND
  1493. '.$groupfilter.$condition_session.'
  1494. ORDER BY id ASC';
  1495. $result = Database::query($sql);
  1496. $row = Database::fetch_array($result);
  1497. $status_visibility_disc = $row['visibility_disc'];
  1498. //change status
  1499. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  1500. if (isset($_GET['actionpage']) &&
  1501. $_GET['actionpage'] == 'showdisc' &&
  1502. $status_visibility_disc == 0
  1503. ) {
  1504. $status_visibility_disc = 1;
  1505. }
  1506. if (isset($_GET['actionpage']) &&
  1507. $_GET['actionpage'] == 'hidedisc' &&
  1508. $status_visibility_disc == 1
  1509. ) {
  1510. $status_visibility_disc = 0;
  1511. }
  1512. $sql = 'UPDATE '.$tbl_wiki.' SET
  1513. visibility_disc="'.Database::escape_string($status_visibility_disc).'"
  1514. WHERE
  1515. c_id = '.$course_id.' AND
  1516. reflink="'.Database::escape_string($page).'" AND
  1517. '.$groupfilter.$condition_session;
  1518. Database::query($sql);
  1519. // Although the value now is assigned to all (not only the first),
  1520. // these three lines remain necessary.
  1521. // They do that by changing the page state is made when you press
  1522. // the button and not have to wait to change his page
  1523. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1524. WHERE
  1525. c_id = '.$course_id.' AND
  1526. reflink="'.Database::escape_string($page).'" AND
  1527. '.$groupfilter.$condition_session.'
  1528. ORDER BY id ASC';
  1529. $result = Database::query($sql);
  1530. $row = Database::fetch_array($result);
  1531. }
  1532. return $row['visibility_disc'];
  1533. }
  1534. /**
  1535. * Lock add discussion
  1536. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1537. * @return int current database status of lock dicuss and change if get action
  1538. */
  1539. public function check_addlock_discuss()
  1540. {
  1541. $tbl_wiki = $this->tbl_wiki;
  1542. $page = $this->page;
  1543. $condition_session = $this->condition_session;
  1544. $groupfilter = $this->groupfilter;
  1545. $course_id = api_get_course_int_id();
  1546. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1547. WHERE
  1548. c_id = '.$course_id.' AND
  1549. reflink="'.Database::escape_string($page).'" AND
  1550. '.$groupfilter.$condition_session.'
  1551. ORDER BY id ASC';
  1552. $result = Database::query($sql);
  1553. $row = Database::fetch_array($result);
  1554. $status_addlock_disc = $row['addlock_disc'];
  1555. //change status
  1556. if (api_is_allowed_to_edit() || api_is_platform_admin()) {
  1557. if (isset($_GET['actionpage']) &&
  1558. $_GET['actionpage'] == 'lockdisc' &&
  1559. $status_addlock_disc == 0
  1560. ) {
  1561. $status_addlock_disc = 1;
  1562. }
  1563. if (isset($_GET['actionpage']) &&
  1564. $_GET['actionpage'] == 'unlockdisc' &&
  1565. $status_addlock_disc == 1
  1566. ) {
  1567. $status_addlock_disc = 0;
  1568. }
  1569. $sql = 'UPDATE '.$tbl_wiki.' SET
  1570. addlock_disc="'.Database::escape_string($status_addlock_disc).'"
  1571. WHERE
  1572. c_id = '.$course_id.' AND
  1573. reflink = "'.Database::escape_string($page).'" AND
  1574. '.$groupfilter.$condition_session;
  1575. Database::query($sql);
  1576. // Although the value now is assigned to all (not only the first),
  1577. // these three lines remain necessary.
  1578. // They do that by changing the page state is made when you press
  1579. // the button and not have to wait to change his page
  1580. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1581. WHERE
  1582. c_id = '.$course_id.' AND
  1583. reflink="'.Database::escape_string($page).'" AND
  1584. '.$groupfilter.$condition_session.'
  1585. ORDER BY id ASC';
  1586. $result = Database::query($sql);
  1587. $row = Database::fetch_array($result);
  1588. }
  1589. return $row['addlock_disc'];
  1590. }
  1591. /**
  1592. * Lock rating discussion
  1593. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1594. * @return int current database status of rating discuss and change it if get action
  1595. */
  1596. public function check_ratinglock_discuss()
  1597. {
  1598. $tbl_wiki = $this->tbl_wiki;
  1599. $page = $this->page;
  1600. $condition_session = $this->condition_session;
  1601. $groupfilter = $this->groupfilter;
  1602. $course_id = api_get_course_int_id();
  1603. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1604. WHERE
  1605. c_id = '.$course_id.' AND
  1606. reflink="'.Database::escape_string($page).'" AND
  1607. '.$groupfilter.$condition_session.'
  1608. ORDER BY id ASC';
  1609. $result = Database::query($sql);
  1610. $row = Database::fetch_array($result);
  1611. $status_ratinglock_disc = $row['ratinglock_disc'];
  1612. //change status
  1613. if (api_is_allowed_to_edit(false, true) ||
  1614. api_is_platform_admin()
  1615. ) {
  1616. if (isset($_GET['actionpage']) &&
  1617. $_GET['actionpage'] == 'lockrating' &&
  1618. $status_ratinglock_disc == 0
  1619. ) {
  1620. $status_ratinglock_disc = 1;
  1621. }
  1622. if (isset($_GET['actionpage']) &&
  1623. $_GET['actionpage'] == 'unlockrating' &&
  1624. $status_ratinglock_disc == 1
  1625. ) {
  1626. $status_ratinglock_disc = 0;
  1627. }
  1628. $sql = 'UPDATE '.$tbl_wiki.'
  1629. SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'"
  1630. WHERE
  1631. c_id = '.$course_id.' AND
  1632. reflink="'.Database::escape_string($page).'" AND
  1633. '.$groupfilter.$condition_session;
  1634. // Visibility. Value to all,not only for the first
  1635. Database::query($sql);
  1636. // Although the value now is assigned to all (not only the first),
  1637. // these three lines remain necessary. They do that by changing the
  1638. // page state is made when you press the button and not have to wait
  1639. // to change his page
  1640. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1641. WHERE
  1642. c_id = '.$course_id.' AND
  1643. reflink="'.Database::escape_string($page).'" AND
  1644. '.$groupfilter.$condition_session.'
  1645. ORDER BY id ASC';
  1646. $result = Database::query($sql);
  1647. $row = Database::fetch_array($result);
  1648. }
  1649. return $row['ratinglock_disc'];
  1650. }
  1651. /**
  1652. * Notify page changes
  1653. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1654. * @return int the current notification status
  1655. */
  1656. public function check_notify_page($reflink)
  1657. {
  1658. $tbl_wiki = $this->tbl_wiki;
  1659. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  1660. $condition_session = $this->condition_session;
  1661. $groupfilter = $this->groupfilter;
  1662. $groupId = api_get_group_id();
  1663. $session_id = api_get_session_id();
  1664. $course_id = api_get_course_int_id();
  1665. $userId = api_get_user_id();
  1666. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1667. WHERE
  1668. c_id = '.$course_id.' AND
  1669. reflink="'.$reflink.'" AND
  1670. '.$groupfilter.$condition_session.'
  1671. ORDER BY id ASC';
  1672. $result = Database::query($sql);
  1673. $row = Database::fetch_array($result);
  1674. $id = $row['id'];
  1675. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1676. WHERE
  1677. c_id = '.$course_id.' AND
  1678. id="'.$id.'" AND
  1679. user_id="'.api_get_user_id().'" AND
  1680. type="P"';
  1681. $result = Database::query($sql);
  1682. $row = Database::fetch_array($result);
  1683. $idm = $row['id'];
  1684. if (empty($idm)) {
  1685. $status_notify = 0;
  1686. } else {
  1687. $status_notify = 1;
  1688. }
  1689. // Change status
  1690. if (isset($_GET['actionpage']) &&
  1691. $_GET['actionpage'] == 'locknotify' &&
  1692. $status_notify == 0
  1693. ) {
  1694. $sql = "SELECT id FROM $tbl_wiki_mailcue
  1695. WHERE c_id = $course_id AND id = $id AND user_id = $userId";
  1696. $result = Database::query($sql);
  1697. $exist = false;
  1698. if (Database::num_rows($result)) {
  1699. $exist = true;
  1700. }
  1701. if ($exist == false) {
  1702. $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
  1703. ($course_id, '".$id."','".api_get_user_id(
  1704. )."','P','".$groupId."','".$session_id."')";
  1705. Database::query($sql);
  1706. }
  1707. $status_notify = 1;
  1708. }
  1709. if (isset($_GET['actionpage']) &&
  1710. $_GET['actionpage'] == 'unlocknotify' &&
  1711. $status_notify == 1
  1712. ) {
  1713. $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
  1714. WHERE
  1715. id="'.$id.'" AND
  1716. user_id="'.api_get_user_id().'" AND
  1717. type="P" AND
  1718. c_id = '.$course_id;
  1719. Database::query($sql);
  1720. $status_notify = 0;
  1721. }
  1722. return $status_notify;
  1723. }
  1724. /**
  1725. * Notify discussion changes
  1726. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1727. * @param string $reflink
  1728. * @return int current database status of rating discuss and change it if get action
  1729. */
  1730. public function check_notify_discuss($reflink)
  1731. {
  1732. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  1733. $tbl_wiki = $this->tbl_wiki;
  1734. $condition_session = $this->condition_session;
  1735. $groupfilter = $this->groupfilter;
  1736. $course_id = api_get_course_int_id();
  1737. $groupId = api_get_group_id();
  1738. $session_id = api_get_session_id();
  1739. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1740. WHERE
  1741. c_id = '.$course_id.' AND
  1742. reflink="'.$reflink.'" AND
  1743. '.$groupfilter.$condition_session.'
  1744. ORDER BY id ASC';
  1745. $result = Database::query($sql);
  1746. $row = Database::fetch_array($result);
  1747. $id = $row['id'];
  1748. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1749. WHERE
  1750. c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id(
  1751. ).'" AND type="D"';
  1752. $result = Database::query($sql);
  1753. $row = Database::fetch_array($result);
  1754. $idm = $row['id'];
  1755. if (empty($idm)) {
  1756. $status_notify_disc = 0;
  1757. } else {
  1758. $status_notify_disc = 1;
  1759. }
  1760. // change status
  1761. if (isset($_GET['actionpage']) &&
  1762. $_GET['actionpage'] == 'locknotifydisc' &&
  1763. $status_notify_disc == 0
  1764. ) {
  1765. $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
  1766. ($course_id, '".$id."','".api_get_user_id()."','D','".$groupId."','".$session_id."')";
  1767. Database::query($sql);
  1768. $status_notify_disc = 1;
  1769. }
  1770. if (isset($_GET['actionpage']) &&
  1771. $_GET['actionpage'] == 'unlocknotifydisc' &&
  1772. $status_notify_disc == 1
  1773. ) {
  1774. $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
  1775. WHERE
  1776. c_id = '.$course_id.' AND
  1777. id="'.$id.'" AND
  1778. user_id="'.api_get_user_id().'" AND
  1779. type="D" AND
  1780. c_id = '.$course_id;
  1781. Database::query($sql);
  1782. $status_notify_disc = 0;
  1783. }
  1784. return $status_notify_disc;
  1785. }
  1786. /**
  1787. * Notify all changes
  1788. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1789. */
  1790. public function check_notify_all()
  1791. {
  1792. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  1793. $course_id = api_get_course_int_id();
  1794. $groupId = api_get_group_id();
  1795. $session_id = api_get_session_id();
  1796. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1797. WHERE
  1798. c_id = '.$course_id.' AND
  1799. user_id="'.api_get_user_id().'" AND
  1800. type="F" AND
  1801. group_id="'.$groupId.'" AND
  1802. session_id="'.$session_id.'"';
  1803. $result = Database::query($sql);
  1804. $row = Database::fetch_array($result);
  1805. $idm = $row['user_id'];
  1806. if (empty($idm)) {
  1807. $status_notify_all = 0;
  1808. } else {
  1809. $status_notify_all = 1;
  1810. }
  1811. //change status
  1812. if (isset($_GET['actionpage']) &&
  1813. $_GET['actionpage'] == 'locknotifyall' &&
  1814. $status_notify_all == 0
  1815. ) {
  1816. $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES
  1817. ($course_id, '".api_get_user_id(
  1818. )."','F','".$groupId."','".$session_id."')";
  1819. Database::query($sql);
  1820. $status_notify_all = 1;
  1821. }
  1822. if (isset($_GET['actionpage']) &&
  1823. isset($_GET['actionpage']) &&
  1824. $_GET['actionpage'] == 'unlocknotifyall' &&
  1825. $status_notify_all == 1
  1826. ) {
  1827. $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
  1828. WHERE
  1829. c_id = '.$course_id.' AND
  1830. user_id="'.api_get_user_id().'" AND
  1831. type="F" AND
  1832. group_id="'.$groupId.'" AND
  1833. session_id="'.$session_id.'" AND
  1834. c_id = '.$course_id;
  1835. Database::query($sql);
  1836. $status_notify_all = 0;
  1837. }
  1838. //show status
  1839. return $status_notify_all;
  1840. }
  1841. /**
  1842. * Sends pending e-mails
  1843. */
  1844. public function check_emailcue(
  1845. $id_or_ref,
  1846. $type,
  1847. $lastime = '',
  1848. $lastuser = ''
  1849. ) {
  1850. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  1851. $tbl_wiki = $this->tbl_wiki;
  1852. $condition_session = $this->condition_session;
  1853. $groupfilter = $this->groupfilter;
  1854. $_course = $this->courseInfo;
  1855. $groupId = api_get_group_id();
  1856. $session_id = api_get_session_id();
  1857. $course_id = api_get_course_int_id();
  1858. $group_properties = GroupManager::get_group_properties($groupId);
  1859. $group_name = $group_properties['name'];
  1860. $allow_send_mail = false; //define the variable to below
  1861. $email_assignment = null;
  1862. if ($type == 'P') {
  1863. //if modifying a wiki page
  1864. //first, current author and time
  1865. //Who is the author?
  1866. $userinfo = api_get_user_info($lastuser);
  1867. $email_user_author = get_lang(
  1868. 'EditedBy'
  1869. ).': '.$userinfo['complete_name'];
  1870. //When ?
  1871. $year = substr($lastime, 0, 4);
  1872. $month = substr($lastime, 5, 2);
  1873. $day = substr($lastime, 8, 2);
  1874. $hours = substr($lastime, 11, 2);
  1875. $minutes = substr($lastime, 14, 2);
  1876. $seconds = substr($lastime, 17, 2);
  1877. $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1878. //second, extract data from first reg
  1879. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1880. WHERE
  1881. c_id = '.$course_id.' AND
  1882. reflink="'.$id_or_ref.'" AND
  1883. '.$groupfilter.$condition_session.'
  1884. ORDER BY id ASC';
  1885. $result = Database::query($sql);
  1886. $row = Database::fetch_array($result);
  1887. $id = $row['id'];
  1888. $email_page_name = $row['title'];
  1889. if ($row['visibility'] == 1) {
  1890. $allow_send_mail = true; //if visibility off - notify off
  1891. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1892. WHERE
  1893. c_id = '.$course_id.' AND
  1894. id="'.$id.'" AND
  1895. type="'.$type.'" OR
  1896. type="F" AND
  1897. group_id="'.$groupId.'" AND
  1898. session_id="'.$session_id.'"';
  1899. //type: P=page, D=discuss, F=full.
  1900. $result = Database::query($sql);
  1901. $emailtext = get_lang('EmailWikipageModified').
  1902. '<strong>'.$email_page_name.'</strong> '.
  1903. get_lang('Wiki');
  1904. }
  1905. } elseif ($type == 'D') {
  1906. //if added a post to discuss
  1907. //first, current author and time
  1908. //Who is the author of last message?
  1909. $userinfo = api_get_user_info($lastuser);
  1910. $email_user_author = get_lang(
  1911. 'AddedBy'
  1912. ).': '.$userinfo['complete_name'];
  1913. //When ?
  1914. $year = substr($lastime, 0, 4);
  1915. $month = substr($lastime, 5, 2);
  1916. $day = substr($lastime, 8, 2);
  1917. $hours = substr($lastime, 11, 2);
  1918. $minutes = substr($lastime, 14, 2);
  1919. $seconds = substr($lastime, 17, 2);
  1920. $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1921. //second, extract data from first reg
  1922. $id = $id_or_ref; //$id_or_ref is id from tblwiki
  1923. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1924. WHERE c_id = '.$course_id.' AND id="'.$id.'"
  1925. ORDER BY id ASC';
  1926. $result = Database::query($sql);
  1927. $row = Database::fetch_array($result);
  1928. $email_page_name = $row['title'];
  1929. if ($row['visibility_disc'] == 1) {
  1930. $allow_send_mail = true; //if visibility off - notify off
  1931. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1932. WHERE
  1933. c_id = '.$course_id.' AND
  1934. id="'.$id.'" AND
  1935. type="'.$type.'" OR
  1936. type="F" AND
  1937. group_id="'.$groupId.'" AND
  1938. session_id="'.$session_id.'"';
  1939. //type: P=page, D=discuss, F=full
  1940. $result = Database::query($sql);
  1941. $emailtext = get_lang(
  1942. 'EmailWikiPageDiscAdded'
  1943. ).' <strong>'.$email_page_name.'</strong> '.get_lang(
  1944. 'Wiki'
  1945. );
  1946. }
  1947. } elseif ($type == 'A') {
  1948. //for added pages
  1949. $id = 0; //for tbl_wiki_mailcue
  1950. $sql = 'SELECT * FROM '.$tbl_wiki.'
  1951. WHERE c_id = '.$course_id.'
  1952. ORDER BY id DESC'; //the added is always the last
  1953. $result = Database::query($sql);
  1954. $row = Database::fetch_array($result);
  1955. $email_page_name = $row['title'];
  1956. //Who is the author?
  1957. $userinfo = api_get_user_info($row['user_id']);
  1958. $email_user_author = get_lang(
  1959. 'AddedBy'
  1960. ).': '.$userinfo['complete_name'];
  1961. //When ?
  1962. $year = substr($row['dtime'], 0, 4);
  1963. $month = substr($row['dtime'], 5, 2);
  1964. $day = substr($row['dtime'], 8, 2);
  1965. $hours = substr($row['dtime'], 11, 2);
  1966. $minutes = substr($row['dtime'], 14, 2);
  1967. $seconds = substr($row['dtime'], 17, 2);
  1968. $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1969. if ($row['assignment'] == 0) {
  1970. $allow_send_mail = true;
  1971. } elseif ($row['assignment'] == 1) {
  1972. $email_assignment = get_lang(
  1973. 'AssignmentDescExtra'
  1974. ).' ('.get_lang('AssignmentMode').')';
  1975. $allow_send_mail = true;
  1976. } elseif ($row['assignment'] == 2) {
  1977. $allow_send_mail = false; //Mode tasks: avoids notifications to all users about all users
  1978. }
  1979. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  1980. WHERE
  1981. c_id = '.$course_id.' AND
  1982. id="'.$id.'" AND
  1983. type="F" AND
  1984. group_id="'.$groupId.'" AND
  1985. session_id="'.$session_id.'"';
  1986. //type: P=page, D=discuss, F=full
  1987. $result = Database::query($sql);
  1988. $emailtext = get_lang(
  1989. 'EmailWikiPageAdded'
  1990. ).' <strong>'.$email_page_name.'</strong> '.get_lang(
  1991. 'In'
  1992. ).' '.get_lang('Wiki');
  1993. } elseif ($type == 'E') {
  1994. $id = 0;
  1995. $allow_send_mail = true;
  1996. // Who is the author?
  1997. $userinfo = api_get_user_info(api_get_user_id()); //current user
  1998. $email_user_author = get_lang('DeletedBy').': '.$userinfo['complete_name'];
  1999. //When ?
  2000. $today = date('r'); //current time
  2001. $email_date_changes = $today;
  2002. $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
  2003. WHERE
  2004. c_id = '.$course_id.' AND
  2005. id="'.$id.'" AND type="F" AND
  2006. group_id="'.$groupId.'" AND
  2007. session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=wiki
  2008. $result = Database::query($sql);
  2009. $emailtext = get_lang('EmailWikipageDedeleted');
  2010. }
  2011. ///make and send email
  2012. if ($allow_send_mail) {
  2013. while ($row = Database::fetch_array($result)) {
  2014. $userinfo = api_get_user_info(
  2015. $row['user_id']
  2016. ); //$row['user_id'] obtained from tbl_wiki_mailcue
  2017. $name_to = $userinfo['complete_name'];
  2018. $email_to = $userinfo['email'];
  2019. $sender_name = api_get_setting('emailAdministrator');
  2020. $sender_email = api_get_setting('emailAdministrator');
  2021. $email_subject = get_lang(
  2022. 'EmailWikiChanges'
  2023. ).' - '.$_course['official_code'];
  2024. $email_body = get_lang('DearUser').' '.api_get_person_name(
  2025. $userinfo['firstname'],
  2026. $userinfo['lastname']
  2027. ).',<br /><br />';
  2028. if ($session_id == 0) {
  2029. $email_body .= $emailtext.' <strong>'.$_course['name'].' - '.$group_name.'</strong><br /><br /><br />';
  2030. } else {
  2031. $email_body .= $emailtext.' <strong>'.$_course['name'].' ('.api_get_session_name(
  2032. api_get_session_id()
  2033. ).') - '.$group_name.'</strong><br /><br /><br />';
  2034. }
  2035. $email_body .= $email_user_author.' ('.$email_date_changes.')<br /><br /><br />';
  2036. $email_body .= $email_assignment.'<br /><br /><br />';
  2037. $email_body .= '<font size="-2">'.get_lang(
  2038. 'EmailWikiChangesExt_1'
  2039. ).': <strong>'.get_lang('NotifyChanges').'</strong><br />';
  2040. $email_body .= get_lang(
  2041. 'EmailWikiChangesExt_2'
  2042. ).': <strong>'.get_lang(
  2043. 'NotNotifyChanges'
  2044. ).'</strong></font><br />';
  2045. @api_mail_html(
  2046. $name_to,
  2047. $email_to,
  2048. $email_subject,
  2049. $email_body,
  2050. $sender_name,
  2051. $sender_email
  2052. );
  2053. }
  2054. }
  2055. }
  2056. /**
  2057. * Function export last wiki page version to document area
  2058. * @param int $doc_id wiki page id
  2059. * @return mixed
  2060. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2061. */
  2062. public function export2doc($doc_id)
  2063. {
  2064. $_course = $this->courseInfo;
  2065. $groupId = api_get_group_id();
  2066. $groupInfo = GroupManager::get_group_properties($groupId);
  2067. $data = self::getWikiDataFromDb($doc_id);
  2068. if (empty($data)) {
  2069. return false;
  2070. }
  2071. $wikiTitle = $data['title'];
  2072. $wikiContents = $data['content'];
  2073. $template =
  2074. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2075. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}">
  2076. <head>
  2077. <title>{TITLE}</title>
  2078. <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
  2079. <style type="text/css" media="screen, projection">
  2080. /*<![CDATA[*/
  2081. {CSS}
  2082. /*]]>*/
  2083. </style>
  2084. {ASCIIMATHML_SCRIPT}</head>
  2085. <body dir="{TEXT_DIRECTION}">
  2086. {CONTENT}
  2087. </body>
  2088. </html>';
  2089. $css_file = api_get_path(SYS_CSS_PATH).'themes/'.api_get_setting(
  2090. 'stylesheets'
  2091. ).'/default.css';
  2092. if (file_exists($css_file)) {
  2093. $css = @file_get_contents($css_file);
  2094. } else {
  2095. $css = '';
  2096. }
  2097. // Fixing some bugs in css files.
  2098. $root_rel = api_get_path(REL_PATH);
  2099. $css_path = 'main/css/';
  2100. $theme = api_get_setting('stylesheets').'/';
  2101. $css = str_replace(
  2102. 'behavior:url("/main/css/csshover3.htc");',
  2103. '',
  2104. $css
  2105. );
  2106. $css = str_replace('main/', $root_rel.'main/', $css);
  2107. $css = str_replace(
  2108. 'images/',
  2109. $root_rel.$css_path.$theme.'images/',
  2110. $css
  2111. );
  2112. $css = str_replace('../../img/', $root_rel.'main/img/', $css);
  2113. $asciimathmal_script = (api_contains_asciimathml(
  2114. $wikiContents
  2115. ) || api_contains_asciisvg($wikiContents))
  2116. ? '<script src="'.api_get_path(
  2117. WEB_CODE_PATH
  2118. ).'inc/lib/javascript/asciimath/ASCIIMathML.js" type="text/javascript"></script>'."\n" : '';
  2119. $template = str_replace(
  2120. [
  2121. '{LANGUAGE}',
  2122. '{ENCODING}',
  2123. '{TEXT_DIRECTION}',
  2124. '{TITLE}',
  2125. '{CSS}',
  2126. '{ASCIIMATHML_SCRIPT}'
  2127. ],
  2128. [
  2129. api_get_language_isocode(),
  2130. api_get_system_encoding(),
  2131. api_get_text_direction(),
  2132. $wikiTitle,
  2133. $css,
  2134. $asciimathmal_script
  2135. ],
  2136. $template
  2137. );
  2138. if (0 != $groupId) {
  2139. $groupPart = '_group'.$groupId; // and add groupId to put the same document title in different groups
  2140. $group_properties = GroupManager::get_group_properties($groupId);
  2141. $groupPath = $group_properties['directory'];
  2142. } else {
  2143. $groupPart = '';
  2144. $groupPath = '';
  2145. }
  2146. $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(
  2147. ).'/document'.$groupPath;
  2148. $exportFile = api_replace_dangerous_char($wikiTitle).$groupPart;
  2149. $wikiContents = trim(
  2150. preg_replace(
  2151. "/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/",
  2152. "$1",
  2153. $wikiContents
  2154. )
  2155. );
  2156. //TODO: put link instead of title
  2157. $wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
  2158. // replace relative path by absolute path for courses, so you can see
  2159. // items into this page wiki (images, mp3, etc..) exported in documents
  2160. if (api_strpos(
  2161. $wikiContents,
  2162. '../..'.api_get_path(REL_COURSE_PATH)
  2163. ) !== false) {
  2164. $web_course_path = api_get_path(WEB_COURSE_PATH);
  2165. $wikiContents = str_replace(
  2166. '../..'.api_get_path(REL_COURSE_PATH),
  2167. $web_course_path,
  2168. $wikiContents
  2169. );
  2170. }
  2171. $i = 1;
  2172. //only export last version, but in new export new version in document area
  2173. while (file_exists($exportDir.'/'.$exportFile.'_'.$i.'.html')) {
  2174. $i++;
  2175. }
  2176. $wikiFileName = $exportFile.'_'.$i.'.html';
  2177. $exportPath = $exportDir.'/'.$wikiFileName;
  2178. file_put_contents($exportPath, $wikiContents);
  2179. $doc_id = add_document(
  2180. $_course,
  2181. $groupPath.'/'.$wikiFileName,
  2182. 'file',
  2183. filesize($exportPath),
  2184. $wikiTitle
  2185. );
  2186. api_item_property_update(
  2187. $_course,
  2188. TOOL_DOCUMENT,
  2189. $doc_id,
  2190. 'DocumentAdded',
  2191. api_get_user_id(),
  2192. $groupInfo
  2193. );
  2194. return $doc_id;
  2195. }
  2196. /**
  2197. * Exports the wiki page to PDF
  2198. */
  2199. public function export_to_pdf($id, $course_code)
  2200. {
  2201. if (!api_is_platform_admin()) {
  2202. if (api_get_setting('students_export2pdf') !== 'true') {
  2203. Display::addFlash(
  2204. Display::return_message(
  2205. get_lang('PDFDownloadNotAllowedForStudents'),
  2206. 'error',
  2207. false
  2208. )
  2209. );
  2210. return false;
  2211. }
  2212. }
  2213. $data = self::getWikiDataFromDb($id);
  2214. $content_pdf = api_html_entity_decode(
  2215. $data['content'],
  2216. ENT_QUOTES,
  2217. api_get_system_encoding()
  2218. );
  2219. //clean wiki links
  2220. $content_pdf = trim(
  2221. preg_replace(
  2222. "/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/",
  2223. "$1",
  2224. $content_pdf
  2225. )
  2226. );
  2227. //TODO: It should be better to display the link insted of the tile but it is hard for [[title]] links
  2228. $title_pdf = api_html_entity_decode(
  2229. $data['title'],
  2230. ENT_QUOTES,
  2231. api_get_system_encoding()
  2232. );
  2233. $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
  2234. $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding());
  2235. $html = '
  2236. <!-- defines the headers/footers - this must occur before the headers/footers are set -->
  2237. <!--mpdf
  2238. <pageheader name="odds" content-left="'.$title_pdf.'" header-style-left="color: #880000; font-style: italic;" line="1" />
  2239. <pagefooter name="odds" content-right="{PAGENO}/{nb}" line="1" />
  2240. <!-- set the headers/footers - they will occur from here on in the document -->
  2241. <!--mpdf
  2242. <setpageheader name="odds" page="odd" value="on" show-this-page="1" />
  2243. <setpagefooter name="odds" page="O" value="on" />
  2244. mpdf-->'.$content_pdf;
  2245. $css_file = api_get_path(SYS_CSS_PATH).'themes/'.api_get_setting('stylesheets').'/print.css';
  2246. if (file_exists($css_file)) {
  2247. $css = @file_get_contents($css_file);
  2248. } else {
  2249. $css = '';
  2250. }
  2251. $pdf = new PDF();
  2252. $pdf->content_to_pdf($html, $css, $title_pdf, $course_code);
  2253. exit;
  2254. }
  2255. /**
  2256. * Function prevent double post (reload or F5)
  2257. *
  2258. */
  2259. public function double_post($wpost_id)
  2260. {
  2261. $postId = Session::read('wpost_id');
  2262. if (!empty($postId)) {
  2263. if ($wpost_id == $postId) {
  2264. return false;
  2265. } else {
  2266. Session::write('wpost_id', $wpost_id);
  2267. return true;
  2268. }
  2269. } else {
  2270. Session::write('wpost_id', $wpost_id);
  2271. return true;
  2272. }
  2273. }
  2274. /**
  2275. * Function wizard individual assignment
  2276. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2277. */
  2278. public function auto_add_page_users($values)
  2279. {
  2280. $assignment_type = $values['assignment'];
  2281. $session_id = $this->session_id;
  2282. $groupId = api_get_group_id();
  2283. $groupInfo = GroupManager::get_group_properties($groupId);
  2284. if ($groupId == 0) {
  2285. //extract course members
  2286. if (!empty($session_id)) {
  2287. $a_users_to_add = CourseManager::get_user_list_from_course_code(
  2288. api_get_course_id(),
  2289. $session_id
  2290. );
  2291. } else {
  2292. $a_users_to_add = CourseManager::get_user_list_from_course_code(
  2293. api_get_course_id(),
  2294. 0
  2295. );
  2296. }
  2297. } else {
  2298. //extract group members
  2299. $subscribed_users = GroupManager::get_subscribed_users($groupInfo);
  2300. $subscribed_tutors = GroupManager::get_subscribed_tutors(
  2301. $groupInfo
  2302. );
  2303. $a_users_to_add_with_duplicates = array_merge(
  2304. $subscribed_users,
  2305. $subscribed_tutors
  2306. );
  2307. //remove duplicates
  2308. $a_users_to_add = $a_users_to_add_with_duplicates;
  2309. $a_users_to_add = array_unique($a_users_to_add);
  2310. }
  2311. $all_students_pages = [];
  2312. // Data about teacher
  2313. $userId = api_get_user_id();
  2314. $userinfo = api_get_user_info($userId);
  2315. $username = api_htmlentities(
  2316. sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES)
  2317. );
  2318. $name = $userinfo['complete_name']." - ".$username;
  2319. $photo = '<img src="'.$userinfo['avatar'].'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  2320. // teacher assignment title
  2321. $title_orig = $values['title'];
  2322. // teacher assignment reflink
  2323. $link2teacher = $values['title'] = $title_orig."_uass".$userId;
  2324. // first: teacher name, photo, and assignment description (original content)
  2325. $content_orig_A = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6">
  2326. <table border="0">
  2327. <tr><td style="font-size:24px">'.get_lang('AssignmentDesc').'</td></tr>
  2328. <tr><td>'.$photo.'<br />'.Display::tag(
  2329. 'span',
  2330. api_get_person_name(
  2331. $userinfo['firstname'],
  2332. $userinfo['lastname']
  2333. ),
  2334. ['title' => $username]
  2335. ).'</td></tr>
  2336. </table></div>';
  2337. $content_orig_B = '<br/><div align="center" style="font-size:24px">'.
  2338. get_lang('AssignmentDescription').': '.
  2339. $title_orig.'</div><br/>'.Security::remove_XSS($_POST['content']);
  2340. //Second: student list (names, photo and links to their works).
  2341. //Third: Create Students work pages.
  2342. foreach ($a_users_to_add as $o_user_to_add) {
  2343. if ($o_user_to_add['user_id'] != $userId) {
  2344. // except that puts the task
  2345. $assig_user_id = $o_user_to_add['user_id'];
  2346. // identifies each page as created by the student, not by teacher
  2347. $userPicture = UserManager::getUserPicture($assig_user_id);
  2348. $username = api_htmlentities(
  2349. sprintf(
  2350. get_lang('LoginX'),
  2351. $o_user_to_add['username'],
  2352. ENT_QUOTES
  2353. )
  2354. );
  2355. $name = api_get_person_name(
  2356. $o_user_to_add['firstname'],
  2357. $o_user_to_add['lastname']
  2358. )." . ".$username;
  2359. $photo = '<img src="'.$userPicture.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />';
  2360. $is_tutor_of_group = GroupManager::is_tutor_of_group(
  2361. $assig_user_id,
  2362. $groupInfo
  2363. ); //student is tutor
  2364. $is_tutor_and_member = GroupManager::is_tutor_of_group(
  2365. $assig_user_id,
  2366. $groupInfo
  2367. ) &&
  2368. GroupManager::is_subscribed($assig_user_id, $groupInfo);
  2369. // student is tutor and member
  2370. if ($is_tutor_and_member) {
  2371. $status_in_group = get_lang('GroupTutorAndMember');
  2372. } else {
  2373. if ($is_tutor_of_group) {
  2374. $status_in_group = get_lang('GroupTutor');
  2375. } else {
  2376. $status_in_group = " "; //get_lang('GroupStandardMember')
  2377. }
  2378. }
  2379. if ($assignment_type == 1) {
  2380. $values['title'] = $title_orig;
  2381. $values['content'] = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6">
  2382. <table border="0">
  2383. <tr><td style="font-size:24px">'.get_lang('AssignmentWork').'</td></tr>
  2384. <tr><td>'.$photo.'<br />'.$name.'</td></tr></table>
  2385. </div>[['.$link2teacher.' | '.get_lang(
  2386. 'AssignmentLinktoTeacherPage'
  2387. ).']] ';
  2388. //If $content_orig_B is added here, the task written by
  2389. // the professor was copied to the page of each student.
  2390. // TODO: config options
  2391. // AssignmentLinktoTeacherPage
  2392. $all_students_pages[] = '<li>'.
  2393. Display::tag(
  2394. 'span',
  2395. strtoupper(
  2396. $o_user_to_add['lastname']
  2397. ).', '.$o_user_to_add['firstname'],
  2398. ['title' => $username]
  2399. ).
  2400. ' [['.Security::remove_XSS(
  2401. $_POST['title']
  2402. )."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>';
  2403. // don't change this line without guaranteeing
  2404. // that users will be ordered by last names in the
  2405. // following format (surname, name)
  2406. $values['assignment'] = 2;
  2407. }
  2408. $this->assig_user_id = $assig_user_id;
  2409. self::save_new_wiki($values);
  2410. }
  2411. }
  2412. foreach ($a_users_to_add as $o_user_to_add) {
  2413. if ($o_user_to_add['user_id'] == $userId) {
  2414. $assig_user_id = $o_user_to_add['user_id'];
  2415. if ($assignment_type == 1) {
  2416. $values['title'] = $title_orig;
  2417. $values['comment'] = get_lang('AssignmentDesc');
  2418. sort($all_students_pages);
  2419. $values['content'] = $content_orig_A.$content_orig_B.'<br/>
  2420. <div align="center" style="font-size:18px; background-color: #F5F8FB; border:solid; border-color:#E6E6E6">
  2421. '.get_lang('AssignmentLinkstoStudentsPage').'
  2422. </div><br/>
  2423. <div style="background-color: #F5F8FB; border:solid; border-color:#E6E6E6">
  2424. <ol>'.implode($all_students_pages).'</ol>
  2425. </div>
  2426. <br/>';
  2427. $values['assignment'] = 1;
  2428. }
  2429. $this->assig_user_id = $assig_user_id;
  2430. self::save_new_wiki($values);
  2431. }
  2432. }
  2433. }
  2434. /**
  2435. * Displays the results of a wiki search
  2436. * @param string Search term
  2437. * @param int Whether to search the contents (1) or just the titles (0)
  2438. * @param int
  2439. */
  2440. public function display_wiki_search_results(
  2441. $search_term,
  2442. $search_content = 0,
  2443. $all_vers = 0
  2444. ) {
  2445. $tbl_wiki = $this->tbl_wiki;
  2446. $condition_session = $this->condition_session;
  2447. $groupfilter = $this->groupfilter;
  2448. $_course = $this->courseInfo;
  2449. $course_id = api_get_course_int_id();
  2450. echo '<legend>'.get_lang('WikiSearchResults').': '.Security::remove_XSS(
  2451. $search_term
  2452. );
  2453. echo '</legend>';
  2454. //only by professors when page is hidden
  2455. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  2456. if ($all_vers == '1') {
  2457. if ($search_content == '1') {
  2458. $sql = "SELECT * FROM ".$tbl_wiki."
  2459. WHERE
  2460. c_id = $course_id AND
  2461. title LIKE '%".Database::escape_string(
  2462. $search_term
  2463. )."%' OR
  2464. content LIKE '%".Database::escape_string(
  2465. $search_term
  2466. )."%' AND
  2467. ".$groupfilter.$condition_session."";
  2468. //search all pages and all versions
  2469. } else {
  2470. $sql = "SELECT * FROM ".$tbl_wiki."
  2471. WHERE
  2472. c_id = $course_id AND
  2473. title LIKE '%".Database::escape_string(
  2474. $search_term
  2475. )."%' AND
  2476. ".$groupfilter.$condition_session."";
  2477. //search all pages and all versions
  2478. }
  2479. } else {
  2480. if ($search_content == '1') {
  2481. $sql = "SELECT * FROM ".$tbl_wiki." s1
  2482. WHERE
  2483. s1.c_id = $course_id AND
  2484. title LIKE '%".Database::escape_string(
  2485. $search_term
  2486. )."%' OR
  2487. content LIKE '%".Database::escape_string(
  2488. $search_term
  2489. )."%' AND
  2490. id=(
  2491. SELECT MAX(s2.id)
  2492. FROM ".$tbl_wiki." s2
  2493. WHERE
  2494. s2.c_id = $course_id AND
  2495. s1.reflink = s2.reflink AND
  2496. ".$groupfilter.$condition_session.")";
  2497. // warning don't use group by reflink because don't return the last version
  2498. } else {
  2499. $sql = "SELECT * FROM ".$tbl_wiki." s1
  2500. WHERE
  2501. s1.c_id = $course_id AND
  2502. title LIKE '%".Database::escape_string(
  2503. $search_term
  2504. )."%' AND
  2505. id = (
  2506. SELECT MAX(s2.id)
  2507. FROM ".$tbl_wiki." s2
  2508. WHERE
  2509. s2.c_id = $course_id AND
  2510. s1.reflink = s2.reflink AND
  2511. ".$groupfilter.$condition_session.")";
  2512. // warning don't use group by reflink because don't return the last version
  2513. }
  2514. }
  2515. } else {
  2516. if ($all_vers == '1') {
  2517. if ($search_content == '1') {
  2518. $sql = "SELECT * FROM ".$tbl_wiki."
  2519. WHERE
  2520. c_id = $course_id AND
  2521. visibility=1 AND
  2522. title LIKE '%".Database::escape_string(
  2523. $search_term
  2524. )."%' OR
  2525. content LIKE '%".Database::escape_string(
  2526. $search_term
  2527. )."%' AND
  2528. ".$groupfilter.$condition_session."";
  2529. //search all pages and all versions
  2530. } else {
  2531. $sql = "SELECT * FROM ".$tbl_wiki."
  2532. WHERE
  2533. c_id = $course_id AND
  2534. visibility=1 AND
  2535. title LIKE '%".Database::escape_string(
  2536. $search_term
  2537. )."%' AND
  2538. ".$groupfilter.$condition_session."";
  2539. //search all pages and all versions
  2540. }
  2541. } else {
  2542. if ($search_content == '1') {
  2543. $sql = "SELECT * FROM ".$tbl_wiki." s1
  2544. WHERE
  2545. s1.c_id = $course_id AND
  2546. visibility=1 AND
  2547. title LIKE '%".Database::escape_string(
  2548. $search_term
  2549. )."%' OR
  2550. content LIKE '%".Database::escape_string(
  2551. $search_term
  2552. )."%' AND
  2553. id=(
  2554. SELECT MAX(s2.id)
  2555. FROM ".$tbl_wiki." s2
  2556. WHERE s2.c_id = $course_id AND
  2557. s1.reflink = s2.reflink AND
  2558. ".$groupfilter.$condition_session.")";
  2559. // warning don't use group by reflink because don't return the last version
  2560. } else {
  2561. $sql = "SELECT * FROM ".$tbl_wiki." s1
  2562. WHERE
  2563. s1.c_id = $course_id AND
  2564. visibility=1 AND
  2565. title LIKE '%".Database::escape_string(
  2566. $search_term
  2567. )."%' AND
  2568. id = (
  2569. SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
  2570. WHERE s2.c_id = $course_id AND
  2571. s1.reflink = s2.reflink AND
  2572. ".$groupfilter.$condition_session.")";
  2573. // warning don't use group by reflink because don't return the last version
  2574. }
  2575. }
  2576. }
  2577. $result = Database::query($sql);
  2578. //show table
  2579. $rows = [];
  2580. if (Database::num_rows($result) > 0) {
  2581. while ($obj = Database::fetch_object($result)) {
  2582. //get author
  2583. $userinfo = api_get_user_info($obj->user_id);
  2584. //get time
  2585. $year = substr($obj->dtime, 0, 4);
  2586. $month = substr($obj->dtime, 5, 2);
  2587. $day = substr($obj->dtime, 8, 2);
  2588. $hours = substr($obj->dtime, 11, 2);
  2589. $minutes = substr($obj->dtime, 14, 2);
  2590. $seconds = substr($obj->dtime, 17, 2);
  2591. //get type assignment icon
  2592. if ($obj->assignment == 1) {
  2593. $ShowAssignment = Display::return_icon(
  2594. 'wiki_assignment.png',
  2595. get_lang('AssignmentDesc'),
  2596. '',
  2597. ICON_SIZE_SMALL
  2598. );
  2599. } elseif ($obj->assignment == 2) {
  2600. $ShowAssignment = Display::return_icon(
  2601. 'wiki_work.png',
  2602. get_lang('AssignmentWork'),
  2603. '',
  2604. ICON_SIZE_SMALL
  2605. );
  2606. } elseif ($obj->assignment == 0) {
  2607. $ShowAssignment = Display::return_icon(
  2608. 'px_transparent.gif'
  2609. );
  2610. }
  2611. $row = [];
  2612. $row[] = $ShowAssignment;
  2613. if ($all_vers == '1') {
  2614. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
  2615. ).'&action=showpage&title='.api_htmlentities(
  2616. urlencode($obj->reflink)
  2617. ).'&view='.$obj->id.'&session_id='.api_htmlentities(
  2618. urlencode($_GET['$session_id'])
  2619. ).'&group_id='.api_htmlentities(
  2620. urlencode($_GET['group_id'])
  2621. ).'">'.
  2622. api_htmlentities($obj->title).'</a>';
  2623. } else {
  2624. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
  2625. ).'&action=showpage&title='.api_htmlentities(
  2626. urlencode($obj->reflink)
  2627. ).'&session_id='.api_htmlentities(
  2628. $_GET['session_id']
  2629. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  2630. $obj->title.'</a>';
  2631. }
  2632. $row[] = ($obj->user_id != 0 && $userinfo !== false) ? UserManager::getUserProfileLink(
  2633. $userinfo
  2634. ) : get_lang('Anonymous').' ('.$obj->user_ip.')';
  2635. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  2636. if ($all_vers == '1') {
  2637. $row[] = $obj->version;
  2638. } else {
  2639. $showdelete = '';
  2640. if (api_is_allowed_to_edit(
  2641. false,
  2642. true
  2643. ) || api_is_platform_admin()) {
  2644. $showdelete = ' <a href="'.api_get_self(
  2645. ).'?'.api_get_cidreq(
  2646. ).'&action=delete&title='.api_htmlentities(
  2647. urlencode($obj->reflink)
  2648. ).'&group_id='.api_htmlentities(
  2649. $_GET['group_id']
  2650. ).'">'.
  2651. Display::return_icon(
  2652. 'delete.png',
  2653. get_lang('Delete'),
  2654. '',
  2655. ICON_SIZE_SMALL
  2656. );
  2657. }
  2658. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
  2659. ).'&action=edit&title='.api_htmlentities(
  2660. urlencode($obj->reflink)
  2661. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  2662. Display::return_icon(
  2663. 'edit.png',
  2664. get_lang('EditPage'),
  2665. '',
  2666. ICON_SIZE_SMALL
  2667. ).'</a>
  2668. <a href="'.api_get_self(
  2669. ).'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(
  2670. urlencode($obj->reflink)
  2671. ).'&session_id='.api_htmlentities(
  2672. $_GET['session_id']
  2673. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  2674. Display::return_icon(
  2675. 'discuss.png',
  2676. get_lang('Discuss'),
  2677. '',
  2678. ICON_SIZE_SMALL
  2679. ).'</a>
  2680. <a href="'.api_get_self(
  2681. ).'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(
  2682. urlencode($obj->reflink)
  2683. ).'&session_id='.api_htmlentities(
  2684. $_GET['session_id']
  2685. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  2686. Display::return_icon(
  2687. 'history.png',
  2688. get_lang('History'),
  2689. '',
  2690. ICON_SIZE_SMALL
  2691. ).'</a> <a href="'.api_get_self(
  2692. ).'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(
  2693. urlencode($obj->reflink)
  2694. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  2695. Display::return_icon(
  2696. 'what_link_here.png',
  2697. get_lang('LinksPages'),
  2698. '',
  2699. ICON_SIZE_SMALL
  2700. ).'</a>'.$showdelete;
  2701. }
  2702. $rows[] = $row;
  2703. }
  2704. $table = new SortableTableFromArrayConfig(
  2705. $rows,
  2706. 1,
  2707. 10,
  2708. 'SearchPages_table',
  2709. '',
  2710. '',
  2711. 'ASC'
  2712. );
  2713. $table->set_additional_parameters(
  2714. [
  2715. 'cidReq' => $_GET['cidReq'],
  2716. 'action' => $_GET['action'],
  2717. 'group_id' => intval($_GET['group_id']),
  2718. 'mode_table' => 'yes2',
  2719. 'search_term' => $search_term,
  2720. 'search_content' => $search_content,
  2721. 'all_vers' => $all_vers,
  2722. ]
  2723. );
  2724. $table->set_header(
  2725. 0,
  2726. get_lang('Type'),
  2727. true,
  2728. ['style' => 'width:30px;']
  2729. );
  2730. $table->set_header(1, get_lang('Title'), true);
  2731. if ($all_vers == '1') {
  2732. $table->set_header(2, get_lang('Author'), true);
  2733. $table->set_header(3, get_lang('Date'), true);
  2734. $table->set_header(4, get_lang('Version'), true);
  2735. } else {
  2736. $table->set_header(
  2737. 2,
  2738. get_lang('Author').' ('.get_lang('LastVersion').')',
  2739. true
  2740. );
  2741. $table->set_header(
  2742. 3,
  2743. get_lang('Date').' ('.get_lang('LastVersion').')',
  2744. true
  2745. );
  2746. $table->set_header(
  2747. 4,
  2748. get_lang('Actions'),
  2749. false,
  2750. ['style' => 'width:130px;']
  2751. );
  2752. }
  2753. $table->display();
  2754. } else {
  2755. echo get_lang('NoSearchResults');
  2756. }
  2757. }
  2758. /**
  2759. * Get wiki information
  2760. * @param int|bool wiki id
  2761. * @return array wiki data
  2762. */
  2763. public function getWikiDataFromDb($id)
  2764. {
  2765. $tbl_wiki = $this->tbl_wiki;
  2766. $course_id = api_get_course_int_id();
  2767. if ($id === false) {
  2768. return [];
  2769. }
  2770. $id = intval($id);
  2771. $sql = 'SELECT * FROM '.$tbl_wiki.'
  2772. WHERE c_id = '.$course_id.' AND id = '.$id.' ';
  2773. $result = Database::query($sql);
  2774. $data = [];
  2775. while ($row = Database::fetch_array($result, 'ASSOC')) {
  2776. $data = $row;
  2777. }
  2778. return $data;
  2779. }
  2780. /**
  2781. * @param string $refLink
  2782. * @return array
  2783. */
  2784. public function getLastWikiData($refLink)
  2785. {
  2786. $tbl_wiki = $this->tbl_wiki;
  2787. $groupfilter = $this->groupfilter;
  2788. $condition_session = $this->condition_session;
  2789. $course_id = api_get_course_int_id();
  2790. $sql = 'SELECT * FROM '.$tbl_wiki.'
  2791. WHERE
  2792. c_id = '.$course_id.' AND
  2793. reflink="'.Database::escape_string($refLink).'" AND
  2794. '.$groupfilter.$condition_session.'
  2795. ORDER BY id DESC';
  2796. $result = Database::query($sql);
  2797. return Database::fetch_array($result);
  2798. }
  2799. /**
  2800. * Get wiki information
  2801. * @param string wiki id
  2802. * @param int $courseId
  2803. * @return array wiki data
  2804. */
  2805. public function getPageByTitle($title, $courseId = null)
  2806. {
  2807. $tbl_wiki = $this->tbl_wiki;
  2808. if (empty($courseId)) {
  2809. $courseId = api_get_course_int_id();
  2810. } else {
  2811. $courseId = intval($courseId);
  2812. }
  2813. if (empty($title) || empty($courseId)) {
  2814. return [];
  2815. }
  2816. $title = Database::escape_string($title);
  2817. $sql = "SELECT * FROM $tbl_wiki
  2818. WHERE c_id = $courseId AND reflink = '$title'";
  2819. $result = Database::query($sql);
  2820. $data = [];
  2821. if (Database::num_rows($result)) {
  2822. $data = Database::fetch_array($result, 'ASSOC');
  2823. }
  2824. return $data;
  2825. }
  2826. /**
  2827. * @param string $title
  2828. * @param int $courseId
  2829. * @param string
  2830. * @param string
  2831. * @return bool
  2832. */
  2833. public function deletePage(
  2834. $title,
  2835. $courseId,
  2836. $groupfilter = null,
  2837. $condition_session = null
  2838. ) {
  2839. $tbl_wiki = $this->tbl_wiki;
  2840. $tbl_wiki_discuss = $this->tbl_wiki_discuss;
  2841. $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
  2842. $tbl_wiki_conf = $this->tbl_wiki_conf;
  2843. $pageInfo = self::getPageByTitle($title, $courseId);
  2844. if (!empty($pageInfo)) {
  2845. $pageId = $pageInfo['id'];
  2846. $sql = "DELETE FROM $tbl_wiki_conf
  2847. WHERE c_id = $courseId AND page_id = $pageId";
  2848. Database::query($sql);
  2849. $sql = 'DELETE FROM '.$tbl_wiki_discuss.'
  2850. WHERE c_id = '.$courseId.' AND publication_id = '.$pageId;
  2851. Database::query($sql);
  2852. $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
  2853. WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.'';
  2854. Database::query($sql);
  2855. $sql = 'DELETE FROM '.$tbl_wiki.'
  2856. WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.'';
  2857. Database::query($sql);
  2858. self::check_emailcue(0, 'E');
  2859. return true;
  2860. }
  2861. return false;
  2862. }
  2863. /**
  2864. * @return array
  2865. */
  2866. public function getAllWiki()
  2867. {
  2868. $tbl_wiki = $this->tbl_wiki;
  2869. $course_id = $this->course_id;
  2870. $condition_session = $this->condition_session;
  2871. $sql = "SELECT * FROM $tbl_wiki
  2872. WHERE
  2873. c_id = $course_id AND
  2874. is_editing != '0' ".$condition_session;
  2875. $result = Database::query($sql);
  2876. return Database::store_result($result, 'ASSOC');
  2877. }
  2878. /**
  2879. * @param int $isEditing
  2880. */
  2881. public function updateWikiIsEditing($isEditing)
  2882. {
  2883. $tbl_wiki = $this->tbl_wiki;
  2884. $course_id = $this->course_id;
  2885. $condition_session = $this->condition_session;
  2886. $isEditing = Database::escape_string($isEditing);
  2887. $sql = 'UPDATE '.$tbl_wiki.' SET
  2888. is_editing = "0",
  2889. time_edit = NULL
  2890. WHERE
  2891. c_id = '.$course_id.' AND
  2892. is_editing="'.$isEditing.'" '.
  2893. $condition_session;
  2894. Database::query($sql);
  2895. }
  2896. /**
  2897. * Release of blocked pages to prevent concurrent editions
  2898. * @param int $userId
  2899. * @param string $action
  2900. */
  2901. public function blockConcurrentEditions($userId, $action = null)
  2902. {
  2903. $result = self::getAllWiki();
  2904. if (!empty($result)) {
  2905. foreach ($result as $is_editing_block) {
  2906. $max_edit_time = 1200; // 20 minutes
  2907. $timestamp_edit = strtotime($is_editing_block['time_edit']);
  2908. $time_editing = time() - $timestamp_edit;
  2909. // First prevent concurrent users and double version
  2910. if ($is_editing_block['is_editing'] == $userId) {
  2911. Session::write('_version', $is_editing_block['version']);
  2912. } else {
  2913. Session::erase('_version');
  2914. }
  2915. // Second checks if has exceeded the time that a page may
  2916. // be available or if a page was edited and saved by its author
  2917. if ($time_editing > $max_edit_time ||
  2918. ($is_editing_block['is_editing'] == $userId &&
  2919. $action != 'edit')
  2920. ) {
  2921. self::updateWikiIsEditing($is_editing_block['is_editing']);
  2922. }
  2923. }
  2924. }
  2925. }
  2926. /**
  2927. * Showing wiki stats
  2928. */
  2929. public function getStats()
  2930. {
  2931. if (!api_is_allowed_to_edit(false, true)) {
  2932. return false;
  2933. }
  2934. $tbl_wiki = $this->tbl_wiki;
  2935. $course_id = $this->course_id;
  2936. $condition_session = $this->condition_session;
  2937. $groupfilter = $this->groupfilter;
  2938. $session_id = $this->session_id;
  2939. $tbl_wiki_conf = $this->tbl_wiki_conf;
  2940. echo '<div class="actions">'.get_lang('Statistics').'</div>';
  2941. // Check all versions of all pages
  2942. $total_words = 0;
  2943. $total_links = 0;
  2944. $total_links_anchors = 0;
  2945. $total_links_mail = 0;
  2946. $total_links_ftp = 0;
  2947. $total_links_irc = 0;
  2948. $total_links_news = 0;
  2949. $total_wlinks = 0;
  2950. $total_images = 0;
  2951. $clean_total_flash = 0;
  2952. $total_flash = 0;
  2953. $total_mp3 = 0;
  2954. $total_flv_p = 0;
  2955. $total_flv = 0;
  2956. $total_youtube = 0;
  2957. $total_multimedia = 0;
  2958. $total_tables = 0;
  2959. $sql = "SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS
  2960. FROM ".$tbl_wiki."
  2961. WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
  2962. $allpages = Database::query($sql);
  2963. while ($row = Database::fetch_array($allpages)) {
  2964. $total_versions = $row['TOTAL_VERS'];
  2965. $total_visits = intval($row['TOTAL_VISITS']);
  2966. }
  2967. $sql = "SELECT * FROM ".$tbl_wiki."
  2968. WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
  2969. $allpages = Database::query($sql);
  2970. while ($row = Database::fetch_array($allpages)) {
  2971. $total_words = $total_words + self::word_count($row['content']);
  2972. $total_links = $total_links + substr_count(
  2973. $row['content'],
  2974. "href="
  2975. );
  2976. $total_links_anchors = $total_links_anchors + substr_count(
  2977. $row['content'],
  2978. 'href="#'
  2979. );
  2980. $total_links_mail = $total_links_mail + substr_count(
  2981. $row['content'],
  2982. 'href="mailto'
  2983. );
  2984. $total_links_ftp = $total_links_ftp + substr_count(
  2985. $row['content'],
  2986. 'href="ftp'
  2987. );
  2988. $total_links_irc = $total_links_irc + substr_count(
  2989. $row['content'],
  2990. 'href="irc'
  2991. );
  2992. $total_links_news = $total_links_news + substr_count(
  2993. $row['content'],
  2994. 'href="news'
  2995. );
  2996. $total_wlinks = $total_wlinks + substr_count($row['content'], "[[");
  2997. $total_images = $total_images + substr_count(
  2998. $row['content'],
  2999. "<img"
  3000. );
  3001. $clean_total_flash = preg_replace(
  3002. '/player.swf/',
  3003. ' ',
  3004. $row['content']
  3005. );
  3006. $total_flash = $total_flash + substr_count(
  3007. $clean_total_flash,
  3008. '.swf"'
  3009. );
  3010. //.swf" end quotes prevent insert swf through flvplayer (is not counted)
  3011. $total_mp3 = $total_mp3 + substr_count($row['content'], ".mp3");
  3012. $total_flv_p = $total_flv_p + substr_count($row['content'], ".flv");
  3013. $total_flv = $total_flv_p / 5;
  3014. $total_youtube = $total_youtube + substr_count(
  3015. $row['content'],
  3016. "http://www.youtube.com"
  3017. );
  3018. $total_multimedia = $total_multimedia + substr_count(
  3019. $row['content'],
  3020. "video/x-msvideo"
  3021. );
  3022. $total_tables = $total_tables + substr_count(
  3023. $row['content'],
  3024. "<table"
  3025. );
  3026. }
  3027. // Check only last version of all pages (current page)
  3028. $sql = ' SELECT *, COUNT(*) AS TOTAL_PAGES, SUM(hits) AS TOTAL_VISITS_LV
  3029. FROM '.$tbl_wiki.' s1
  3030. WHERE s1.c_id = '.$course_id.' AND id=(
  3031. SELECT MAX(s2.id)
  3032. FROM '.$tbl_wiki.' s2
  3033. WHERE
  3034. s2.c_id = '.$course_id.' AND
  3035. s1.reflink = s2.reflink AND
  3036. '.$groupfilter.' AND
  3037. session_id='.$session_id.')';
  3038. $allpages = Database::query($sql);
  3039. while ($row = Database::fetch_array($allpages)) {
  3040. $total_pages = $row['TOTAL_PAGES'];
  3041. $total_visits_lv = intval($row['TOTAL_VISITS_LV']);
  3042. }
  3043. $total_words_lv = 0;
  3044. $total_links_lv = 0;
  3045. $total_links_anchors_lv = 0;
  3046. $total_links_mail_lv = 0;
  3047. $total_links_ftp_lv = 0;
  3048. $total_links_irc_lv = 0;
  3049. $total_links_news_lv = 0;
  3050. $total_wlinks_lv = 0;
  3051. $total_images_lv = 0;
  3052. $clean_total_flash_lv = 0;
  3053. $total_flash_lv = 0;
  3054. $total_mp3_lv = 0;
  3055. $total_flv_p_lv = 0;
  3056. $total_flv_lv = 0;
  3057. $total_youtube_lv = 0;
  3058. $total_multimedia_lv = 0;
  3059. $total_tables_lv = 0;
  3060. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  3061. WHERE s1.c_id = '.$course_id.' AND id=(
  3062. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  3063. WHERE
  3064. s2.c_id = '.$course_id.' AND
  3065. s1.reflink = s2.reflink AND
  3066. '.$groupfilter.' AND
  3067. session_id='.$session_id.'
  3068. )';
  3069. $allpages = Database::query($sql);
  3070. while ($row = Database::fetch_array($allpages)) {
  3071. $total_words_lv = $total_words_lv + self::word_count(
  3072. $row['content']
  3073. );
  3074. $total_links_lv = $total_links_lv + substr_count(
  3075. $row['content'],
  3076. "href="
  3077. );
  3078. $total_links_anchors_lv = $total_links_anchors_lv + substr_count(
  3079. $row['content'],
  3080. 'href="#'
  3081. );
  3082. $total_links_mail_lv = $total_links_mail_lv + substr_count(
  3083. $row['content'],
  3084. 'href="mailto'
  3085. );
  3086. $total_links_ftp_lv = $total_links_ftp_lv + substr_count(
  3087. $row['content'],
  3088. 'href="ftp'
  3089. );
  3090. $total_links_irc_lv = $total_links_irc_lv + substr_count(
  3091. $row['content'],
  3092. 'href="irc'
  3093. );
  3094. $total_links_news_lv = $total_links_news_lv + substr_count(
  3095. $row['content'],
  3096. 'href="news'
  3097. );
  3098. $total_wlinks_lv = $total_wlinks_lv + substr_count(
  3099. $row['content'],
  3100. "[["
  3101. );
  3102. $total_images_lv = $total_images_lv + substr_count(
  3103. $row['content'],
  3104. "<img"
  3105. );
  3106. $clean_total_flash_lv = preg_replace(
  3107. '/player.swf/',
  3108. ' ',
  3109. $row['content']
  3110. );
  3111. $total_flash_lv = $total_flash_lv + substr_count(
  3112. $clean_total_flash_lv,
  3113. '.swf"'
  3114. );
  3115. //.swf" end quotes prevent insert swf through flvplayer (is not counted)
  3116. $total_mp3_lv = $total_mp3_lv + substr_count(
  3117. $row['content'],
  3118. ".mp3"
  3119. );
  3120. $total_flv_p_lv = $total_flv_p_lv + substr_count(
  3121. $row['content'],
  3122. ".flv"
  3123. );
  3124. $total_flv_lv = $total_flv_p_lv / 5;
  3125. $total_youtube_lv = $total_youtube_lv + substr_count(
  3126. $row['content'],
  3127. "http://www.youtube.com"
  3128. );
  3129. $total_multimedia_lv = $total_multimedia_lv + substr_count(
  3130. $row['content'],
  3131. "video/x-msvideo"
  3132. );
  3133. $total_tables_lv = $total_tables_lv + substr_count(
  3134. $row['content'],
  3135. "<table"
  3136. );
  3137. }
  3138. //Total pages edited at this time
  3139. $total_editing_now = 0;
  3140. $sql = 'SELECT *, COUNT(*) AS TOTAL_EDITING_NOW
  3141. FROM '.$tbl_wiki.' s1
  3142. WHERE is_editing!=0 AND s1.c_id = '.$course_id.' AND
  3143. id=(
  3144. SELECT MAX(s2.id)
  3145. FROM '.$tbl_wiki.' s2
  3146. WHERE
  3147. s2.c_id = '.$course_id.' AND
  3148. s1.reflink = s2.reflink AND
  3149. '.$groupfilter.' AND
  3150. session_id='.$session_id.'
  3151. )';
  3152. // Can not use group by because the mark is set in the latest version
  3153. $allpages = Database::query($sql);
  3154. while ($row = Database::fetch_array($allpages)) {
  3155. $total_editing_now = $row['TOTAL_EDITING_NOW'];
  3156. }
  3157. // Total hidden pages
  3158. $total_hidden = 0;
  3159. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3160. WHERE
  3161. c_id = '.$course_id.' AND
  3162. visibility = 0 AND
  3163. '.$groupfilter.$condition_session.'
  3164. GROUP BY reflink';
  3165. // or group by page_id. As the mark of hidden places it in all
  3166. // versions of the page, I can use group by to see the first
  3167. $allpages = Database::query($sql);
  3168. while ($row = Database::fetch_array($allpages)) {
  3169. $total_hidden = $total_hidden + 1;
  3170. }
  3171. //Total protect pages
  3172. $total_protected = 0;
  3173. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3174. WHERE
  3175. c_id = '.$course_id.' AND
  3176. editlock = 1 AND
  3177. '.$groupfilter.$condition_session.'
  3178. GROUP BY reflink';
  3179. // or group by page_id. As the mark of protected page is the
  3180. // first version of the page, I can use group by
  3181. $allpages = Database::query($sql);
  3182. while ($row = Database::fetch_array($allpages)) {
  3183. $total_protected = $total_protected + 1;
  3184. }
  3185. // Total empty versions.
  3186. $total_empty_content = 0;
  3187. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3188. WHERE
  3189. c_id = '.$course_id.' AND
  3190. content="" AND
  3191. '.$groupfilter.$condition_session.'';
  3192. $allpages = Database::query($sql);
  3193. while ($row = Database::fetch_array($allpages)) {
  3194. $total_empty_content = $total_empty_content + 1;
  3195. }
  3196. //Total empty pages (last version)
  3197. $total_empty_content_lv = 0;
  3198. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  3199. WHERE s1.c_id = '.$course_id.' AND content="" AND id=(
  3200. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  3201. WHERE
  3202. s1.c_id = '.$course_id.' AND
  3203. s1.reflink = s2.reflink AND
  3204. '.$groupfilter.' AND
  3205. session_id='.$session_id.'
  3206. )';
  3207. $allpages = Database::query($sql);
  3208. while ($row = Database::fetch_array($allpages)) {
  3209. $total_empty_content_lv = $total_empty_content_lv + 1;
  3210. }
  3211. // Total locked discuss pages
  3212. $total_lock_disc = 0;
  3213. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3214. WHERE c_id = '.$course_id.' AND addlock_disc=0 AND '.$groupfilter.$condition_session.'
  3215. GROUP BY reflink';//group by because mark lock in all vers, then always is ok
  3216. $allpages = Database::query($sql);
  3217. while ($row = Database::fetch_array($allpages)) {
  3218. $total_lock_disc = $total_lock_disc + 1;
  3219. }
  3220. // Total hidden discuss pages.
  3221. $total_hidden_disc = 0;
  3222. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3223. WHERE c_id = '.$course_id.' AND visibility_disc=0 AND '.$groupfilter.$condition_session.'
  3224. GROUP BY reflink';
  3225. //group by because mark lock in all vers, then always is ok
  3226. $allpages = Database::query($sql);
  3227. while ($row = Database::fetch_array($allpages)) {
  3228. $total_hidden_disc = $total_hidden_disc + 1;
  3229. }
  3230. // Total versions with any short comment by user or system
  3231. $total_comment_version = 0;
  3232. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3233. WHERE c_id = '.$course_id.' AND comment!="" AND '.$groupfilter.$condition_session.'';
  3234. $allpages = Database::query($sql);
  3235. while ($row = Database::fetch_array($allpages)) {
  3236. $total_comment_version = $total_comment_version + 1;
  3237. }
  3238. // Total pages that can only be scored by teachers.
  3239. $total_only_teachers_rating = 0;
  3240. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3241. WHERE c_id = '.$course_id.' AND
  3242. ratinglock_disc = 0 AND
  3243. '.$groupfilter.$condition_session.'
  3244. GROUP BY reflink';//group by because mark lock in all vers, then always is ok
  3245. $allpages = Database::query($sql);
  3246. while ($row = Database::fetch_array($allpages)) {
  3247. $total_only_teachers_rating = $total_only_teachers_rating + 1;
  3248. }
  3249. // Total pages scored by peers
  3250. // put always this line alfter check num all pages and num pages rated by teachers
  3251. $total_rating_by_peers = $total_pages - $total_only_teachers_rating;
  3252. //Total pages identified as standard task
  3253. $total_task = 0;
  3254. $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
  3255. WHERE '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND
  3256. '.$tbl_wiki_conf.'.task!="" AND
  3257. '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
  3258. '.$tbl_wiki.'.'.$groupfilter.$condition_session;
  3259. $allpages = Database::query($sql);
  3260. while ($row = Database::fetch_array($allpages)) {
  3261. $total_task = $total_task + 1;
  3262. }
  3263. //Total pages identified as teacher page (wiki portfolio mode - individual assignment)
  3264. $total_teacher_assignment = 0;
  3265. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  3266. WHERE s1.c_id = '.$course_id.' AND assignment=1 AND id=(
  3267. SELECT MAX(s2.id)
  3268. FROM '.$tbl_wiki.' s2
  3269. WHERE
  3270. s2.c_id = '.$course_id.' AND
  3271. s1.reflink = s2.reflink AND
  3272. '.$groupfilter.' AND
  3273. session_id='.$session_id.'
  3274. )';
  3275. //mark all versions, but do not use group by reflink because y want the pages not versions
  3276. $allpages = Database::query($sql);
  3277. while ($row = Database::fetch_array($allpages)) {
  3278. $total_teacher_assignment = $total_teacher_assignment + 1;
  3279. }
  3280. //Total pages identifies as student page (wiki portfolio mode - individual assignment)
  3281. $total_student_assignment = 0;
  3282. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  3283. WHERE s1.c_id = '.$course_id.' AND assignment=2 AND
  3284. id = (SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  3285. WHERE
  3286. s2.c_id = '.$course_id.' AND
  3287. s1.reflink = s2.reflink AND
  3288. '.$groupfilter.' AND
  3289. session_id='.$session_id.'
  3290. )';
  3291. //mark all versions, but do not use group by reflink because y want the pages not versions
  3292. $allpages = Database::query($sql);
  3293. while ($row = Database::fetch_array($allpages)) {
  3294. $total_student_assignment = $total_student_assignment + 1;
  3295. }
  3296. //Current Wiki status add new pages
  3297. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3298. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3299. GROUP BY addlock';//group by because mark 0 in all vers, then always is ok
  3300. $allpages = Database::query($sql);
  3301. $wiki_add_lock = null;
  3302. while ($row = Database::fetch_array($allpages)) {
  3303. $wiki_add_lock = $row['addlock'];
  3304. }
  3305. if ($wiki_add_lock == 1) {
  3306. $status_add_new_pag = get_lang('Yes');
  3307. } else {
  3308. $status_add_new_pag = get_lang('No');
  3309. }
  3310. // Creation date of the oldest wiki page and version
  3311. $first_wiki_date = null;
  3312. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3313. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3314. ORDER BY dtime ASC
  3315. LIMIT 1';
  3316. $allpages = Database::query($sql);
  3317. while ($row = Database::fetch_array($allpages)) {
  3318. $first_wiki_date = api_get_local_time($row['dtime']);
  3319. }
  3320. // Date of publication of the latest wiki version.
  3321. $last_wiki_date = null;
  3322. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3323. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3324. ORDER BY dtime DESC
  3325. LIMIT 1';
  3326. $allpages = Database::query($sql);
  3327. while ($row = Database::fetch_array($allpages)) {
  3328. $last_wiki_date = api_get_local_time($row['dtime']);
  3329. }
  3330. // Average score of all wiki pages. (If a page has not scored zero rated)
  3331. $media_score = 0;
  3332. $sql = "SELECT *, SUM(score) AS TOTAL_SCORE FROM ".$tbl_wiki."
  3333. WHERE c_id = $course_id AND ".$groupfilter.$condition_session."
  3334. GROUP BY reflink ";
  3335. //group by because mark in all versions, then always is ok.
  3336. // Do not use "count" because using "group by", would give a wrong value
  3337. $allpages = Database::query($sql);
  3338. $total_score = 0;
  3339. while ($row = Database::fetch_array($allpages)) {
  3340. $total_score = $total_score + $row['TOTAL_SCORE'];
  3341. }
  3342. if (!empty($total_pages)) {
  3343. $media_score = $total_score / $total_pages;
  3344. //put always this line alfter check num all pages
  3345. }
  3346. // Average user progress in his pages.
  3347. $media_progress = 0;
  3348. $sql = 'SELECT *, SUM(progress) AS TOTAL_PROGRESS
  3349. FROM '.$tbl_wiki.' s1
  3350. WHERE s1.c_id = '.$course_id.' AND id=
  3351. (
  3352. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  3353. WHERE
  3354. s2.c_id = '.$course_id.' AND
  3355. s1.reflink = s2.reflink AND
  3356. '.$groupfilter.' AND
  3357. session_id='.$session_id.'
  3358. )';
  3359. // As the value is only the latest version I can not use group by
  3360. $allpages = Database::query($sql);
  3361. while ($row = Database::fetch_array($allpages)) {
  3362. $total_progress = $row['TOTAL_PROGRESS'];
  3363. }
  3364. if (!empty($total_pages)) {
  3365. $media_progress = $total_progress / $total_pages;
  3366. //put always this line alfter check num all pages
  3367. }
  3368. // Total users that have participated in the Wiki
  3369. $total_users = 0;
  3370. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3371. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3372. GROUP BY user_id';
  3373. //as the mark of user it in all versions of the page, I can use group by to see the first
  3374. $allpages = Database::query($sql);
  3375. while ($row = Database::fetch_array($allpages)) {
  3376. $total_users = $total_users + 1;
  3377. }
  3378. // Total of different IP addresses that have participated in the wiki
  3379. $total_ip = 0;
  3380. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3381. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3382. GROUP BY user_ip';
  3383. $allpages = Database::query($sql);
  3384. while ($row = Database::fetch_array($allpages)) {
  3385. $total_ip = $total_ip + 1;
  3386. }
  3387. echo '<table class="data_table">';
  3388. echo '<thead>';
  3389. echo '<tr>';
  3390. echo '<th colspan="2">'.get_lang('General').'</th>';
  3391. echo '</tr>';
  3392. echo '</thead>';
  3393. echo '<tr>';
  3394. echo '<td>'.get_lang('StudentAddNewPages').'</td>';
  3395. echo '<td>'.$status_add_new_pag.'</td>';
  3396. echo '</tr>';
  3397. echo '<tr>';
  3398. echo '<td>'.get_lang('DateCreateOldestWikiPage').'</td>';
  3399. echo '<td>'.$first_wiki_date.'</td>';
  3400. echo '</tr>';
  3401. echo '<tr>';
  3402. echo '<td>'.get_lang('DateEditLatestWikiVersion').'</td>';
  3403. echo '<td>'.$last_wiki_date.'</td>';
  3404. echo '</tr>';
  3405. echo '<tr>';
  3406. echo '<td>'.get_lang('AverageScoreAllPages').'</td>';
  3407. echo '<td>'.$media_score.' %</td>';
  3408. echo '</tr>';
  3409. echo '<tr>';
  3410. echo '<td>'.get_lang('AverageMediaUserProgress').'</td>';
  3411. echo '<td>'.$media_progress.' %</td>';
  3412. echo '</tr>';
  3413. echo '<tr>';
  3414. echo '<td>'.get_lang('TotalWikiUsers').'</td>';
  3415. echo '<td>'.$total_users.'</td>';
  3416. echo '</tr>';
  3417. echo '<tr>';
  3418. echo '<td>'.get_lang('TotalIpAdress').'</td>';
  3419. echo '<td>'.$total_ip.'</td>';
  3420. echo '</tr>';
  3421. echo '</table>';
  3422. echo '<br/>';
  3423. echo '<table class="data_table">';
  3424. echo '<thead>';
  3425. echo '<tr>';
  3426. echo '<th colspan="2">'.get_lang('Pages').' '.get_lang(
  3427. 'And'
  3428. ).' '.get_lang('Versions').'</th>';
  3429. echo '</tr>';
  3430. echo '</thead>';
  3431. echo '<tr>';
  3432. echo '<td>'.get_lang('Pages').' - '.get_lang(
  3433. 'NumContributions'
  3434. ).'</td>';
  3435. echo '<td>'.$total_pages.' ('.get_lang(
  3436. 'Versions'
  3437. ).': '.$total_versions.')</td>';
  3438. echo '</tr>';
  3439. echo '<tr>';
  3440. echo '<td>'.get_lang('EmptyPages').'</td>';
  3441. echo '<td>'.$total_empty_content_lv.' ('.get_lang(
  3442. 'Versions'
  3443. ).': '.$total_empty_content.')</td>';
  3444. echo '</tr>';
  3445. echo '<tr>';
  3446. echo '<td>'.get_lang('NumAccess').'</td>';
  3447. echo '<td>'.$total_visits_lv.' ('.get_lang(
  3448. 'Versions'
  3449. ).': '.$total_visits.')</td>';
  3450. echo '</tr>';
  3451. echo '<tr>';
  3452. echo '<td>'.get_lang('TotalPagesEditedAtThisTime').'</td>';
  3453. echo '<td>'.$total_editing_now.'</td>';
  3454. echo '</tr>';
  3455. echo '<tr>';
  3456. echo '<td>'.get_lang('TotalHiddenPages').'</td>';
  3457. echo '<td>'.$total_hidden.'</td>';
  3458. echo '</tr>';
  3459. echo '<tr>';
  3460. echo '<td>'.get_lang('NumProtectedPages').'</td>';
  3461. echo '<td>'.$total_protected.'</td>';
  3462. echo '</tr>';
  3463. echo '<tr>';
  3464. echo '<td>'.get_lang('LockedDiscussPages').'</td>';
  3465. echo '<td>'.$total_lock_disc.'</td>';
  3466. echo '</tr>';
  3467. echo '<tr>';
  3468. echo '<td>'.get_lang('HiddenDiscussPages').'</td>';
  3469. echo '<td>'.$total_hidden_disc.'</td>';
  3470. echo '</tr>';
  3471. echo '<tr>';
  3472. echo '<td>'.get_lang('TotalComments').'</td>';
  3473. echo '<td>'.$total_comment_version.'</td>';
  3474. echo '</tr>';
  3475. echo '<tr>';
  3476. echo '<td>'.get_lang('TotalOnlyRatingByTeacher').'</td>';
  3477. echo '<td>'.$total_only_teachers_rating.'</td>';
  3478. echo '</tr>';
  3479. echo '<tr>';
  3480. echo '<td>'.get_lang('TotalRatingPeers').'</td>';
  3481. echo '<td>'.$total_rating_by_peers.'</td>';
  3482. echo '</tr>';
  3483. echo '<tr>';
  3484. echo '<td>'.get_lang('TotalTeacherAssignments').' - '.get_lang(
  3485. 'PortfolioMode'
  3486. ).'</td>';
  3487. echo '<td>'.$total_teacher_assignment.'</td>';
  3488. echo '</tr>';
  3489. echo '<tr>';
  3490. echo '<td>'.get_lang('TotalStudentAssignments').' - '.get_lang(
  3491. 'PortfolioMode'
  3492. ).'</td>';
  3493. echo '<td>'.$total_student_assignment.'</td>';
  3494. echo '</tr>';
  3495. echo '<tr>';
  3496. echo '<td>'.get_lang('TotalTask').' - '.get_lang(
  3497. 'StandardMode'
  3498. ).'</td>';
  3499. echo '<td>'.$total_task.'</td>';
  3500. echo '</tr>';
  3501. echo '</table>';
  3502. echo '<br/>';
  3503. echo '<table class="data_table">';
  3504. echo '<thead>';
  3505. echo '<tr>';
  3506. echo '<th colspan="3">'.get_lang('ContentPagesInfo').'</th>';
  3507. echo '</tr>';
  3508. echo '<tr>';
  3509. echo '<td></td>';
  3510. echo '<td>'.get_lang('InTheLastVersion').'</td>';
  3511. echo '<td>'.get_lang('InAllVersions').'</td>';
  3512. echo '</tr>';
  3513. echo '</thead>';
  3514. echo '<tr>';
  3515. echo '<td>'.get_lang('NumWords').'</td>';
  3516. echo '<td>'.$total_words_lv.'</td>';
  3517. echo '<td>'.$total_words.'</td>';
  3518. echo '</tr>';
  3519. echo '<tr>';
  3520. echo '<td>'.get_lang('NumlinksHtmlImagMedia').'</td>';
  3521. echo '<td>'.$total_links_lv.' ('.get_lang(
  3522. 'Anchors'
  3523. ).':'.$total_links_anchors_lv.', Mail:'.$total_links_mail_lv.', FTP:'.$total_links_ftp_lv.' IRC:'.$total_links_irc_lv.', News:'.$total_links_news_lv.', ... ) </td>';
  3524. echo '<td>'.$total_links.' ('.get_lang(
  3525. 'Anchors'
  3526. ).':'.$total_links_anchors.', Mail:'.$total_links_mail.', FTP:'.$total_links_ftp.', IRC:'.$total_links_irc.', News:'.$total_links_news.', ... ) </td>';
  3527. echo '</tr>';
  3528. echo '<tr>';
  3529. echo '<td>'.get_lang('NumWikilinks').'</td>';
  3530. echo '<td>'.$total_wlinks_lv.'</td>';
  3531. echo '<td>'.$total_wlinks.'</td>';
  3532. echo '</tr>';
  3533. echo '<tr>';
  3534. echo '<td>'.get_lang('NumImages').'</td>';
  3535. echo '<td>'.$total_images_lv.'</td>';
  3536. echo '<td>'.$total_images.'</td>';
  3537. echo '</tr>';
  3538. echo '<tr>';
  3539. echo '<td>'.get_lang('NumFlash').'</td>';
  3540. echo '<td>'.$total_flash_lv.'</td>';
  3541. echo '<td>'.$total_flash.'</td>';
  3542. echo '</tr>';
  3543. echo '<tr>';
  3544. echo '<td>'.get_lang('NumMp3').'</td>';
  3545. echo '<td>'.$total_mp3_lv.'</td>';
  3546. echo '<td>'.$total_mp3.'</td>';
  3547. echo '</tr>';
  3548. echo '<tr>';
  3549. echo '<td>'.get_lang('NumFlvVideo').'</td>';
  3550. echo '<td>'.$total_flv_lv.'</td>';
  3551. echo '<td>'.$total_flv.'</td>';
  3552. echo '</tr>';
  3553. echo '<tr>';
  3554. echo '<td>'.get_lang('NumYoutubeVideo').'</td>';
  3555. echo '<td>'.$total_youtube_lv.'</td>';
  3556. echo '<td>'.$total_youtube.'</td>';
  3557. echo '</tr>';
  3558. echo '<tr>';
  3559. echo '<td>'.get_lang('NumOtherAudioVideo').'</td>';
  3560. echo '<td>'.$total_multimedia_lv.'</td>';
  3561. echo '<td>'.$total_multimedia.'</td>';
  3562. echo '</tr>';
  3563. echo '<tr>';
  3564. echo '<td>'.get_lang('NumTables').'</td>';
  3565. echo '<td>'.$total_tables_lv.'</td>';
  3566. echo '<td>'.$total_tables.'</td>';
  3567. echo '</tr>';
  3568. echo '</table>';
  3569. }
  3570. /**
  3571. * @param string $action
  3572. */
  3573. public function getActiveUsers($action)
  3574. {
  3575. $tbl_wiki = $this->tbl_wiki;
  3576. $course_id = $this->course_id;
  3577. $condition_session = $this->condition_session;
  3578. $groupfilter = $this->groupfilter;
  3579. $_course = $this->courseInfo;
  3580. echo '<div class="actions">'.get_lang('MostActiveUsers').'</div>';
  3581. $sql = 'SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.'
  3582. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  3583. GROUP BY user_id';
  3584. $allpages = Database::query($sql);
  3585. //show table
  3586. if (Database::num_rows($allpages) > 0) {
  3587. while ($obj = Database::fetch_object($allpages)) {
  3588. $userinfo = api_get_user_info($obj->user_id);
  3589. $row = [];
  3590. if ($obj->user_id != 0 && $userinfo !== false) {
  3591. $row[] = UserManager::getUserProfileLink($userinfo).'
  3592. <a href="'.api_get_self(
  3593. ).'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode(
  3594. $obj->user_id
  3595. ).
  3596. '&session_id='.api_htmlentities(
  3597. $_GET['session_id']
  3598. ).'&group_id='.api_htmlentities(
  3599. $_GET['group_id']
  3600. ).'"></a>';
  3601. } else {
  3602. $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
  3603. }
  3604. $row[] = '<a href="'.api_get_self(
  3605. ).'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode(
  3606. $obj->user_id
  3607. ).'&session_id='.api_htmlentities(
  3608. $_GET['session_id']
  3609. ).'&group_id='.api_htmlentities(
  3610. $_GET['group_id']
  3611. ).'">'.$obj->NUM_EDIT.'</a>';
  3612. $rows[] = $row;
  3613. }
  3614. $table = new SortableTableFromArrayConfig(
  3615. $rows,
  3616. 1,
  3617. 10,
  3618. 'MostActiveUsersA_table',
  3619. '',
  3620. '',
  3621. 'DESC'
  3622. );
  3623. $table->set_additional_parameters(
  3624. [
  3625. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  3626. 'action' => Security::remove_XSS($action),
  3627. 'session_id' => Security::remove_XSS($_GET['session_id']),
  3628. 'group_id' => Security::remove_XSS($_GET['group_id'])
  3629. ]
  3630. );
  3631. $table->set_header(0, get_lang('Author'), true);
  3632. $table->set_header(
  3633. 1,
  3634. get_lang('Contributions'),
  3635. true,
  3636. ['style' => 'width:30px;']
  3637. );
  3638. $table->display();
  3639. }
  3640. }
  3641. /**
  3642. * @param string $page
  3643. */
  3644. public function getDiscuss($page)
  3645. {
  3646. $tbl_wiki = $this->tbl_wiki;
  3647. $course_id = $this->course_id;
  3648. $condition_session = $this->condition_session;
  3649. $groupfilter = $this->groupfilter;
  3650. $tbl_wiki_discuss = $this->tbl_wiki_discuss;
  3651. if (api_get_session_id() != 0 &&
  3652. api_is_allowed_to_session_edit(false, true) == false
  3653. ) {
  3654. api_not_allowed();
  3655. }
  3656. if (!$_GET['title']) {
  3657. Display::addFlash(
  3658. Display::return_message(
  3659. get_lang("MustSelectPage"),
  3660. 'error',
  3661. false
  3662. )
  3663. );
  3664. return;
  3665. }
  3666. // First extract the date of last version
  3667. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3668. WHERE
  3669. c_id = '.$course_id.' AND
  3670. reflink = "'.Database::escape_string($page).'" AND
  3671. '.$groupfilter.$condition_session.'
  3672. ORDER BY id DESC';
  3673. $result = Database::query($sql);
  3674. $row = Database::fetch_array($result);
  3675. $lastversiondate = api_get_local_time($row['dtime']);
  3676. $lastuserinfo = api_get_user_info($row['user_id']);
  3677. // Select page to discuss
  3678. $sql = 'SELECT * FROM '.$tbl_wiki.'
  3679. WHERE
  3680. c_id = '.$course_id.' AND
  3681. reflink="'.Database::escape_string($page).'" AND
  3682. '.$groupfilter.$condition_session.'
  3683. ORDER BY id ASC';
  3684. $result = Database::query($sql);
  3685. $row = Database::fetch_array($result);
  3686. $id = $row['id'];
  3687. $firstuserid = $row['user_id'];
  3688. if (isset($_POST['Submit']) && self::double_post($_POST['wpost_id'])) {
  3689. $dtime = api_get_utc_datetime();
  3690. $message_author = api_get_user_id();
  3691. $params = [
  3692. 'c_id' => $course_id,
  3693. 'publication_id' => $id,
  3694. 'userc_id' => $message_author,
  3695. 'comment' => $_POST['comment'],
  3696. 'p_score' => $_POST['rating'],
  3697. 'dtime' => $dtime
  3698. ];
  3699. $discussId = Database::insert($tbl_wiki_discuss, $params);
  3700. if ($discussId) {
  3701. $sql = "UPDATE $tbl_wiki_discuss SET id = iid WHERE iid = $discussId";
  3702. Database::query($sql);
  3703. }
  3704. self::check_emailcue($id, 'D', $dtime, $message_author);
  3705. header(
  3706. 'Location: index.php?action=discuss&title='.api_htmlentities(urlencode($page)).'&'.api_get_cidreq()
  3707. );
  3708. exit;
  3709. }
  3710. // mode assignment: previous to show page type
  3711. $icon_assignment = null;
  3712. if ($row['assignment'] == 1) {
  3713. $icon_assignment = Display::return_icon(
  3714. 'wiki_assignment.png',
  3715. get_lang('AssignmentDescExtra'),
  3716. '',
  3717. ICON_SIZE_SMALL
  3718. );
  3719. } elseif ($row['assignment'] == 2) {
  3720. $icon_assignment = Display::return_icon(
  3721. 'wiki_work.png',
  3722. get_lang('AssignmentWorkExtra'),
  3723. '',
  3724. ICON_SIZE_SMALL
  3725. );
  3726. }
  3727. $countWPost = null;
  3728. $avg_WPost_score = null;
  3729. // Show title and form to discuss if page exist
  3730. if ($id != '') {
  3731. // Show discussion to students if isn't hidden.
  3732. // Show page to all teachers if is hidden.
  3733. // Mode assignments: If is hidden, show pages to student only if student is the author
  3734. if ($row['visibility_disc'] == 1 ||
  3735. api_is_allowed_to_edit(false, true) ||
  3736. api_is_platform_admin() ||
  3737. ($row['assignment'] == 2 && $row['visibility_disc'] == 0 && (api_get_user_id() == $row['user_id']))
  3738. ) {
  3739. echo '<div id="wikititle">';
  3740. // discussion action: protecting (locking) the discussion
  3741. $addlock_disc = null;
  3742. $lock_unlock_disc = null;
  3743. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  3744. if (self::check_addlock_discuss() == 1) {
  3745. $addlock_disc = Display::return_icon(
  3746. 'unlock.png',
  3747. get_lang('UnlockDiscussExtra'),
  3748. '',
  3749. ICON_SIZE_SMALL
  3750. );
  3751. $lock_unlock_disc = 'unlockdisc';
  3752. } else {
  3753. $addlock_disc = Display::return_icon(
  3754. 'lock.png',
  3755. get_lang('LockDiscussExtra'),
  3756. '',
  3757. ICON_SIZE_SMALL
  3758. );
  3759. $lock_unlock_disc = 'lockdisc';
  3760. }
  3761. }
  3762. echo '<span style="float:right">';
  3763. echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_disc.'&title='.api_htmlentities(
  3764. urlencode($page)
  3765. ).'">'.$addlock_disc.'</a>';
  3766. echo '</span>';
  3767. // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
  3768. $visibility_disc = null;
  3769. $hide_show_disc = null;
  3770. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  3771. if (self::check_visibility_discuss() == 1) {
  3772. /// TODO: Fix Mode assignments: If is hidden, show discussion to student only if student is the author
  3773. $visibility_disc = Display::return_icon(
  3774. 'visible.png',
  3775. get_lang('ShowDiscussExtra'),
  3776. '',
  3777. ICON_SIZE_SMALL
  3778. );
  3779. $hide_show_disc = 'hidedisc';
  3780. } else {
  3781. $visibility_disc = Display::return_icon(
  3782. 'invisible.png',
  3783. get_lang('HideDiscussExtra'),
  3784. '',
  3785. ICON_SIZE_SMALL
  3786. );
  3787. $hide_show_disc = 'showdisc';
  3788. }
  3789. }
  3790. echo '<span style="float:right">';
  3791. echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$hide_show_disc.'&title='.api_htmlentities(
  3792. urlencode($page)
  3793. ).'">'.$visibility_disc.'</a>';
  3794. echo '</span>';
  3795. // discussion action: check add rating lock. Show/Hide list to rating for all student
  3796. $lock_unlock_rating_disc = null;
  3797. $ratinglock_disc = null;
  3798. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  3799. if (self::check_ratinglock_discuss() == 1) {
  3800. $ratinglock_disc = Display::return_icon(
  3801. 'star.png',
  3802. get_lang('UnlockRatingDiscussExtra'),
  3803. '',
  3804. ICON_SIZE_SMALL
  3805. );
  3806. $lock_unlock_rating_disc = 'unlockrating';
  3807. } else {
  3808. $ratinglock_disc = Display::return_icon(
  3809. 'star_na.png',
  3810. get_lang('LockRatingDiscussExtra'),
  3811. '',
  3812. ICON_SIZE_SMALL
  3813. );
  3814. $lock_unlock_rating_disc = 'lockrating';
  3815. }
  3816. }
  3817. echo '<span style="float:right">';
  3818. echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_rating_disc.'&title='.api_htmlentities(
  3819. urlencode($page)
  3820. ).'">'.$ratinglock_disc.'</a>';
  3821. echo '</span>';
  3822. // discussion action: email notification
  3823. if (self::check_notify_discuss($page) == 1) {
  3824. $notify_disc = Display::return_icon(
  3825. 'messagebox_info.png',
  3826. get_lang('NotifyDiscussByEmail'),
  3827. '',
  3828. ICON_SIZE_SMALL
  3829. );
  3830. $lock_unlock_notify_disc = 'unlocknotifydisc';
  3831. } else {
  3832. $notify_disc = Display::return_icon(
  3833. 'mail.png',
  3834. get_lang('CancelNotifyDiscussByEmail'),
  3835. '',
  3836. ICON_SIZE_SMALL
  3837. );
  3838. $lock_unlock_notify_disc = 'locknotifydisc';
  3839. }
  3840. echo '<span style="float:right">';
  3841. echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_notify_disc.'&title='.api_htmlentities(
  3842. urlencode($page)
  3843. ).'">'.$notify_disc.'</a>';
  3844. echo '</span>';
  3845. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.api_htmlentities(
  3846. $row['title']
  3847. );
  3848. if ($lastuserinfo !== false) {
  3849. echo ' ('.get_lang('MostRecentVersionBy').' '.
  3850. UserManager::getUserProfileLink($lastuserinfo).' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read average score
  3851. }
  3852. echo '</div>';
  3853. if ($row['addlock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  3854. //show comments but students can't add theirs
  3855. ?>
  3856. <div class="panel panel-default">
  3857. <div class="panel-body">
  3858. <form name="form1" method="post" action=""
  3859. class="form-horizontal">
  3860. <div class="form-group">
  3861. <label
  3862. class="col-sm-2 control-label">
  3863. <?php echo get_lang('Comments'); ?>:</label>
  3864. <div class="col-sm-10">
  3865. <?php echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">'; //prevent double post?>
  3866. <textarea class="form-control"
  3867. name="comment" cols="80"
  3868. rows="5"
  3869. id="comment">
  3870. </textarea>
  3871. </div>
  3872. </div>
  3873. <div class="form-group">
  3874. <?php
  3875. //check if rating is allowed
  3876. if ($row['ratinglock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  3877. ?>
  3878. <label
  3879. class="col-sm-2 control-label"><?php echo get_lang('Rating'); ?>:</label>
  3880. <div class="col-sm-10">
  3881. <select name="rating" id="rating" class="selectpicker">
  3882. <option value="-" selected>-</option>
  3883. <option value="0">0</option>
  3884. <option value="1">1</option>
  3885. <option value="2">2</option>
  3886. <option value="3">3</option>
  3887. <option value="4">4</option>
  3888. <option value="5">5</option>
  3889. <option value="6">6</option>
  3890. <option value="7">7</option>
  3891. <option value="8">8</option>
  3892. <option value="9">9</option>
  3893. <option value="10">10</option>
  3894. </select>
  3895. </div>
  3896. <?php
  3897. } else {
  3898. echo '<input type=hidden name="rating" value="-">';
  3899. // must pass a default value to avoid rate automatically
  3900. } ?>
  3901. </div>
  3902. <div class="form-group">
  3903. <div class="col-sm-offset-2 col-sm-10">
  3904. <?php echo '<button class="btn btn-default" type="submit" name="Submit"> '.
  3905. get_lang('Send').'</button>'; ?>
  3906. </div>
  3907. </div>
  3908. </div>
  3909. </div>
  3910. </form>
  3911. <?php
  3912. }
  3913. // end discuss lock
  3914. echo '<hr noshade size="1">';
  3915. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  3916. $sql = "SELECT *
  3917. FROM $tbl_wiki_discuss reviews, $user_table user
  3918. WHERE
  3919. reviews.c_id = $course_id AND
  3920. reviews.publication_id='".$id."' AND
  3921. user.user_id='".$firstuserid."'
  3922. ORDER BY reviews.id DESC";
  3923. $result = Database::query($sql);
  3924. $countWPost = Database::num_rows($result);
  3925. echo get_lang('NumComments').": ".$countWPost; //comment's numbers
  3926. $sql = "SELECT SUM(p_score) as sumWPost
  3927. FROM $tbl_wiki_discuss
  3928. WHERE c_id = $course_id AND publication_id = '".$id."' AND NOT p_score='-'
  3929. ORDER BY id DESC";
  3930. $result2 = Database::query($sql);
  3931. $row2 = Database::fetch_array($result2);
  3932. $sql = "SELECT * FROM $tbl_wiki_discuss
  3933. WHERE c_id = $course_id AND publication_id='".$id."' AND NOT p_score='-'";
  3934. $result3 = Database::query($sql);
  3935. $countWPost_score = Database::num_rows($result3);
  3936. echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;
  3937. if ($countWPost_score != 0) {
  3938. $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score, 2).' / 10';
  3939. } else {
  3940. $avg_WPost_score = $countWPost_score;
  3941. }
  3942. echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
  3943. $sql = 'UPDATE '.$tbl_wiki.' SET
  3944. score = "'.Database::escape_string($avg_WPost_score).'"
  3945. WHERE
  3946. c_id = '.$course_id.' AND
  3947. reflink="'.Database::escape_string($page).'" AND
  3948. '.$groupfilter.$condition_session;
  3949. // check if work ok. TODO:
  3950. Database::query($sql);
  3951. echo '<hr noshade size="1">';
  3952. while ($row = Database::fetch_array($result)) {
  3953. $userinfo = api_get_user_info($row['userc_id']);
  3954. if (($userinfo['status']) == "5") {
  3955. $author_status = get_lang('Student');
  3956. } else {
  3957. $author_status = get_lang('Teacher');
  3958. }
  3959. $name = $userinfo['complete_name'];
  3960. $author_photo = '<img src="'.$userinfo['avatar'].'" alt="'.api_htmlentities($name).'" width="40" height="50" align="top" title="'.api_htmlentities($name).'" />';
  3961. // stars
  3962. $p_score = $row['p_score'];
  3963. switch ($p_score) {
  3964. case 0:
  3965. $imagerating = Display::return_icon(
  3966. 'rating/stars_0.gif'
  3967. );
  3968. break;
  3969. case 1:
  3970. $imagerating = Display::return_icon(
  3971. 'rating/stars_5.gif'
  3972. );
  3973. break;
  3974. case 2:
  3975. $imagerating = Display::return_icon(
  3976. 'rating/stars_10.gif'
  3977. );
  3978. break;
  3979. case 3:
  3980. $imagerating = Display::return_icon(
  3981. 'rating/stars_15.gif'
  3982. );
  3983. break;
  3984. case 4:
  3985. $imagerating = Display::return_icon(
  3986. 'rating/stars_20.gif'
  3987. );
  3988. break;
  3989. case 5:
  3990. $imagerating = Display::return_icon(
  3991. 'rating/stars_25.gif'
  3992. );
  3993. break;
  3994. case 6:
  3995. $imagerating = Display::return_icon(
  3996. 'rating/stars_30.gif'
  3997. );
  3998. break;
  3999. case 7:
  4000. $imagerating = Display::return_icon(
  4001. 'rating/stars_35.gif'
  4002. );
  4003. break;
  4004. case 8:
  4005. $imagerating = Display::return_icon(
  4006. 'rating/stars_40.gif'
  4007. );
  4008. break;
  4009. case 9:
  4010. $imagerating = Display::return_icon(
  4011. 'rating/stars_45.gif'
  4012. );
  4013. break;
  4014. case 10:
  4015. $imagerating = Display::return_icon(
  4016. 'rating/stars_50.gif'
  4017. );
  4018. break;
  4019. }
  4020. echo '<p><table>';
  4021. echo '<tr>';
  4022. echo '<td rowspan="2">'.$author_photo.'</td>';
  4023. $userProfile = '';
  4024. if ($userinfo !== false) {
  4025. $userProfile = UserManager::getUserProfileLink(
  4026. $userinfo
  4027. );
  4028. }
  4029. echo '<td style=" color:#999999">'.$userProfile.' ('.$author_status.') '.
  4030. api_get_local_time(
  4031. $row['dtime']
  4032. ).
  4033. ' - '.get_lang(
  4034. 'Rating'
  4035. ).': '.$row['p_score'].' '.$imagerating.' </td>';
  4036. echo '</tr>';
  4037. echo '<tr>';
  4038. echo '<td>'.api_htmlentities($row['comment']).'</td>';
  4039. echo '</tr>';
  4040. echo "</table>";
  4041. }
  4042. } else {
  4043. Display::addFlash(
  4044. Display::return_message(
  4045. get_lang('LockByTeacher'),
  4046. 'warning',
  4047. false
  4048. )
  4049. );
  4050. }
  4051. } else {
  4052. Display::addFlash(
  4053. Display::return_message(
  4054. get_lang('DiscussNotAvailable'),
  4055. 'normal',
  4056. false
  4057. )
  4058. );
  4059. }
  4060. }
  4061. /**
  4062. * Show all pages
  4063. */
  4064. public function allPages($action)
  4065. {
  4066. $tbl_wiki = $this->tbl_wiki;
  4067. $course_id = $this->course_id;
  4068. $session_id = $this->session_id;
  4069. $groupfilter = $this->groupfilter;
  4070. $_course = $this->courseInfo;
  4071. echo '<div class="actions">'.get_lang('AllPages');
  4072. // menu delete all wiki
  4073. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  4074. echo ' <a href="index.php?action=deletewiki&'.api_get_cidreq().'">'.
  4075. Display::return_icon(
  4076. 'delete.png',
  4077. get_lang('DeleteWiki'),
  4078. '',
  4079. ICON_SIZE_MEDIUM
  4080. ).'</a>';
  4081. }
  4082. echo '</div>';
  4083. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin(
  4084. )) { //only by professors if page is hidden
  4085. $sql = 'SELECT *
  4086. FROM '.$tbl_wiki.' s1
  4087. WHERE s1.c_id = '.$course_id.' AND id=(
  4088. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  4089. WHERE
  4090. s2.c_id = '.$course_id.' AND
  4091. s1.reflink = s2.reflink AND
  4092. '.$groupfilter.' AND
  4093. session_id='.$session_id.')';
  4094. // warning don't use group by reflink because does not return the last version
  4095. } else {
  4096. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  4097. WHERE visibility=1 AND s1.c_id = '.$course_id.' AND id=(
  4098. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  4099. WHERE
  4100. s2.c_id = '.$course_id.' AND
  4101. s1.reflink = s2.reflink AND
  4102. '.$groupfilter.' AND
  4103. session_id='.$session_id.')';
  4104. // warning don't use group by reflink because does not return the last version
  4105. }
  4106. $allpages = Database::query($sql);
  4107. //show table
  4108. if (Database::num_rows($allpages) > 0) {
  4109. while ($obj = Database::fetch_object($allpages)) {
  4110. //get author
  4111. $userinfo = api_get_user_info($obj->user_id);
  4112. $username = api_htmlentities(
  4113. sprintf(get_lang('LoginX'), $userinfo['username']),
  4114. ENT_QUOTES
  4115. );
  4116. //get type assignment icon
  4117. if ($obj->assignment == 1) {
  4118. $ShowAssignment = Display::return_icon(
  4119. 'wiki_assignment.png',
  4120. get_lang('AssignmentDesc'),
  4121. '',
  4122. ICON_SIZE_SMALL
  4123. );
  4124. } elseif ($obj->assignment == 2) {
  4125. $ShowAssignment = Display::return_icon(
  4126. 'wiki_work.png',
  4127. get_lang('AssignmentWork'),
  4128. '',
  4129. ICON_SIZE_SMALL
  4130. );
  4131. } elseif ($obj->assignment == 0) {
  4132. $ShowAssignment = Display::return_icon(
  4133. 'px_transparent.gif'
  4134. );
  4135. }
  4136. //get icon task
  4137. if (!empty($obj->task)) {
  4138. $icon_task = Display::return_icon(
  4139. 'wiki_task.png',
  4140. get_lang('StandardTask'),
  4141. '',
  4142. ICON_SIZE_SMALL
  4143. );
  4144. } else {
  4145. $icon_task = Display::return_icon('px_transparent.gif');
  4146. }
  4147. $row = [];
  4148. $row[] = $ShowAssignment.$icon_task;
  4149. $row[] = '<a href="'.api_get_self(
  4150. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  4151. urlencode($obj->reflink)
  4152. ).'&session_id='.api_htmlentities(
  4153. $_GET['session_id']
  4154. ).'&group_id='.api_htmlentities($_GET['group_id']).'">
  4155. '.api_htmlentities($obj->title).'</a>';
  4156. if ($userinfo !== false) {
  4157. $row[] = UserManager::getUserProfileLink($userinfo);
  4158. } else {
  4159. $row[] = get_lang('Anonymous').' ('.api_htmlentities(
  4160. $obj->user_ip
  4161. ).')';
  4162. }
  4163. $row[] = api_get_local_time(
  4164. $obj->dtime
  4165. );
  4166. $showdelete = '';
  4167. if (api_is_allowed_to_edit(
  4168. false,
  4169. true
  4170. ) || api_is_platform_admin()) {
  4171. $showdelete = ' <a href="'.api_get_self(
  4172. ).'?cidReq='.$_course['code'].'&action=delete&title='.api_htmlentities(
  4173. urlencode($obj->reflink)
  4174. ).'&session_id='.api_htmlentities(
  4175. $_GET['session_id']
  4176. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4177. Display::return_icon(
  4178. 'delete.png',
  4179. get_lang('Delete'),
  4180. '',
  4181. ICON_SIZE_SMALL
  4182. );
  4183. }
  4184. if (api_is_allowed_to_session_edit(false, true)) {
  4185. $row[] = '<a href="'.api_get_self(
  4186. ).'?cidReq='.$_course['code'].'&action=edit&title='.api_htmlentities(
  4187. urlencode($obj->reflink)
  4188. ).'&session_id='.api_htmlentities(
  4189. $_GET['session_id']
  4190. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4191. Display::return_icon(
  4192. 'edit.png',
  4193. get_lang('EditPage'),
  4194. '',
  4195. ICON_SIZE_SMALL
  4196. ).'</a> <a href="'.api_get_self(
  4197. ).'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(
  4198. urlencode($obj->reflink)
  4199. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4200. Display::return_icon(
  4201. 'discuss.png',
  4202. get_lang('Discuss'),
  4203. '',
  4204. ICON_SIZE_SMALL
  4205. ).'</a> <a href="'.api_get_self(
  4206. ).'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(
  4207. urlencode($obj->reflink)
  4208. ).'&session_id='.api_htmlentities(
  4209. $_GET['session_id']
  4210. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4211. Display::return_icon(
  4212. 'history.png',
  4213. get_lang('History'),
  4214. '',
  4215. ICON_SIZE_SMALL
  4216. ).'</a>
  4217. <a href="'.api_get_self(
  4218. ).'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(
  4219. urlencode($obj->reflink)
  4220. ).'&session_id='.api_htmlentities(
  4221. $_GET['session_id']
  4222. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4223. Display::return_icon(
  4224. 'what_link_here.png',
  4225. get_lang('LinksPages'),
  4226. '',
  4227. ICON_SIZE_SMALL
  4228. ).'</a>'.$showdelete;
  4229. }
  4230. $rows[] = $row;
  4231. }
  4232. $table = new SortableTableFromArrayConfig(
  4233. $rows,
  4234. 1,
  4235. 10,
  4236. 'AllPages_table',
  4237. '',
  4238. '',
  4239. 'ASC'
  4240. );
  4241. $table->set_additional_parameters(
  4242. [
  4243. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  4244. 'action' => Security::remove_XSS($action),
  4245. 'group_id' => Security::remove_XSS($_GET['group_id'])
  4246. ]
  4247. );
  4248. $table->set_header(
  4249. 0,
  4250. get_lang('Type'),
  4251. true,
  4252. ['style' => 'width:30px;']
  4253. );
  4254. $table->set_header(1, get_lang('Title'), true);
  4255. $table->set_header(
  4256. 2,
  4257. get_lang('Author').' ('.get_lang('LastVersion').')',
  4258. true
  4259. );
  4260. $table->set_header(
  4261. 3,
  4262. get_lang('Date').' ('.get_lang('LastVersion').')',
  4263. true
  4264. );
  4265. if (api_is_allowed_to_session_edit(false, true)) {
  4266. $table->set_header(
  4267. 4,
  4268. get_lang('Actions'),
  4269. true,
  4270. ['style' => 'width:130px;']
  4271. );
  4272. }
  4273. $table->display();
  4274. }
  4275. }
  4276. /**
  4277. * Get recent changes
  4278. * @param string $page
  4279. * @param string $action
  4280. *
  4281. */
  4282. public function recentChanges($page, $action)
  4283. {
  4284. $tbl_wiki = $this->tbl_wiki;
  4285. $course_id = $this->course_id;
  4286. $condition_session = $this->condition_session;
  4287. $groupfilter = $this->groupfilter;
  4288. $tbl_wiki_conf = $this->tbl_wiki_conf;
  4289. if (api_is_allowed_to_session_edit(false, true)) {
  4290. if (self::check_notify_all() == 1) {
  4291. $notify_all = Display::return_icon(
  4292. 'messagebox_info.png',
  4293. get_lang('NotifyByEmail'),
  4294. '',
  4295. ICON_SIZE_SMALL
  4296. ).' '.get_lang('NotNotifyChanges');
  4297. $lock_unlock_notify_all = 'unlocknotifyall';
  4298. } else {
  4299. $notify_all = Display::return_icon(
  4300. 'mail.png',
  4301. get_lang('CancelNotifyByEmail'),
  4302. '',
  4303. ICON_SIZE_SMALL
  4304. ).' '.get_lang('NotifyChanges');
  4305. $lock_unlock_notify_all = 'locknotifyall';
  4306. }
  4307. }
  4308. echo '<div class="actions"><span style="float: right;">';
  4309. echo '<a href="index.php?action=recentchanges&actionpage='.$lock_unlock_notify_all.'&'.api_get_cidreq().'&title='.api_htmlentities(
  4310. urlencode($page)
  4311. ).'">'.$notify_all.'</a>';
  4312. echo '</span>'.get_lang('RecentChanges').'</div>';
  4313. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  4314. //only by professors if page is hidden
  4315. $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
  4316. WHERE '.$tbl_wiki_conf.'.c_id= '.$course_id.' AND
  4317. '.$tbl_wiki.'.c_id= '.$course_id.' AND
  4318. '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
  4319. '.$tbl_wiki.'.'.$groupfilter.$condition_session.'
  4320. ORDER BY dtime DESC'; // new version
  4321. } else {
  4322. $sql = 'SELECT *
  4323. FROM '.$tbl_wiki.'
  4324. WHERE
  4325. c_id = '.$course_id.' AND
  4326. '.$groupfilter.$condition_session.' AND
  4327. visibility=1
  4328. ORDER BY dtime DESC';
  4329. // old version TODO: Replace by the bottom line
  4330. }
  4331. $allpages = Database::query($sql);
  4332. //show table
  4333. if (Database::num_rows($allpages) > 0) {
  4334. $rows = [];
  4335. while ($obj = Database::fetch_object($allpages)) {
  4336. //get author
  4337. $userinfo = api_get_user_info($obj->user_id);
  4338. //get type assignment icon
  4339. if ($obj->assignment == 1) {
  4340. $ShowAssignment = Display::return_icon(
  4341. 'wiki_assignment.png',
  4342. get_lang('AssignmentDesc'),
  4343. '',
  4344. ICON_SIZE_SMALL
  4345. );
  4346. } elseif ($obj->assignment == 2) {
  4347. $ShowAssignment = Display::return_icon(
  4348. 'wiki_work.png',
  4349. get_lang('AssignmentWork'),
  4350. '',
  4351. ICON_SIZE_SMALL
  4352. );
  4353. } elseif ($obj->assignment == 0) {
  4354. $ShowAssignment = Display::return_icon(
  4355. 'px_transparent.gif'
  4356. );
  4357. }
  4358. // Get icon task
  4359. if (!empty($obj->task)) {
  4360. $icon_task = Display::return_icon(
  4361. 'wiki_task.png',
  4362. get_lang('StandardTask'),
  4363. '',
  4364. ICON_SIZE_SMALL
  4365. );
  4366. } else {
  4367. $icon_task = Display::return_icon('px_transparent.gif');
  4368. }
  4369. $row = [];
  4370. $row[] = api_get_local_time(
  4371. $obj->dtime
  4372. );
  4373. $row[] = $ShowAssignment.$icon_task;
  4374. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
  4375. ).'&action=showpage&title='.api_htmlentities(
  4376. urlencode($obj->reflink)
  4377. ).'&view='.$obj->id.'&session_id='.api_get_session_id(
  4378. ).'&group_id='.api_get_group_id().'">'.
  4379. api_htmlentities($obj->title).'</a>';
  4380. $row[] = $obj->version > 1 ? get_lang('EditedBy') : get_lang(
  4381. 'AddedBy'
  4382. );
  4383. if ($userinfo !== false) {
  4384. $row[] = UserManager::getUserProfileLink($userinfo);
  4385. } else {
  4386. $row[] = get_lang('Anonymous').' ('.api_htmlentities(
  4387. $obj->user_ip
  4388. ).')';
  4389. }
  4390. $rows[] = $row;
  4391. }
  4392. $table = new SortableTableFromArrayConfig(
  4393. $rows,
  4394. 0,
  4395. 10,
  4396. 'RecentPages_table',
  4397. '',
  4398. '',
  4399. 'DESC'
  4400. );
  4401. $table->set_additional_parameters(
  4402. [
  4403. 'cidReq' => api_get_course_id(),
  4404. 'action' => Security::remove_XSS($action),
  4405. 'session_id' => api_get_session_id(),
  4406. 'group_id' => api_get_group_id()
  4407. ]
  4408. );
  4409. $table->set_header(
  4410. 0,
  4411. get_lang('Date'),
  4412. true,
  4413. ['style' => 'width:200px;']
  4414. );
  4415. $table->set_header(
  4416. 1,
  4417. get_lang('Type'),
  4418. true,
  4419. ['style' => 'width:30px;']
  4420. );
  4421. $table->set_header(2, get_lang('Title'), true);
  4422. $table->set_header(
  4423. 3,
  4424. get_lang('Actions'),
  4425. true,
  4426. ['style' => 'width:80px;']
  4427. );
  4428. $table->set_header(4, get_lang('Author'), true);
  4429. $table->display();
  4430. }
  4431. }
  4432. /**
  4433. * What links here. Show pages that have linked this page
  4434. *
  4435. * @param string $page
  4436. */
  4437. public function getLinks($page)
  4438. {
  4439. $tbl_wiki = $this->tbl_wiki;
  4440. $course_id = $this->course_id;
  4441. $condition_session = $this->condition_session;
  4442. $groupfilter = $this->groupfilter;
  4443. $_course = $this->courseInfo;
  4444. $action = $this->action;
  4445. if (!$_GET['title']) {
  4446. Display::addFlash(
  4447. Display::return_message(
  4448. get_lang("MustSelectPage"),
  4449. 'error',
  4450. false
  4451. )
  4452. );
  4453. } else {
  4454. $sql = 'SELECT * FROM '.$tbl_wiki.'
  4455. WHERE
  4456. c_id = '.$course_id.' AND
  4457. reflink="'.Database::escape_string($page).'" AND
  4458. '.$groupfilter.$condition_session;
  4459. $result = Database::query($sql);
  4460. $row = Database::fetch_array($result);
  4461. //get type assignment icon
  4462. $ShowAssignment = '';
  4463. if ($row['assignment'] == 1) {
  4464. $ShowAssignment = Display::return_icon(
  4465. 'wiki_assignment.png',
  4466. get_lang('AssignmentDesc'),
  4467. '',
  4468. ICON_SIZE_SMALL
  4469. );
  4470. } elseif ($row['assignment'] == 2) {
  4471. $ShowAssignment = Display::return_icon(
  4472. 'wiki_work.png',
  4473. get_lang('AssignmentWork'),
  4474. '',
  4475. ICON_SIZE_SMALL
  4476. );
  4477. } elseif ($row['assignment'] == 0) {
  4478. $ShowAssignment = Display::return_icon('px_transparent.gif');
  4479. }
  4480. //fix Title to reflink (link Main Page)
  4481. if ($page == get_lang('DefaultTitle')) {
  4482. $page = 'index';
  4483. }
  4484. echo '<div id="wikititle">';
  4485. echo get_lang(
  4486. 'LinksPagesFrom'
  4487. ).': '.$ShowAssignment.' <a href="'.api_get_self(
  4488. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  4489. urlencode($page)
  4490. ).'&session_id='.api_htmlentities(
  4491. $_GET['session_id']
  4492. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4493. api_htmlentities($row['title']).'</a>';
  4494. echo '</div>';
  4495. //fix index to title Main page into linksto
  4496. if ($page == 'index') {
  4497. $page = str_replace(' ', '_', get_lang('DefaultTitle'));
  4498. }
  4499. //table
  4500. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin(
  4501. )) {
  4502. //only by professors if page is hidden
  4503. $sql = "SELECT * FROM ".$tbl_wiki." s1
  4504. WHERE s1.c_id = $course_id AND linksto LIKE '%".Database::escape_string(
  4505. $page
  4506. )."%' AND id=(
  4507. SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
  4508. WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";
  4509. //add blank space after like '%" " %' to identify each word
  4510. } else {
  4511. $sql = "SELECT * FROM ".$tbl_wiki." s1
  4512. WHERE s1.c_id = $course_id AND visibility=1 AND linksto LIKE '%".Database::escape_string(
  4513. $page
  4514. )."%' AND id=(
  4515. SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
  4516. WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";
  4517. //add blank space after like '%" " %' to identify each word
  4518. }
  4519. $allpages = Database::query($sql);
  4520. //show table
  4521. if (Database::num_rows($allpages) > 0) {
  4522. $rows = [];
  4523. while ($obj = Database::fetch_object($allpages)) {
  4524. //get author
  4525. $userinfo = api_get_user_info($obj->user_id);
  4526. //get time
  4527. $year = substr($obj->dtime, 0, 4);
  4528. $month = substr($obj->dtime, 5, 2);
  4529. $day = substr($obj->dtime, 8, 2);
  4530. $hours = substr($obj->dtime, 11, 2);
  4531. $minutes = substr($obj->dtime, 14, 2);
  4532. $seconds = substr($obj->dtime, 17, 2);
  4533. //get type assignment icon
  4534. if ($obj->assignment == 1) {
  4535. $ShowAssignment = Display::return_icon(
  4536. 'wiki_assignment.png',
  4537. get_lang('AssignmentDesc'),
  4538. '',
  4539. ICON_SIZE_SMALL
  4540. );
  4541. } elseif ($obj->assignment == 2) {
  4542. $ShowAssignment = Display::return_icon(
  4543. 'wiki_work.png',
  4544. get_lang('AssignmentWork'),
  4545. '',
  4546. ICON_SIZE_SMALL
  4547. );
  4548. } elseif ($obj->assignment == 0) {
  4549. $ShowAssignment = Display::return_icon(
  4550. 'px_transparent.gif'
  4551. );
  4552. }
  4553. $row = [];
  4554. $row[] = $ShowAssignment;
  4555. $row[] = '<a href="'.api_get_self(
  4556. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  4557. urlencode($obj->reflink)
  4558. ).'&session_id='.api_htmlentities(
  4559. $_GET['session_id']
  4560. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4561. api_htmlentities($obj->title).'</a>';
  4562. if ($userinfo !== false) {
  4563. $row[] = UserManager::getUserProfileLink($userinfo);
  4564. } else {
  4565. $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
  4566. }
  4567. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  4568. $rows[] = $row;
  4569. }
  4570. $table = new SortableTableFromArrayConfig(
  4571. $rows,
  4572. 1,
  4573. 10,
  4574. 'AllPages_table',
  4575. '',
  4576. '',
  4577. 'ASC'
  4578. );
  4579. $table->set_additional_parameters(
  4580. [
  4581. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  4582. 'action' => Security::remove_XSS($action),
  4583. 'group_id' => intval($_GET['group_id']),
  4584. ]
  4585. );
  4586. $table->set_header(
  4587. 0,
  4588. get_lang('Type'),
  4589. true,
  4590. ['style' => 'width:30px;']
  4591. );
  4592. $table->set_header(1, get_lang('Title'), true);
  4593. $table->set_header(2, get_lang('Author'), true);
  4594. $table->set_header(3, get_lang('Date'), true);
  4595. $table->display();
  4596. }
  4597. }
  4598. }
  4599. /**
  4600. * @param string $action
  4601. */
  4602. public function getSearchPages($action)
  4603. {
  4604. echo '<div class="actions">'.get_lang('SearchPages').'</div>';
  4605. if (isset($_GET['mode_table'])) {
  4606. if (!isset($_GET['SearchPages_table_page_nr'])) {
  4607. $_GET['search_term'] = isset($_POST['search_term']) ? $_POST['search_term'] : '';
  4608. $_GET['search_content'] = isset($_POST['search_content']) ? $_POST['search_content'] : '';
  4609. $_GET['all_vers'] = isset($_POST['all_vers']) ? $_POST['all_vers'] : '';
  4610. }
  4611. self::display_wiki_search_results(
  4612. $_GET['search_term'],
  4613. $_GET['search_content'],
  4614. $_GET['all_vers']
  4615. );
  4616. } else {
  4617. // initiate the object
  4618. $form = new FormValidator(
  4619. 'wiki_search',
  4620. 'post',
  4621. api_get_self().'?cidReq='.api_get_course_id(
  4622. ).'&action='.api_htmlentities(
  4623. $action
  4624. ).'&session_id='.api_get_session_id(
  4625. ).'&group_id='.api_get_group_id().'&mode_table=yes1'
  4626. );
  4627. // Setting the form elements
  4628. $form->addText(
  4629. 'search_term',
  4630. get_lang('SearchTerm'),
  4631. true,
  4632. ['autofocus' => 'autofocus']
  4633. );
  4634. $form->addElement(
  4635. 'checkbox',
  4636. 'search_content',
  4637. null,
  4638. get_lang('AlsoSearchContent')
  4639. );
  4640. $form->addElement(
  4641. 'checkbox',
  4642. 'all_vers',
  4643. null,
  4644. get_lang('IncludeAllVersions')
  4645. );
  4646. $form->addButtonSearch(get_lang('Search'), 'SubmitWikiSearch');
  4647. // setting the rules
  4648. $form->addRule(
  4649. 'search_term',
  4650. get_lang('TooShort'),
  4651. 'minlength',
  4652. 3
  4653. ); //TODO: before fixing the pagination rules worked, not now
  4654. if ($form->validate()) {
  4655. $form->display();
  4656. $values = $form->exportValues();
  4657. self::display_wiki_search_results(
  4658. $values['search_term'],
  4659. $values['search_content'],
  4660. $values['all_vers']
  4661. );
  4662. } else {
  4663. $form->display();
  4664. }
  4665. }
  4666. }
  4667. /**
  4668. * @param int $userId
  4669. * @param string $action
  4670. */
  4671. public function getUserContributions($userId, $action)
  4672. {
  4673. $_course = $this->courseInfo;
  4674. $tbl_wiki = $this->tbl_wiki;
  4675. $course_id = $this->course_id;
  4676. $condition_session = $this->condition_session;
  4677. $groupfilter = $this->groupfilter;
  4678. $userId = intval($userId);
  4679. $userinfo = api_get_user_info($userId);
  4680. if ($userinfo !== false) {
  4681. echo '<div class="actions">'.
  4682. get_lang('UserContributions').': '.UserManager::getUserProfileLink($userinfo).
  4683. '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.$userId.
  4684. '&session_id='.$this->session_id.'&group_id='.$this->group_id.'">'.
  4685. '</a></div>';
  4686. }
  4687. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  4688. //only by professors if page is hidden
  4689. $sql = 'SELECT * FROM '.$tbl_wiki.'
  4690. WHERE
  4691. c_id = '.$course_id.' AND
  4692. '.$groupfilter.$condition_session.' AND
  4693. user_id="'.$userId.'"';
  4694. } else {
  4695. $sql = 'SELECT * FROM '.$tbl_wiki.'
  4696. WHERE
  4697. c_id = '.$course_id.' AND
  4698. '.$groupfilter.$condition_session.' AND
  4699. user_id="'.$userId.'" AND
  4700. visibility=1';
  4701. }
  4702. $allpages = Database::query($sql);
  4703. //show table
  4704. if (Database::num_rows($allpages) > 0) {
  4705. $rows = [];
  4706. while ($obj = Database::fetch_object($allpages)) {
  4707. //get type assignment icon
  4708. $ShowAssignment = '';
  4709. if ($obj->assignment == 1) {
  4710. $ShowAssignment = Display::return_icon(
  4711. 'wiki_assignment.png',
  4712. get_lang('AssignmentDescExtra'),
  4713. '',
  4714. ICON_SIZE_SMALL
  4715. );
  4716. } elseif ($obj->assignment == 2) {
  4717. $ShowAssignment = Display::return_icon(
  4718. 'wiki_work.png',
  4719. get_lang('AssignmentWork'),
  4720. '',
  4721. ICON_SIZE_SMALL
  4722. );
  4723. } elseif ($obj->assignment == 0) {
  4724. $ShowAssignment = Display::return_icon(
  4725. 'px_transparent.gif'
  4726. );
  4727. }
  4728. $row = [];
  4729. $row[] = api_get_local_time($obj->dtime);
  4730. $row[] = $ShowAssignment;
  4731. $row[] = '<a href="'.api_get_self(
  4732. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  4733. urlencode($obj->reflink)
  4734. ).'&view='.$obj->id.'&session_id='.api_get_session_id(
  4735. ).'&group_id='.api_get_group_id().'">'.
  4736. api_htmlentities($obj->title).'</a>';
  4737. $row[] = Security::remove_XSS($obj->version);
  4738. $row[] = Security::remove_XSS($obj->comment);
  4739. $row[] = Security::remove_XSS($obj->progress).' %';
  4740. $row[] = Security::remove_XSS($obj->score);
  4741. $rows[] = $row;
  4742. }
  4743. $table = new SortableTableFromArrayConfig(
  4744. $rows,
  4745. 2,
  4746. 10,
  4747. 'UsersContributions_table',
  4748. '',
  4749. '',
  4750. 'ASC'
  4751. );
  4752. $table->set_additional_parameters(
  4753. [
  4754. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  4755. 'action' => Security::remove_XSS($action),
  4756. 'user_id' => intval($userId),
  4757. 'session_id' => intval($_GET['session_id']),
  4758. 'group_id' => intval($_GET['group_id']),
  4759. ]
  4760. );
  4761. $table->set_header(
  4762. 0,
  4763. get_lang('Date'),
  4764. true,
  4765. ['style' => 'width:200px;']
  4766. );
  4767. $table->set_header(
  4768. 1,
  4769. get_lang('Type'),
  4770. true,
  4771. ['style' => 'width:30px;']
  4772. );
  4773. $table->set_header(
  4774. 2,
  4775. get_lang('Title'),
  4776. true,
  4777. ['style' => 'width:200px;']
  4778. );
  4779. $table->set_header(
  4780. 3,
  4781. get_lang('Version'),
  4782. true,
  4783. ['style' => 'width:30px;']
  4784. );
  4785. $table->set_header(
  4786. 4,
  4787. get_lang('Comment'),
  4788. true,
  4789. ['style' => 'width:200px;']
  4790. );
  4791. $table->set_header(
  4792. 5,
  4793. get_lang('Progress'),
  4794. true,
  4795. ['style' => 'width:30px;']
  4796. );
  4797. $table->set_header(
  4798. 6,
  4799. get_lang('Rating'),
  4800. true,
  4801. ['style' => 'width:30px;']
  4802. );
  4803. $table->display();
  4804. }
  4805. }
  4806. /**
  4807. * @param string $action
  4808. */
  4809. public function getMostChangedPages($action)
  4810. {
  4811. $_course = $this->courseInfo;
  4812. $tbl_wiki = $this->tbl_wiki;
  4813. $course_id = $this->course_id;
  4814. $condition_session = $this->condition_session;
  4815. $groupfilter = $this->groupfilter;
  4816. echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
  4817. if (api_is_allowed_to_edit(false, true) ||
  4818. api_is_platform_admin()
  4819. ) { //only by professors if page is hidden
  4820. $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
  4821. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  4822. GROUP BY reflink';//TODO:check MAX and group by return last version
  4823. } else {
  4824. $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
  4825. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1
  4826. GROUP BY reflink'; //TODO:check MAX and group by return last version
  4827. }
  4828. $allpages = Database::query($sql);
  4829. //show table
  4830. if (Database::num_rows($allpages) > 0) {
  4831. $rows = [];
  4832. while ($obj = Database::fetch_object($allpages)) {
  4833. //get type assignment icon
  4834. $ShowAssignment = '';
  4835. if ($obj->assignment == 1) {
  4836. $ShowAssignment = Display::return_icon(
  4837. 'wiki_assignment.png',
  4838. get_lang('AssignmentDesc'),
  4839. '',
  4840. ICON_SIZE_SMALL
  4841. );
  4842. } elseif ($obj->assignment == 2) {
  4843. $ShowAssignment = Display::return_icon(
  4844. 'wiki_work.png',
  4845. get_lang('AssignmentWork'),
  4846. '',
  4847. ICON_SIZE_SMALL
  4848. );
  4849. } elseif ($obj->assignment == 0) {
  4850. $ShowAssignment = Display::return_icon(
  4851. 'px_transparent.gif'
  4852. );
  4853. }
  4854. $row = [];
  4855. $row[] = $ShowAssignment;
  4856. $row[] = '<a href="'.api_get_self(
  4857. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  4858. urlencode($obj->reflink)
  4859. ).'&session_id='.api_htmlentities(
  4860. $_GET['session_id']
  4861. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  4862. api_htmlentities($obj->title).'</a>';
  4863. $row[] = $obj->MAX;
  4864. $rows[] = $row;
  4865. }
  4866. $table = new SortableTableFromArrayConfig(
  4867. $rows,
  4868. 2,
  4869. 10,
  4870. 'MostChangedPages_table',
  4871. '',
  4872. '',
  4873. 'DESC'
  4874. );
  4875. $table->set_additional_parameters(
  4876. [
  4877. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  4878. 'action' => Security::remove_XSS($action),
  4879. 'session_id' => intval($_GET['session_id']),
  4880. 'group_id' => intval($_GET['group_id']),
  4881. ]
  4882. );
  4883. $table->set_header(
  4884. 0,
  4885. get_lang('Type'),
  4886. true,
  4887. ['style' => 'width:30px;']
  4888. );
  4889. $table->set_header(1, get_lang('Title'), true);
  4890. $table->set_header(2, get_lang('Changes'), true);
  4891. $table->display();
  4892. }
  4893. }
  4894. /**
  4895. * Restore page
  4896. * @return bool
  4897. */
  4898. public function restorePage()
  4899. {
  4900. $userId = api_get_user_id();
  4901. $_course = $this->courseInfo;
  4902. $current_row = $this->getWikiData();
  4903. $last_row = $this->getLastWikiData($this->page);
  4904. if (empty($last_row)) {
  4905. return false;
  4906. }
  4907. $PassEdit = false;
  4908. /* Only teachers and platform admin can edit the index page.
  4909. Only teachers and platform admin can edit an assignment teacher*/
  4910. if (($current_row['reflink'] == 'index' ||
  4911. $current_row['reflink'] == '' ||
  4912. $current_row['assignment'] == 1) &&
  4913. (!api_is_allowed_to_edit(false, true) &&
  4914. $this->group_id == 0)
  4915. ) {
  4916. Display::addFlash(
  4917. Display::return_message(
  4918. get_lang('OnlyEditPagesCourseManager'),
  4919. 'normal',
  4920. false
  4921. )
  4922. );
  4923. } else {
  4924. // check if is a wiki group
  4925. if ($current_row['group_id'] != 0) {
  4926. $groupInfo = GroupManager::get_group_properties(
  4927. $this->group_id
  4928. );
  4929. //Only teacher, platform admin and group members can edit a wiki group
  4930. if (api_is_allowed_to_edit(false, true) ||
  4931. api_is_platform_admin() ||
  4932. GroupManager::is_user_in_group($userId, $groupInfo) ||
  4933. api_is_allowed_in_course()
  4934. ) {
  4935. $PassEdit = true;
  4936. } else {
  4937. Display::addFlash(
  4938. Display::return_message(
  4939. get_lang('OnlyEditPagesGroupMembers'),
  4940. 'normal',
  4941. false
  4942. )
  4943. );
  4944. }
  4945. } else {
  4946. $PassEdit = true;
  4947. }
  4948. // check if is an assignment
  4949. //$icon_assignment = null;
  4950. if ($current_row['assignment'] == 1) {
  4951. Display::addFlash(
  4952. Display::return_message(
  4953. get_lang('EditAssignmentWarning'),
  4954. 'normal',
  4955. false
  4956. )
  4957. );
  4958. } elseif ($current_row['assignment'] == 2) {
  4959. if (($userId == $current_row['user_id']) == false) {
  4960. if (api_is_allowed_to_edit(
  4961. false,
  4962. true
  4963. ) || api_is_platform_admin()) {
  4964. $PassEdit = true;
  4965. } else {
  4966. Display::addFlash(
  4967. Display::return_message(
  4968. get_lang('LockByTeacher'),
  4969. 'normal',
  4970. false
  4971. )
  4972. );
  4973. $PassEdit = false;
  4974. }
  4975. } else {
  4976. $PassEdit = true;
  4977. }
  4978. }
  4979. //show editor if edit is allowed
  4980. if ($PassEdit) {
  4981. if ($current_row['editlock'] == 1 &&
  4982. (api_is_allowed_to_edit(false, true) == false ||
  4983. api_is_platform_admin() == false)
  4984. ) {
  4985. Display::addFlash(
  4986. Display::return_message(
  4987. get_lang('PageLockedExtra'),
  4988. 'normal',
  4989. false
  4990. )
  4991. );
  4992. } else {
  4993. if ($last_row['is_editing'] != 0 && $last_row['is_editing'] != $userId) {
  4994. // Checking for concurrent users
  4995. $timestamp_edit = strtotime($last_row['time_edit']);
  4996. $time_editing = time() - $timestamp_edit;
  4997. $max_edit_time = 1200; // 20 minutes
  4998. $rest_time = $max_edit_time - $time_editing;
  4999. $userinfo = api_get_user_info($last_row['is_editing']);
  5000. $is_being_edited = get_lang(
  5001. 'ThisPageisBeginEditedBy'
  5002. ).' <a href='.$userinfo['profile_url'].'>'.
  5003. Display::tag(
  5004. 'span',
  5005. $userinfo['complete_name_with_username']
  5006. ).
  5007. get_lang('ThisPageisBeginEditedTryLater').' '.date(
  5008. "i",
  5009. $rest_time
  5010. ).' '.get_lang('MinMinutes');
  5011. Display::addFlash(
  5012. Display::return_message(
  5013. $is_being_edited,
  5014. 'normal',
  5015. false
  5016. )
  5017. );
  5018. } else {
  5019. Display::addFlash(
  5020. Display::return_message(
  5021. self::restore_wikipage(
  5022. $current_row['page_id'],
  5023. $current_row['reflink'],
  5024. $current_row['title'],
  5025. $current_row['content'],
  5026. $current_row['group_id'],
  5027. $current_row['assignment'],
  5028. $current_row['progress'],
  5029. $current_row['version'],
  5030. $last_row['version'],
  5031. $current_row['linksto']
  5032. ).': <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5033. urlencode($last_row['reflink'])
  5034. ).'&session_id='.$last_row['session_id'].'&group_id='.$last_row['group_id'].'">'.
  5035. api_htmlentities($last_row['title']).'</a>',
  5036. 'confirmation',
  5037. false
  5038. )
  5039. );
  5040. }
  5041. }
  5042. }
  5043. }
  5044. }
  5045. /**
  5046. * @param int|bool $wikiId
  5047. */
  5048. public function setWikiData($wikiId)
  5049. {
  5050. $this->wikiData = self::getWikiDataFromDb($wikiId);
  5051. }
  5052. /**
  5053. * @return array
  5054. */
  5055. public function getWikiData()
  5056. {
  5057. return $this->wikiData;
  5058. }
  5059. /**
  5060. * Check last version
  5061. * @param int $view
  5062. * @return bool
  5063. */
  5064. public function checkLastVersion($view)
  5065. {
  5066. $tbl_wiki = $this->tbl_wiki;
  5067. $course_id = $this->course_id;
  5068. $condition_session = $this->condition_session;
  5069. $groupfilter = $this->groupfilter;
  5070. $page = $this->page;
  5071. $_course = $this->courseInfo;
  5072. if (empty($view)) {
  5073. return false;
  5074. }
  5075. $current_row = $this->getWikiData();
  5076. $sql = 'SELECT * FROM '.$tbl_wiki.'
  5077. WHERE
  5078. c_id = '.$course_id.' AND
  5079. reflink = "'.Database::escape_string($page).'" AND
  5080. '.$groupfilter.$condition_session.'
  5081. ORDER BY id DESC'; //last version
  5082. $result = Database::query($sql);
  5083. $last_row = Database::fetch_array($result);
  5084. if ($view < $last_row['id']) {
  5085. $message = '<center>'.get_lang('NoAreSeeingTheLastVersion').'<br />
  5086. '.get_lang("Version").' (
  5087. <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5088. urlencode($current_row['reflink'])
  5089. ).'&group_id='.$current_row['group_id'].'&session_id='.$current_row['session_id'].'&view='.api_htmlentities(
  5090. $_GET['view']
  5091. ).'" title="'.get_lang('CurrentVersion').'">
  5092. '.$current_row['version'].'
  5093. </a> /
  5094. <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5095. urlencode($last_row['reflink'])
  5096. ).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'" title="'.get_lang(
  5097. 'LastVersion'
  5098. ).'">
  5099. '.$last_row['version'].'
  5100. </a>) <br />'.get_lang("ConvertToLastVersion").':
  5101. <a href="index.php?cidReq='.$_course['id'].'&action=restorepage&title='.api_htmlentities(
  5102. urlencode($last_row['reflink'])
  5103. ).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'&view='.api_htmlentities(
  5104. $_GET['view']
  5105. ).'">'.
  5106. get_lang("Restore").'</a></center>';
  5107. Display::addFlash(
  5108. Display::return_message($message, 'warning', false)
  5109. );
  5110. }
  5111. }
  5112. /**
  5113. * Get most linked pages
  5114. */
  5115. public function getMostLinked()
  5116. {
  5117. $tbl_wiki = $this->tbl_wiki;
  5118. $course_id = $this->course_id;
  5119. $groupfilter = $this->groupfilter;
  5120. $condition_session = $this->condition_session;
  5121. $_course = $this->courseInfo;
  5122. echo '<div class="actions">'.get_lang('MostLinkedPages').'</div>';
  5123. $pages = [];
  5124. $linked = [];
  5125. // Get name pages
  5126. $sql = 'SELECT * FROM '.$tbl_wiki.'
  5127. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  5128. GROUP BY reflink
  5129. ORDER BY reflink ASC';
  5130. $allpages = Database::query($sql);
  5131. while ($row = Database::fetch_array($allpages)) {
  5132. if ($row['reflink'] == 'index') {
  5133. $row['reflink'] = str_replace(
  5134. ' ',
  5135. '_',
  5136. get_lang('DefaultTitle')
  5137. );
  5138. }
  5139. $pages[] = $row['reflink'];
  5140. }
  5141. // Get name refs in last pages
  5142. $sql = 'SELECT *
  5143. FROM '.$tbl_wiki.' s1
  5144. WHERE s1.c_id = '.$course_id.' AND id=(
  5145. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  5146. WHERE
  5147. s2.c_id = '.$course_id.' AND
  5148. s1.reflink = s2.reflink AND
  5149. '.$groupfilter.$condition_session.'
  5150. )';
  5151. $allpages = Database::query($sql);
  5152. while ($row = Database::fetch_array($allpages)) {
  5153. //remove self reference
  5154. $row['linksto'] = str_replace(
  5155. $row["reflink"],
  5156. " ",
  5157. trim($row["linksto"])
  5158. );
  5159. $refs = explode(" ", trim($row["linksto"]));
  5160. // Find linksto into reflink. If found ->page is linked
  5161. foreach ($refs as $v) {
  5162. if (in_array($v, $pages)) {
  5163. if (trim($v) != "") {
  5164. $linked[] = $v;
  5165. }
  5166. }
  5167. }
  5168. }
  5169. $linked = array_unique($linked);
  5170. //make a unique list. TODO:delete this line and count how many for each page
  5171. //show table
  5172. $rows = [];
  5173. foreach ($linked as $linked_show) {
  5174. $row = [];
  5175. $row[] = '<a href="'.api_get_self(
  5176. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5177. urlencode(str_replace('_', ' ', $linked_show))
  5178. ).'&session_id='.api_htmlentities(
  5179. $_GET['session_id']
  5180. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  5181. str_replace('_', ' ', $linked_show).'</a>';
  5182. $rows[] = $row;
  5183. }
  5184. $table = new SortableTableFromArrayConfig(
  5185. $rows,
  5186. 0,
  5187. 10,
  5188. 'LinkedPages_table',
  5189. '',
  5190. '',
  5191. 'DESC'
  5192. );
  5193. $table->set_additional_parameters(
  5194. [
  5195. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  5196. 'action' => Security::remove_XSS($this->action),
  5197. 'session_id' => intval($_GET['session_id']),
  5198. 'group_id' => intval($_GET['group_id']),
  5199. ]
  5200. );
  5201. $table->set_header(0, get_lang('Title'), true);
  5202. $table->display();
  5203. }
  5204. /**
  5205. * Get orphan pages
  5206. */
  5207. public function getOrphaned()
  5208. {
  5209. $tbl_wiki = $this->tbl_wiki;
  5210. $course_id = $this->course_id;
  5211. $groupfilter = $this->groupfilter;
  5212. $condition_session = $this->condition_session;
  5213. $_course = $this->courseInfo;
  5214. echo '<div class="actions">'.get_lang('OrphanedPages').'</div>';
  5215. $pages = [];
  5216. $orphaned = [];
  5217. //get name pages
  5218. $sql = 'SELECT * FROM '.$tbl_wiki.'
  5219. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  5220. GROUP BY reflink
  5221. ORDER BY reflink ASC';
  5222. $allpages = Database::query($sql);
  5223. while ($row = Database::fetch_array($allpages)) {
  5224. $pages[] = $row['reflink'];
  5225. }
  5226. //get name refs in last pages and make a unique list
  5227. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  5228. WHERE s1.c_id = '.$course_id.' AND id=(
  5229. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  5230. WHERE
  5231. s2.c_id = '.$course_id.' AND
  5232. s1.reflink = s2.reflink AND
  5233. '.$groupfilter.$condition_session.'
  5234. )';
  5235. $allpages = Database::query($sql);
  5236. $array_refs_linked = [];
  5237. while ($row = Database::fetch_array($allpages)) {
  5238. $row['linksto'] = str_replace(
  5239. $row["reflink"],
  5240. " ",
  5241. trim($row["linksto"])
  5242. ); //remove self reference
  5243. $refs = explode(" ", trim($row["linksto"]));
  5244. foreach ($refs as $ref_linked) {
  5245. if ($ref_linked == str_replace(
  5246. ' ',
  5247. '_',
  5248. get_lang('DefaultTitle')
  5249. )) {
  5250. $ref_linked = 'index';
  5251. }
  5252. $array_refs_linked[] = $ref_linked;
  5253. }
  5254. }
  5255. $array_refs_linked = array_unique($array_refs_linked);
  5256. //search each name of list linksto into list reflink
  5257. foreach ($pages as $v) {
  5258. if (!in_array($v, $array_refs_linked)) {
  5259. $orphaned[] = $v;
  5260. }
  5261. }
  5262. $rows = [];
  5263. foreach ($orphaned as $orphaned_show) {
  5264. // get visibility status and title
  5265. $sql = 'SELECT *
  5266. FROM '.$tbl_wiki.'
  5267. WHERE
  5268. c_id = '.$course_id.' AND
  5269. '.$groupfilter.$condition_session.' AND
  5270. reflink="'.Database::escape_string($orphaned_show).'"
  5271. GROUP BY reflink';
  5272. $allpages = Database::query($sql);
  5273. while ($row = Database::fetch_array($allpages)) {
  5274. $orphaned_title = $row['title'];
  5275. $orphaned_visibility = $row['visibility'];
  5276. if ($row['assignment'] == 1) {
  5277. $ShowAssignment = Display::return_icon(
  5278. 'wiki_assignment.png',
  5279. '',
  5280. '',
  5281. ICON_SIZE_SMALL
  5282. );
  5283. } elseif ($row['assignment'] == 2) {
  5284. $ShowAssignment = Display::return_icon(
  5285. 'wiki_work.png',
  5286. '',
  5287. '',
  5288. ICON_SIZE_SMALL
  5289. );
  5290. } elseif ($row['assignment'] == 0) {
  5291. $ShowAssignment = Display::return_icon(
  5292. 'px_transparent.gif'
  5293. );
  5294. }
  5295. }
  5296. if (!api_is_allowed_to_edit(false, true) || !api_is_platform_admin(
  5297. ) && $orphaned_visibility == 0) {
  5298. continue;
  5299. }
  5300. //show table
  5301. $row = [];
  5302. $row[] = $ShowAssignment;
  5303. $row[] = '<a href="'.api_get_self(
  5304. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5305. urlencode($orphaned_show)
  5306. ).'&session_id='.api_htmlentities(
  5307. $_GET['session_id']
  5308. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  5309. api_htmlentities($orphaned_title).'</a>';
  5310. $rows[] = $row;
  5311. }
  5312. $table = new SortableTableFromArrayConfig(
  5313. $rows,
  5314. 1,
  5315. 10,
  5316. 'OrphanedPages_table',
  5317. '',
  5318. '',
  5319. 'DESC'
  5320. );
  5321. $table->set_additional_parameters(
  5322. [
  5323. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  5324. 'action' => Security::remove_XSS($this->action),
  5325. 'session_id' => intval($_GET['session_id']),
  5326. 'group_id' => intval($_GET['group_id']),
  5327. ]
  5328. );
  5329. $table->set_header(
  5330. 0,
  5331. get_lang('Type'),
  5332. true,
  5333. ['style' => 'width:30px;']
  5334. );
  5335. $table->set_header(1, get_lang('Title'), true);
  5336. $table->display();
  5337. }
  5338. /**
  5339. * Get wanted pages
  5340. */
  5341. public function getWantedPages()
  5342. {
  5343. $tbl_wiki = $this->tbl_wiki;
  5344. $course_id = $this->course_id;
  5345. $groupfilter = $this->groupfilter;
  5346. $condition_session = $this->condition_session;
  5347. echo '<div class="actions">'.get_lang('WantedPages').'</div>';
  5348. $pages = [];
  5349. $wanted = [];
  5350. //get name pages
  5351. $sql = 'SELECT * FROM '.$tbl_wiki.'
  5352. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  5353. GROUP BY reflink
  5354. ORDER BY reflink ASC';
  5355. $allpages = Database::query($sql);
  5356. while ($row = Database::fetch_array($allpages)) {
  5357. if ($row['reflink'] == 'index') {
  5358. $row['reflink'] = str_replace(
  5359. ' ',
  5360. '_',
  5361. get_lang('DefaultTitle')
  5362. );
  5363. }
  5364. $pages[] = $row['reflink'];
  5365. }
  5366. //get name refs in last pages
  5367. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  5368. WHERE s1.c_id = '.$course_id.' AND id=(
  5369. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  5370. WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.$condition_session.'
  5371. )';
  5372. $allpages = Database::query($sql);
  5373. while ($row = Database::fetch_array($allpages)) {
  5374. $refs = explode(" ", trim($row["linksto"]));
  5375. // Find linksto into reflink. If not found ->page is wanted
  5376. foreach ($refs as $v) {
  5377. if (!in_array($v, $pages)) {
  5378. if (trim($v) != "") {
  5379. $wanted[] = $v;
  5380. }
  5381. }
  5382. }
  5383. }
  5384. $wanted = array_unique($wanted); //make a unique list
  5385. //show table
  5386. $rows = [];
  5387. foreach ($wanted as $wanted_show) {
  5388. $row = [];
  5389. $wanted_show = Security::remove_XSS($wanted_show);
  5390. $row[] = '<a href="'.api_get_path(
  5391. WEB_PATH
  5392. ).'main/wiki/index.php?cidReq=&action=addnew&title='.str_replace(
  5393. '_',
  5394. ' ',
  5395. $wanted_show
  5396. ).'&session_id='.api_htmlentities(
  5397. $_GET['session_id']
  5398. ).'&group_id='.api_htmlentities(
  5399. $_GET['group_id']
  5400. ).'" class="new_wiki_link">'.str_replace(
  5401. '_',
  5402. ' ',
  5403. $wanted_show
  5404. ).'</a>'; //meter un remove xss en lugar de htmlentities
  5405. $rows[] = $row;
  5406. }
  5407. $table = new SortableTableFromArrayConfig(
  5408. $rows,
  5409. 0,
  5410. 10,
  5411. 'WantedPages_table',
  5412. '',
  5413. '',
  5414. 'DESC'
  5415. );
  5416. $table->set_additional_parameters(
  5417. [
  5418. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  5419. 'action' => Security::remove_XSS($this->action),
  5420. 'session_id' => intval($_GET['session_id']),
  5421. 'group_id' => intval($_GET['group_id']),
  5422. ]
  5423. );
  5424. $table->set_header(0, get_lang('Title'), true);
  5425. $table->display();
  5426. }
  5427. /**
  5428. * Most visited
  5429. */
  5430. public function getMostVisited()
  5431. {
  5432. $tbl_wiki = $this->tbl_wiki;
  5433. $course_id = $this->course_id;
  5434. $groupfilter = $this->groupfilter;
  5435. $condition_session = $this->condition_session;
  5436. $_course = $this->courseInfo;
  5437. echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
  5438. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin(
  5439. )) { //only by professors if page is hidden
  5440. $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
  5441. WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
  5442. GROUP BY reflink';
  5443. } else {
  5444. $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
  5445. WHERE
  5446. c_id = '.$course_id.' AND
  5447. '.$groupfilter.$condition_session.' AND
  5448. visibility=1
  5449. GROUP BY reflink';
  5450. }
  5451. $allpages = Database::query($sql);
  5452. //show table
  5453. if (Database::num_rows($allpages) > 0) {
  5454. $rows = [];
  5455. while ($obj = Database::fetch_object($allpages)) {
  5456. //get type assignment icon
  5457. $ShowAssignment = '';
  5458. if ($obj->assignment == 1) {
  5459. $ShowAssignment = Display::return_icon(
  5460. 'wiki_assignment.png',
  5461. get_lang('AssignmentDesc'),
  5462. '',
  5463. ICON_SIZE_SMALL
  5464. );
  5465. } elseif ($obj->assignment == 2) {
  5466. $ShowAssignment = $ShowAssignment = Display::return_icon(
  5467. 'wiki_work.png',
  5468. get_lang('AssignmentWork'),
  5469. '',
  5470. ICON_SIZE_SMALL
  5471. );
  5472. } elseif ($obj->assignment == 0) {
  5473. $ShowAssignment = Display::return_icon(
  5474. 'px_transparent.gif'
  5475. );
  5476. }
  5477. $row = [];
  5478. $row[] = $ShowAssignment;
  5479. $row[] = '<a href="'.api_get_self(
  5480. ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
  5481. urlencode($obj->reflink)
  5482. ).'&session_id='.api_htmlentities(
  5483. $_GET['session_id']
  5484. ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
  5485. api_htmlentities($obj->title).'</a>';
  5486. $row[] = $obj->tsum;
  5487. $rows[] = $row;
  5488. }
  5489. $table = new SortableTableFromArrayConfig(
  5490. $rows,
  5491. 2,
  5492. 10,
  5493. 'MostVisitedPages_table',
  5494. '',
  5495. '',
  5496. 'DESC'
  5497. );
  5498. $table->set_additional_parameters(
  5499. [
  5500. 'cidReq' => Security::remove_XSS($_GET['cidReq']),
  5501. 'action' => Security::remove_XSS($this->action),
  5502. 'session_id' => intval($_GET['session_id']),
  5503. 'group_id' => intval($_GET['group_id']),
  5504. ]
  5505. );
  5506. $table->set_header(
  5507. 0,
  5508. get_lang('Type'),
  5509. true,
  5510. ['style' => 'width:30px;']
  5511. );
  5512. $table->set_header(1, get_lang('Title'), true);
  5513. $table->set_header(2, get_lang('Visits'), true);
  5514. $table->display();
  5515. }
  5516. }
  5517. /**
  5518. * Get actions bar
  5519. * @return string
  5520. */
  5521. public function showActionBar()
  5522. {
  5523. $_course = $this->courseInfo;
  5524. $session_id = $this->session_id;
  5525. $groupId = $this->group_id;
  5526. $page = $this->page;
  5527. $actionsLeft = '';
  5528. $actionsLeft .= '<a href="index.php?action=showpage&title=index&cidReq='.$_course['id'].'&session_id='.$session_id.'&group_id='.$groupId.'">'.
  5529. Display::return_icon(
  5530. 'home.png',
  5531. get_lang('Home'),
  5532. '',
  5533. ICON_SIZE_MEDIUM
  5534. ).'</a>';
  5535. if (api_is_allowed_to_session_edit(
  5536. false,
  5537. true
  5538. ) && api_is_allowed_to_edit()) {
  5539. // menu add page
  5540. $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=addnew&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
  5541. 'addnew'
  5542. ).'>'
  5543. .Display::return_icon(
  5544. 'add.png',
  5545. get_lang('AddNew'),
  5546. '',
  5547. ICON_SIZE_MEDIUM
  5548. ).'</a>';
  5549. }
  5550. $lock_unlock_addnew = null;
  5551. $protect_addnewpage = null;
  5552. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  5553. // page action: enable or disable the adding of new pages
  5554. if (self::check_addnewpagelock() == 0) {
  5555. $protect_addnewpage = Display::return_icon(
  5556. 'off.png',
  5557. get_lang('AddOptionProtected')
  5558. );
  5559. $lock_unlock_addnew = 'unlockaddnew';
  5560. } else {
  5561. $protect_addnewpage = Display::return_icon(
  5562. 'on.png',
  5563. get_lang('AddOptionUnprotected')
  5564. );
  5565. $lock_unlock_addnew = 'lockaddnew';
  5566. }
  5567. }
  5568. // menu find
  5569. $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=searchpages&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
  5570. 'searchpages'
  5571. ).'>'.
  5572. Display::return_icon(
  5573. 'search.png',
  5574. get_lang('SearchPages'),
  5575. '',
  5576. ICON_SIZE_MEDIUM
  5577. ).'</a></li>';
  5578. ///menu more
  5579. $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=searchpages&session_id='.$session_id.'&group_id='.$groupId.'&action=more&title='.api_htmlentities(
  5580. urlencode($page)
  5581. ).'"'.self::is_active_navigation_tab('more').'>'.
  5582. Display::return_icon(
  5583. 'stats.png',
  5584. get_lang('Statistics'),
  5585. '',
  5586. ICON_SIZE_MEDIUM
  5587. ).'</a></li>';
  5588. // menu all pages
  5589. $actionsLeft .= '<a class="btn btn-default" href="index.php?cidReq='.$_course['id'].'&action=allpages&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
  5590. 'allpages'
  5591. ).'>'.
  5592. get_lang('AllPages').'</a>';
  5593. // menu recent changes
  5594. $actionsLeft .= '<a class="btn btn-default" href="index.php?cidReq='.$_course['id'].'&action=recentchanges&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
  5595. 'recentchanges'
  5596. ).'>'.
  5597. get_lang('RecentChanges').'</a>';
  5598. echo Display::toolbarAction('toolbar-wiki', [$actionsLeft]);
  5599. }
  5600. /**
  5601. * Showing warning
  5602. */
  5603. public function deletePageWarning()
  5604. {
  5605. $page = $this->page;
  5606. $course_id = $this->course_id;
  5607. $groupfilter = $this->groupfilter;
  5608. $condition_session = $this->condition_session;
  5609. if (!$_GET['title']) {
  5610. Display::addFlash(
  5611. Display::return_message(
  5612. get_lang('MustSelectPage'),
  5613. 'error',
  5614. false
  5615. )
  5616. );
  5617. return;
  5618. }
  5619. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  5620. Display::addFlash(
  5621. '<div id="wikititle">'.get_lang('DeletePageHistory').'</div>'
  5622. );
  5623. if ($page == "index") {
  5624. Display::addFlash(
  5625. Display::return_message(
  5626. get_lang('WarningDeleteMainPage'),
  5627. 'warning',
  5628. false
  5629. )
  5630. );
  5631. }
  5632. $message = get_lang('ConfirmDeletePage')."
  5633. <a href=\"index.php?".api_get_cidreq()."\">".get_lang("No")."</a>
  5634. <a href=\"".api_get_self()."?".api_get_cidreq(
  5635. )."&action=delete&title=".api_htmlentities(
  5636. urlencode($page)
  5637. )."&delete=yes\">".
  5638. get_lang("Yes")."</a>";
  5639. if (!isset($_GET['delete'])) {
  5640. Display::addFlash(
  5641. Display::return_message($message, 'warning', false)
  5642. );
  5643. }
  5644. if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
  5645. $result = self::deletePage(
  5646. $page,
  5647. $course_id,
  5648. $groupfilter,
  5649. $condition_session
  5650. );
  5651. if ($result) {
  5652. Display::addFlash(
  5653. Display::return_message(
  5654. get_lang('WikiPageDeleted'),
  5655. 'confirmation',
  5656. false
  5657. )
  5658. );
  5659. }
  5660. }
  5661. } else {
  5662. Display::addFlash(
  5663. Display::return_message(
  5664. get_lang('OnlyAdminDeletePageWiki'),
  5665. 'normal',
  5666. false
  5667. )
  5668. );
  5669. }
  5670. }
  5671. /**
  5672. * Edit page
  5673. */
  5674. public function editPage()
  5675. {
  5676. $tbl_wiki = $this->tbl_wiki;
  5677. $tbl_wiki_conf = $this->tbl_wiki_conf;
  5678. $condition_session = $this->condition_session;
  5679. $groupfilter = $this->groupfilter;
  5680. $page = $this->page;
  5681. $course_id = $this->course_id;
  5682. $groupId = $this->group_id;
  5683. $userId = api_get_user_id();
  5684. if (api_get_session_id() != 0 &&
  5685. api_is_allowed_to_session_edit(false, true) == false
  5686. ) {
  5687. api_not_allowed();
  5688. }
  5689. $sql = 'SELECT *
  5690. FROM '.$tbl_wiki.' w INNER JOIN '.$tbl_wiki_conf.' c
  5691. ON (w.c_id = c.c_id AND w.page_id = c.page_id)
  5692. WHERE
  5693. w.c_id = '.$course_id.' AND
  5694. w.reflink= "'.Database::escape_string($page).'" AND
  5695. w.'.$groupfilter.$condition_session.'
  5696. ORDER BY id DESC';
  5697. $result = Database::query($sql);
  5698. $row = Database::fetch_array($result);
  5699. // we do not need a while loop since we are always displaying the last version
  5700. if ($row['content'] == '' && $row['title'] == '' && $page == '') {
  5701. Display::addFlash(
  5702. Display::return_message(
  5703. get_lang('MustSelectPage'),
  5704. 'error',
  5705. false
  5706. )
  5707. );
  5708. return;
  5709. } elseif ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
  5710. // Table structure for better export to pdf
  5711. $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
  5712. $default_table_for_content_End = '</td></tr></table>';
  5713. $content = $default_table_for_content_Start.sprintf(
  5714. get_lang('DefaultContent'),
  5715. api_get_path(WEB_IMG_PATH)
  5716. ).$default_table_for_content_End;
  5717. $title = get_lang('DefaultTitle');
  5718. $page_id = 0;
  5719. } else {
  5720. $content = api_html_entity_decode($row['content']);
  5721. $title = api_html_entity_decode($row['title']);
  5722. $page_id = $row['page_id'];
  5723. }
  5724. // Only teachers and platform admin can edit the index page.
  5725. // Only teachers and platform admin can edit an assignment teacher.
  5726. // And users in groups
  5727. if (($row['reflink'] == 'index' || $row['reflink'] == '' || $row['assignment'] == 1) &&
  5728. (!api_is_allowed_to_edit(
  5729. false,
  5730. true
  5731. ) && $groupId == 0) && !api_is_allowed_in_course()
  5732. ) {
  5733. Display::addFlash(
  5734. Display::return_message(
  5735. get_lang('OnlyEditPagesCourseManager'),
  5736. 'error'
  5737. )
  5738. );
  5739. } else {
  5740. $PassEdit = false;
  5741. // Check if is a wiki group
  5742. if (!empty($groupId)) {
  5743. $groupInfo = GroupManager::get_group_properties($groupId);
  5744. //Only teacher, platform admin and group members can edit a wiki group
  5745. if (api_is_allowed_to_edit(false, true) ||
  5746. api_is_platform_admin() ||
  5747. GroupManager::is_user_in_group($userId, $groupInfo)
  5748. ) {
  5749. $PassEdit = true;
  5750. } else {
  5751. Display::addFlash(
  5752. Display::return_message(
  5753. get_lang('OnlyEditPagesGroupMembers')
  5754. )
  5755. );
  5756. }
  5757. } else {
  5758. $PassEdit = true;
  5759. }
  5760. $icon_assignment = null;
  5761. // check if is a assignment
  5762. if ($row['assignment'] == 1) {
  5763. Display::addFlash(
  5764. Display::return_message(get_lang('EditAssignmentWarning'))
  5765. );
  5766. $icon_assignment = Display::return_icon(
  5767. 'wiki_assignment.png',
  5768. get_lang('AssignmentDescExtra'),
  5769. '',
  5770. ICON_SIZE_SMALL
  5771. );
  5772. } elseif ($row['assignment'] == 2) {
  5773. $icon_assignment = Display::return_icon(
  5774. 'wiki_work.png',
  5775. get_lang('AssignmentWorkExtra'),
  5776. '',
  5777. ICON_SIZE_SMALL
  5778. );
  5779. if (($userId == $row['user_id']) == false) {
  5780. if (api_is_allowed_to_edit(
  5781. false,
  5782. true
  5783. ) || api_is_platform_admin()) {
  5784. $PassEdit = true;
  5785. } else {
  5786. Display::addFlash(
  5787. Display::return_message(
  5788. get_lang('LockByTeacher'),
  5789. 'warning'
  5790. )
  5791. );
  5792. $PassEdit = false;
  5793. }
  5794. } else {
  5795. $PassEdit = true;
  5796. }
  5797. }
  5798. if ($PassEdit) {
  5799. //show editor if edit is allowed <<<<<
  5800. if ($row['editlock'] == 1 &&
  5801. (api_is_allowed_to_edit(false, true) == false ||
  5802. api_is_platform_admin() == false)
  5803. ) {
  5804. Display::addFlash(
  5805. Display::return_message(
  5806. get_lang('PageLockedExtra')
  5807. )
  5808. );
  5809. } else {
  5810. // Check tasks
  5811. if (!empty($row['startdate_assig']) && time() <
  5812. api_strtotime($row['startdate_assig'])
  5813. ) {
  5814. $message = get_lang(
  5815. 'TheTaskDoesNotBeginUntil'
  5816. ).': '.api_get_local_time($row['startdate_assig']);
  5817. Display::addFlash(
  5818. Display::return_message(
  5819. $message,
  5820. 'warning'
  5821. )
  5822. );
  5823. if (!api_is_allowed_to_edit(false, true)) {
  5824. $this->redirectHome();
  5825. }
  5826. }
  5827. if (!empty($row['enddate_assig']) &&
  5828. time() > strtotime($row['enddate_assig']) &&
  5829. $row['delayedsubmit'] == 0
  5830. ) {
  5831. $message = get_lang(
  5832. 'TheDeadlineHasBeenCompleted'
  5833. ).': '.api_get_local_time($row['enddate_assig']);
  5834. Display::addFlash(
  5835. Display::return_message(
  5836. $message,
  5837. 'warning'
  5838. )
  5839. );
  5840. if (!api_is_allowed_to_edit(false, true)) {
  5841. $this->redirectHome();
  5842. }
  5843. }
  5844. if (!empty($row['max_version']) && $row['version'] >= $row['max_version']) {
  5845. $message = get_lang('HasReachedMaxiNumVersions');
  5846. Display::addFlash(
  5847. Display::return_message(
  5848. $message,
  5849. 'warning'
  5850. )
  5851. );
  5852. if (!api_is_allowed_to_edit(false, true)) {
  5853. $this->redirectHome();
  5854. }
  5855. }
  5856. if (!empty($row['max_text']) && $row['max_text'] <= self::word_count(
  5857. $row['content']
  5858. )) {
  5859. $message = get_lang('HasReachedMaxNumWords');
  5860. Display::addFlash(
  5861. Display::return_message(
  5862. $message,
  5863. 'warning'
  5864. )
  5865. );
  5866. if (!api_is_allowed_to_edit(false, true)) {
  5867. $this->redirectHome();
  5868. }
  5869. }
  5870. if (!empty($row['task'])) {
  5871. //previous change 0 by text
  5872. if (!empty($row['startdate_assig'])) {
  5873. $message_task_startdate = get_lang('No');
  5874. } else {
  5875. $message_task_startdate = api_get_local_time(
  5876. $row['startdate_assig']
  5877. );
  5878. }
  5879. if (!empty($row['enddate_assig'])) {
  5880. $message_task_enddate = get_lang('No');
  5881. } else {
  5882. $message_task_enddate = api_get_local_time(
  5883. $row['enddate_assig']
  5884. );
  5885. }
  5886. if ($row['delayedsubmit'] == 0) {
  5887. $message_task_delayedsubmit = get_lang('No');
  5888. } else {
  5889. $message_task_delayedsubmit = get_lang('Yes');
  5890. }
  5891. if ($row['max_version'] == 0) {
  5892. $message_task_max_version = get_lang('No');
  5893. } else {
  5894. $message_task_max_version = $row['max_version'];
  5895. }
  5896. if ($row['max_text'] == 0) {
  5897. $message_task_max_text = get_lang('No');
  5898. } else {
  5899. $message_task_max_text = $row['max_text'];
  5900. }
  5901. // Comp message
  5902. $message_task = '<b>'.get_lang(
  5903. 'DescriptionOfTheTask'
  5904. ).'</b><p>'.$row['task'].'</p><hr>';
  5905. $message_task .= '<p>'.get_lang(
  5906. 'StartDate'
  5907. ).': '.$message_task_startdate.'</p>';
  5908. $message_task .= '<p>'.get_lang(
  5909. 'EndDate'
  5910. ).': '.$message_task_enddate;
  5911. $message_task .= ' ('.get_lang(
  5912. 'AllowLaterSends'
  5913. ).') '.$message_task_delayedsubmit.'</p>';
  5914. $message_task .= '<p>'.get_lang(
  5915. 'OtherSettings'
  5916. ).': '.get_lang(
  5917. 'NMaxVersion'
  5918. ).': '.$message_task_max_version;
  5919. $message_task .= ' '.get_lang(
  5920. 'NMaxWords'
  5921. ).': '.$message_task_max_text;
  5922. // Display message
  5923. Display::addFlash(
  5924. Display::return_message(
  5925. $message_task
  5926. )
  5927. );
  5928. }
  5929. $feedback_message = '';
  5930. if ($row['progress'] == $row['fprogress1'] && !empty($row['fprogress1'])) {
  5931. $feedback_message = '<b>'.get_lang(
  5932. 'Feedback'
  5933. ).'</b><p>'.api_htmlentities(
  5934. $row['feedback1']
  5935. ).'</p>';
  5936. } elseif ($row['progress'] == $row['fprogress2'] && !empty($row['fprogress2'])) {
  5937. $feedback_message = '<b>'.get_lang(
  5938. 'Feedback'
  5939. ).'</b><p>'.api_htmlentities(
  5940. $row['feedback2']
  5941. ).'</p>';
  5942. } elseif ($row['progress'] == $row['fprogress3'] && !empty($row['fprogress3'])) {
  5943. $feedback_message = '<b>'.get_lang(
  5944. 'Feedback'
  5945. ).'</b><p>'.api_htmlentities(
  5946. $row['feedback3']
  5947. ).'</p>';
  5948. }
  5949. if (!empty($feedback_message)) {
  5950. Display::addFlash(
  5951. Display::return_message(
  5952. $feedback_message
  5953. )
  5954. );
  5955. }
  5956. // Previous checking for concurrent editions
  5957. if ($row['is_editing'] == 0) {
  5958. Display::addFlash(
  5959. Display::return_message(
  5960. get_lang('WarningMaxEditingTime')
  5961. )
  5962. );
  5963. $time_edit = api_get_utc_datetime();
  5964. $sql = 'UPDATE '.$tbl_wiki.' SET
  5965. is_editing = "'.$userId.'",
  5966. time_edit = "'.$time_edit.'"
  5967. WHERE c_id = '.$course_id.' AND id="'.$row['id'].'"';
  5968. Database::query($sql);
  5969. } elseif ($row['is_editing'] != $userId) {
  5970. $timestamp_edit = strtotime($row['time_edit']);
  5971. $time_editing = time() - $timestamp_edit;
  5972. $max_edit_time = 1200; // 20 minutes
  5973. $rest_time = $max_edit_time - $time_editing;
  5974. $userinfo = api_get_user_info($row['is_editing']);
  5975. if ($userinfo !== false) {
  5976. $is_being_edited = get_lang(
  5977. 'ThisPageisBeginEditedBy'
  5978. ).' '.UserManager::getUserProfileLink(
  5979. $userinfo
  5980. ).'
  5981. '.get_lang(
  5982. 'ThisPageisBeginEditedTryLater'
  5983. ).' '.date("i", $rest_time).' '.get_lang(
  5984. 'MinMinutes'
  5985. ).'';
  5986. }
  5987. Display::addFlash(
  5988. Display::return_message(
  5989. $is_being_edited,
  5990. 'normal',
  5991. false
  5992. )
  5993. );
  5994. $this->redirectHome();
  5995. }
  5996. // Form.
  5997. $url = api_get_self().'?action=edit&title='.urlencode(
  5998. $page
  5999. ).'&session_id='.api_get_session_id(
  6000. ).'&group_id='.api_get_group_id().'&'.api_get_cidreq();
  6001. $form = new FormValidator('wiki', 'post', $url);
  6002. $form->addElement(
  6003. 'header',
  6004. $icon_assignment.str_repeat(
  6005. '&nbsp;',
  6006. 3
  6007. ).api_htmlentities($title)
  6008. );
  6009. self::setForm($form, $row);
  6010. $form->addElement('hidden', 'title');
  6011. $form->addButtonSave(get_lang('Save'), 'SaveWikiChange');
  6012. $row['title'] = $title;
  6013. $row['page_id'] = $page_id;
  6014. $row['reflink'] = $page;
  6015. $row['content'] = $content;
  6016. $form->setDefaults($row);
  6017. $form->display();
  6018. // Saving a change
  6019. if ($form->validate()) {
  6020. $versionFromSession = Session::read('_version');
  6021. if (empty($_POST['title'])) {
  6022. Display::addFlash(
  6023. Display::return_message(
  6024. get_lang("NoWikiPageTitle"),
  6025. 'error'
  6026. )
  6027. );
  6028. } elseif (!self::double_post($_POST['wpost_id'])) {
  6029. //double post
  6030. } elseif ($_POST['version'] != '' && $versionFromSession != 0 && $_POST['version'] != $versionFromSession) {
  6031. //prevent concurrent users and double version
  6032. Display::addFlash(
  6033. Display::return_message(
  6034. get_lang("EditedByAnotherUser"),
  6035. 'error'
  6036. )
  6037. );
  6038. } else {
  6039. $returnMessage = self::save_wiki(
  6040. $form->exportValues()
  6041. );
  6042. Display::addFlash(
  6043. Display::return_message(
  6044. $returnMessage,
  6045. 'confirmation'
  6046. )
  6047. );
  6048. }
  6049. $wikiData = self::getWikiData();
  6050. $redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq(
  6051. );
  6052. header('Location: '.$redirectUrl);
  6053. exit;
  6054. }
  6055. }
  6056. }
  6057. }
  6058. }
  6059. /**
  6060. * Get history
  6061. */
  6062. public function getHistory()
  6063. {
  6064. $tbl_wiki = $this->tbl_wiki;
  6065. $condition_session = $this->condition_session;
  6066. $groupfilter = $this->groupfilter;
  6067. $page = $this->page;
  6068. $course_id = $this->course_id;
  6069. $session_id = $this->session_id;
  6070. $userId = api_get_user_id();
  6071. if (!$_GET['title']) {
  6072. Display::addFlash(
  6073. Display::return_message(
  6074. get_lang("MustSelectPage"),
  6075. 'error',
  6076. false
  6077. )
  6078. );
  6079. return;
  6080. }
  6081. /* First, see the property visibility that is at the last register and
  6082. therefore we should select descending order.
  6083. But to give ownership to each record,
  6084. this is no longer necessary except for the title. TODO: check this*/
  6085. $sql = 'SELECT * FROM '.$tbl_wiki.'
  6086. WHERE
  6087. c_id = '.$course_id.' AND
  6088. reflink="'.Database::escape_string($page).'" AND
  6089. '.$groupfilter.$condition_session.'
  6090. ORDER BY id DESC';
  6091. $result = Database::query($sql);
  6092. $KeyVisibility = null;
  6093. $KeyAssignment = null;
  6094. $KeyTitle = null;
  6095. $KeyUserId = null;
  6096. while ($row = Database::fetch_array($result)) {
  6097. $KeyVisibility = $row['visibility'];
  6098. $KeyAssignment = $row['assignment'];
  6099. $KeyTitle = $row['title'];
  6100. $KeyUserId = $row['user_id'];
  6101. }
  6102. $icon_assignment = null;
  6103. if ($KeyAssignment == 1) {
  6104. $icon_assignment = Display::return_icon(
  6105. 'wiki_assignment.png',
  6106. get_lang('AssignmentDescExtra'),
  6107. '',
  6108. ICON_SIZE_SMALL
  6109. );
  6110. } elseif ($KeyAssignment == 2) {
  6111. $icon_assignment = Display::return_icon(
  6112. 'wiki_work.png',
  6113. get_lang('AssignmentWorkExtra'),
  6114. '',
  6115. ICON_SIZE_SMALL
  6116. );
  6117. }
  6118. // Second, show
  6119. //if the page is hidden and is a job only sees its author and professor
  6120. if ($KeyVisibility == 1 ||
  6121. api_is_allowed_to_edit(false, true) ||
  6122. api_is_platform_admin() ||
  6123. (
  6124. $KeyAssignment == 2 && $KeyVisibility == 0 &&
  6125. ($userId == $KeyUserId)
  6126. )
  6127. ) {
  6128. // We show the complete history
  6129. if (!isset($_POST['HistoryDifferences']) &&
  6130. !isset($_POST['HistoryDifferences2'])
  6131. ) {
  6132. $sql = 'SELECT * FROM '.$tbl_wiki.'
  6133. WHERE
  6134. c_id = '.$course_id.' AND
  6135. reflink="'.Database::escape_string($page).'" AND
  6136. '.$groupfilter.$condition_session.'
  6137. ORDER BY id DESC';
  6138. $result = Database::query($sql);
  6139. $title = $_GET['title'];
  6140. $group_id = api_get_group_id();
  6141. echo '<div id="wikititle">';
  6142. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.api_htmlentities(
  6143. $KeyTitle
  6144. );
  6145. echo '</div>';
  6146. echo '<form id="differences" method="POST" action="index.php?'.api_get_cidreq(
  6147. ).'&action=history&title='.api_htmlentities(
  6148. urlencode($title)
  6149. ).'&session_id='.api_htmlentities(
  6150. $session_id
  6151. ).'&group_id='.api_htmlentities($group_id).'">';
  6152. echo '<ul style="list-style-type: none;">';
  6153. echo '<br/>';
  6154. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.
  6155. get_lang('ShowDifferences').' '.get_lang(
  6156. 'LinesDiff'
  6157. ).'</button>';
  6158. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.
  6159. get_lang('ShowDifferences').' '.get_lang(
  6160. 'WordsDiff'
  6161. ).'</button>';
  6162. echo '<br/><br/>';
  6163. $counter = 0;
  6164. $total_versions = Database::num_rows($result);
  6165. while ($row = Database::fetch_array($result)) {
  6166. $userinfo = api_get_user_info($row['user_id']);
  6167. $username = api_htmlentities(
  6168. sprintf(get_lang('LoginX'), $userinfo['username']),
  6169. ENT_QUOTES
  6170. );
  6171. echo '<li style="margin-bottom: 5px;">';
  6172. ($counter == 0) ? $oldstyle = 'style="visibility: hidden;"' : $oldstyle = '';
  6173. ($counter == 0) ? $newchecked = ' checked' : $newchecked = '';
  6174. ($counter == $total_versions - 1) ? $newstyle = 'style="visibility: hidden;"' : $newstyle = '';
  6175. ($counter == 1) ? $oldchecked = ' checked' : $oldchecked = '';
  6176. echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
  6177. echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
  6178. echo '<a href="'.api_get_self(
  6179. ).'?action=showpage&title='.api_htmlentities(
  6180. urlencode($page)
  6181. ).'&view='.$row['id'].'">';
  6182. echo '<a href="'.api_get_self().'?'.api_get_cidreq(
  6183. ).'&action=showpage&title='.api_htmlentities(
  6184. urlencode($page)
  6185. ).'&view='.$row['id'].'">';
  6186. echo api_get_local_time(
  6187. $row['dtime']
  6188. );
  6189. echo '</a>';
  6190. echo ' ('.get_lang('Version').' '.$row['version'].')';
  6191. echo ' '.get_lang('By').' ';
  6192. if ($userinfo !== false) {
  6193. echo UserManager::getUserProfileLink($userinfo);
  6194. } else {
  6195. echo get_lang('Anonymous').' ('.api_htmlentities(
  6196. $row['user_ip']
  6197. ).')';
  6198. }
  6199. echo ' ( '.get_lang('Progress').': '.api_htmlentities(
  6200. $row['progress']
  6201. ).'%, ';
  6202. $comment = $row['comment'];
  6203. if (!empty($comment)) {
  6204. $comment = api_substr($comment, 0, 100);
  6205. if ($comment !== false) {
  6206. $comment = api_htmlentities($comment);
  6207. echo get_lang('Comments').': '.$comment;
  6208. if (api_strlen($row['comment']) > 100) {
  6209. echo '... ';
  6210. }
  6211. }
  6212. } else {
  6213. echo get_lang('Comments').': ---';
  6214. }
  6215. echo ' ) </li>';
  6216. $counter++;
  6217. } //end while
  6218. echo '<br/>';
  6219. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang(
  6220. 'ShowDifferences'
  6221. ).' '.get_lang('LinesDiff').'</button>';
  6222. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang(
  6223. 'ShowDifferences'
  6224. ).' '.get_lang('WordsDiff').'</button>';
  6225. echo '</ul></form>';
  6226. } else { // We show the differences between two versions
  6227. $version_old = [];
  6228. if (isset($_POST['old'])) {
  6229. $sql_old = "SELECT * FROM $tbl_wiki
  6230. WHERE c_id = $course_id AND id='".Database::escape_string(
  6231. $_POST['old']
  6232. )."'";
  6233. $result_old = Database::query($sql_old);
  6234. $version_old = Database::fetch_array($result_old);
  6235. }
  6236. $sql_new = "SELECT * FROM $tbl_wiki
  6237. WHERE
  6238. c_id = $course_id AND
  6239. id = '".Database::escape_string($_POST['new'])."'";
  6240. $result_new = Database::query($sql_new);
  6241. $version_new = Database::fetch_array($result_new);
  6242. $oldTime = isset($version_old['dtime']) ? api_get_local_time($version_old['dtime']) : null;
  6243. $oldContent = isset($version_old['content']) ? $version_old['content'] : null;
  6244. if (isset($_POST['HistoryDifferences'])) {
  6245. include 'diff.inc.php';
  6246. //title
  6247. echo '<div id="wikititle">'.api_htmlentities(
  6248. $version_new['title']
  6249. ).'
  6250. <font size="-2"><i>('.get_lang('DifferencesNew').'</i>
  6251. <font style="background-color:#aaaaaa">'.api_get_local_time($version_new['dtime']).'</font>
  6252. <i>'.get_lang('DifferencesOld').'</i>
  6253. <font style="background-color:#aaaaaa">'.$oldTime.'</font>
  6254. ) '.get_lang('Legend').': <span class="diffAdded" >'.get_lang(
  6255. 'WikiDiffAddedLine'
  6256. ).'</span>
  6257. <span class="diffDeleted" >'.get_lang(
  6258. 'WikiDiffDeletedLine'
  6259. ).'</span> <span class="diffMoved">'.get_lang(
  6260. 'WikiDiffMovedLine'
  6261. ).'</span></font>
  6262. </div>';
  6263. }
  6264. if (isset($_POST['HistoryDifferences2'])) {
  6265. //title
  6266. echo '<div id="wikititle">'.api_htmlentities(
  6267. $version_new['title']
  6268. ).'
  6269. <font size="-2"><i>('.get_lang(
  6270. 'DifferencesNew'
  6271. ).'</i> <font style="background-color:#aaaaaa">'.api_get_local_time($version_new['dtime']).'</font>
  6272. <i>'.get_lang(
  6273. 'DifferencesOld'
  6274. ).'</i> <font style="background-color:#aaaaaa">'.$oldTime.'</font>)
  6275. '.get_lang(
  6276. 'Legend'
  6277. ).': <span class="diffAddedTex" >'.get_lang(
  6278. 'WikiDiffAddedTex'
  6279. ).'</span>
  6280. <span class="diffDeletedTex" >'.get_lang(
  6281. 'WikiDiffDeletedTex'
  6282. ).'</span></font></div>';
  6283. }
  6284. if (isset($_POST['HistoryDifferences'])) {
  6285. echo '<table>'.diff(
  6286. $oldContent,
  6287. $version_new['content'],
  6288. true,
  6289. 'format_table_line'
  6290. ).'</table>'; // format_line mode is better for words
  6291. echo '<br />';
  6292. echo '<strong>'.get_lang(
  6293. 'Legend'
  6294. ).'</strong><div class="diff">'."\n";
  6295. echo '<table><tr>';
  6296. echo '<td>';
  6297. echo '</td><td>';
  6298. echo '<span class="diffEqual" >'.get_lang(
  6299. 'WikiDiffUnchangedLine'
  6300. ).'</span><br />';
  6301. echo '<span class="diffAdded" >'.get_lang(
  6302. 'WikiDiffAddedLine'
  6303. ).'</span><br />';
  6304. echo '<span class="diffDeleted" >'.get_lang(
  6305. 'WikiDiffDeletedLine'
  6306. ).'</span><br />';
  6307. echo '<span class="diffMoved" >'.get_lang(
  6308. 'WikiDiffMovedLine'
  6309. ).'</span><br />';
  6310. echo '</td>';
  6311. echo '</tr></table>';
  6312. }
  6313. if (isset($_POST['HistoryDifferences2'])) {
  6314. $lines1 = [strip_tags($oldContent)]; //without <> tags
  6315. $lines2 = [
  6316. strip_tags(
  6317. $version_new['content']
  6318. )
  6319. ]; //without <> tags
  6320. $diff = new Text_Diff($lines1, $lines2);
  6321. $renderer = new Text_Diff_Renderer_inline();
  6322. echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render(
  6323. $diff
  6324. ); // Code inline
  6325. echo '<br />';
  6326. echo '<strong>'.get_lang(
  6327. 'Legend'
  6328. ).'</strong><div class="diff">'."\n";
  6329. echo '<table><tr>';
  6330. echo '<td>';
  6331. echo '</td><td>';
  6332. echo '<span class="diffAddedTex" >'.get_lang(
  6333. 'WikiDiffAddedTex'
  6334. ).'</span><br />';
  6335. echo '<span class="diffDeletedTex" >'.get_lang(
  6336. 'WikiDiffDeletedTex'
  6337. ).'</span><br />';
  6338. echo '</td>';
  6339. echo '</tr></table>';
  6340. }
  6341. }
  6342. }
  6343. }
  6344. /**
  6345. * Get stat tables
  6346. */
  6347. public function getStatsTable()
  6348. {
  6349. $_course = $this->courseInfo;
  6350. $session_id = $this->session_id;
  6351. $groupId = $this->group_id;
  6352. echo '<div class="actions">'.get_lang('More').'</div>';
  6353. echo '<table border="0">';
  6354. echo ' <tr>';
  6355. echo ' <td>';
  6356. echo ' <ul>';
  6357. //Submenu Most active users
  6358. echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mactiveusers&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6359. 'MostActiveUsers'
  6360. ).'</a></li>';
  6361. //Submenu Most visited pages
  6362. echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mvisited&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6363. 'MostVisitedPages'
  6364. ).'</a></li>';
  6365. //Submenu Most changed pages
  6366. echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mostchanged&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6367. 'MostChangedPages'
  6368. ).'</a></li>';
  6369. echo ' </ul>';
  6370. echo ' </td>';
  6371. echo ' <td>';
  6372. echo ' <ul>';
  6373. // Submenu Orphaned pages
  6374. echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=orphaned&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6375. 'OrphanedPages'
  6376. ).'</a></li>';
  6377. // Submenu Wanted pages
  6378. echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=wanted&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6379. 'WantedPages'
  6380. ).'</a></li>';
  6381. // Submenu Most linked pages
  6382. echo '<li><a href="index.php?cidReq='.$_course['code'].'&action=mostlinked&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6383. 'MostLinkedPages'
  6384. ).'</a></li>';
  6385. echo '</ul>';
  6386. echo '</td>';
  6387. echo '<td style="vertical-align:top">';
  6388. echo '<ul>';
  6389. // Submenu Statistics
  6390. if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
  6391. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=statistics&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
  6392. 'Statistics'
  6393. ).'</a></li>';
  6394. }
  6395. echo ' </ul>';
  6396. echo ' </td>';
  6397. echo ' </tr>';
  6398. echo '</table>';
  6399. }
  6400. /**
  6401. * Kind of controller
  6402. * @param string $action
  6403. */
  6404. public function handleAction($action)
  6405. {
  6406. $page = $this->page;
  6407. switch ($action) {
  6408. case 'export_to_pdf':
  6409. if (isset($_GET['wiki_id'])) {
  6410. self::export_to_pdf($_GET['wiki_id'], api_get_course_id());
  6411. break;
  6412. }
  6413. break;
  6414. case 'export2doc':
  6415. if (isset($_GET['wiki_id'])) {
  6416. $export2doc = self::export2doc($_GET['wiki_id']);
  6417. if ($export2doc) {
  6418. Display::addFlash(
  6419. Display::return_message(
  6420. get_lang('ThePageHasBeenExportedToDocArea'),
  6421. 'confirmation',
  6422. false
  6423. )
  6424. );
  6425. }
  6426. }
  6427. break;
  6428. case 'restorepage':
  6429. self::restorePage();
  6430. break;
  6431. case 'more':
  6432. self::getStatsTable();
  6433. break;
  6434. case 'statistics':
  6435. self::getStats();
  6436. break;
  6437. case 'mactiveusers':
  6438. self::getActiveUsers($action);
  6439. break;
  6440. case 'usercontrib':
  6441. self::getUserContributions($_GET['user_id'], $action);
  6442. break;
  6443. case 'mostchanged':
  6444. $this->getMostChangedPages($action);
  6445. break;
  6446. case 'mvisited':
  6447. self::getMostVisited();
  6448. break;
  6449. case 'wanted':
  6450. $this->getWantedPages();
  6451. break;
  6452. case 'orphaned':
  6453. self::getOrphaned();
  6454. break;
  6455. case 'mostlinked':
  6456. self::getMostLinked();
  6457. break;
  6458. case 'delete':
  6459. self::deletePageWarning($page);
  6460. break;
  6461. case 'deletewiki':
  6462. $title = '<div class="actions">'.get_lang(
  6463. 'DeleteWiki'
  6464. ).'</div>';
  6465. if (api_is_allowed_to_edit(
  6466. false,
  6467. true
  6468. ) || api_is_platform_admin()) {
  6469. $message = get_lang('ConfirmDeleteWiki');
  6470. $message .= '<p>
  6471. <a href="index.php?'.api_get_cidreq().'">'.get_lang(
  6472. 'No'
  6473. ).'</a>
  6474. &nbsp;&nbsp;|&nbsp;&nbsp;
  6475. <a href="'.api_get_self().'?'.api_get_cidreq(
  6476. ).'&action=deletewiki&delete=yes">'.
  6477. get_lang('Yes').'</a>
  6478. </p>';
  6479. if (!isset($_GET['delete'])) {
  6480. Display::addFlash(
  6481. $title.Display::return_message(
  6482. $message,
  6483. 'warning',
  6484. false
  6485. )
  6486. );
  6487. }
  6488. } else {
  6489. Display::addFlash(
  6490. Display::return_message(
  6491. get_lang("OnlyAdminDeleteWiki"),
  6492. 'normal',
  6493. false
  6494. )
  6495. );
  6496. }
  6497. if (api_is_allowed_to_edit(
  6498. false,
  6499. true
  6500. ) || api_is_platform_admin()) {
  6501. if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
  6502. $return_message = self::delete_wiki();
  6503. Display::addFlash(
  6504. Display::return_message(
  6505. $return_message,
  6506. 'confirmation',
  6507. false
  6508. )
  6509. );
  6510. $this->redirectHome();
  6511. }
  6512. }
  6513. break;
  6514. case 'searchpages':
  6515. self::getSearchPages($action);
  6516. break;
  6517. case 'links':
  6518. self::getLinks($page);
  6519. break;
  6520. case 'addnew':
  6521. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(
  6522. false,
  6523. true
  6524. ) == false) {
  6525. api_not_allowed();
  6526. }
  6527. $groupInfo = GroupManager::get_group_properties(
  6528. api_get_group_id()
  6529. );
  6530. echo '<div class="actions">'.get_lang('AddNew').'</div>';
  6531. echo '<br/>';
  6532. //first, check if page index was created. chektitle=false
  6533. if (self::checktitle('index')) {
  6534. if (api_is_allowed_to_edit(false, true) ||
  6535. api_is_platform_admin() ||
  6536. GroupManager::is_user_in_group(
  6537. api_get_user_id(),
  6538. $groupInfo
  6539. ) ||
  6540. api_is_allowed_in_course()
  6541. ) {
  6542. Display::addFlash(
  6543. Display::return_message(
  6544. get_lang('GoAndEditMainPage'),
  6545. 'normal',
  6546. false
  6547. )
  6548. );
  6549. } else {
  6550. Display::addFlash(
  6551. Display::return_message(
  6552. get_lang('WikiStandBy'),
  6553. 'normal',
  6554. false
  6555. )
  6556. );
  6557. }
  6558. } elseif (self::check_addnewpagelock(
  6559. ) == 0 && (api_is_allowed_to_edit(
  6560. false,
  6561. true
  6562. ) == false || api_is_platform_admin() == false)) {
  6563. Display::addFlash(
  6564. Display::return_message(
  6565. get_lang('AddPagesLocked'),
  6566. 'error',
  6567. false
  6568. )
  6569. );
  6570. } else {
  6571. $groupInfo = GroupManager::get_group_properties(
  6572. api_get_group_id()
  6573. );
  6574. if (api_is_allowed_to_edit(false, true) ||
  6575. api_is_platform_admin() ||
  6576. GroupManager::is_user_in_group(
  6577. api_get_user_id(),
  6578. $groupInfo
  6579. ) ||
  6580. $_GET['group_id'] == 0
  6581. ) {
  6582. self::display_new_wiki_form();
  6583. } else {
  6584. Display::addFlash(
  6585. Display::return_message(
  6586. get_lang('OnlyAddPagesGroupMembers'),
  6587. 'normal',
  6588. false
  6589. )
  6590. );
  6591. }
  6592. }
  6593. break;
  6594. case 'show':
  6595. self::display_wiki_entry($page);
  6596. break;
  6597. case 'showpage':
  6598. self::display_wiki_entry($page);
  6599. break;
  6600. case 'edit':
  6601. self::editPage();
  6602. break;
  6603. case 'history':
  6604. self::getHistory();
  6605. break;
  6606. case 'recentchanges':
  6607. self::recentChanges($page, $action);
  6608. break;
  6609. case 'allpages':
  6610. self::allPages($action);
  6611. break;
  6612. case 'discuss':
  6613. self::getDiscuss($page);
  6614. break;
  6615. case 'export_to_doc_file':
  6616. self::exportTo($_GET['id'], 'odt');
  6617. exit;
  6618. break;
  6619. }
  6620. }
  6621. /**
  6622. * Redirect to home
  6623. */
  6624. public function redirectHome()
  6625. {
  6626. $redirectUrl = $this->url.'&action=showpage&title=index';
  6627. header('Location: '.$redirectUrl.'&'.api_get_cidreq());
  6628. exit;
  6629. }
  6630. /**
  6631. * Export wiki content in a ODF
  6632. * @param int $id
  6633. * @param string int
  6634. * @return bool
  6635. */
  6636. public function exportTo($id, $format = 'doc')
  6637. {
  6638. $data = self::getWikiDataFromDb($id);
  6639. if (isset($data['content']) && !empty($data['content'])) {
  6640. Export::htmlToOdt($data['content'], $data['reflink'], $format);
  6641. }
  6642. return false;
  6643. }
  6644. }