wiki.inc.php 272 KB

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