wiki.inc.php 272 KB

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