wiki.inc.php 272 KB

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