wiki.inc.php 276 KB

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