wiki.inc.php 256 KB

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