1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Component\Filesystem\Data;
- use ChamiloSession as Session;
- /**
- * Class Wiki
- * Functions library for the wiki tool.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
- * @author Julio Montoya <gugli100@gmail.com> using the pdf.lib.php library
- *
- * @package chamilo.wiki
- */
- class Wiki
- {
- public $tbl_wiki;
- public $tbl_wiki_discuss;
- public $tbl_wiki_mailcue;
- public $tbl_wiki_conf;
- public $session_id = null;
- public $course_id = null;
- public $condition_session = null;
- public $group_id;
- public $assig_user_id;
- public $groupfilter = 'group_id=0';
- public $courseInfo;
- public $charset;
- public $page;
- public $action;
- public $wikiData = [];
- public $url;
- /**
- * Constructor.
- */
- public function __construct()
- {
- // Database table definition
- $this->tbl_wiki = Database::get_course_table(TABLE_WIKI);
- $this->tbl_wiki_discuss = Database::get_course_table(
- TABLE_WIKI_DISCUSS
- );
- $this->tbl_wiki_mailcue = Database::get_course_table(
- TABLE_WIKI_MAILCUE
- );
- $this->tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
- $this->session_id = api_get_session_id();
- $this->condition_session = api_get_session_condition($this->session_id);
- $this->course_id = api_get_course_int_id();
- $this->group_id = api_get_group_id();
- if (!empty($this->group_id)) {
- $this->groupfilter = ' group_id="'.$this->group_id.'"';
- }
- $this->courseInfo = api_get_course_info();
- $this->url = api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq();
- }
- /**
- * Check whether this title is already used.
- *
- * @param string $link
- *
- * @return bool False if title is already taken
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- */
- public function checktitle($link)
- {
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($link).'" AND
- '.$groupfilter.$condition_session.'';
- $result = Database::query($sql);
- $num = Database::num_rows($result);
- // the value has not been found and is this available
- if ($num == 0) {
- return true;
- } else {
- // the value has been found
- return false;
- }
- }
- /**
- * check wikilinks that has a page.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @param string $input
- *
- * @return string
- */
- public function links_to($input)
- {
- $input_array = preg_split(
- "/(\[\[|\]\])/",
- $input,
- -1,
- PREG_SPLIT_DELIM_CAPTURE
- );
- $all_links = [];
- foreach ($input_array as $key => $value) {
- if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' &&
- isset($input_array[$key + 1]) && $input_array[$key + 1] == ']]'
- ) {
- if (api_strpos($value, "|") !== false) {
- $full_link_array = explode("|", $value);
- $link = trim($full_link_array[0]);
- $title = trim($full_link_array[1]);
- } else {
- $link = trim($value);
- $title = trim($value);
- }
- unset($input_array[$key - 1]);
- unset($input_array[$key + 1]);
- //replace blank spaces by _ within the links. But to remove links at the end add a blank space
- $all_links[] = Database::escape_string(
- str_replace(' ', '_', $link)
- ).' ';
- }
- }
- $output = implode($all_links);
- return $output;
- }
- /**
- * detect and add style to external links.
- *
- * @author Juan Carlos Raña Trabado
- */
- public function detect_external_link($input)
- {
- $exlink = 'href=';
- $exlinkStyle = 'class="wiki_link_ext" href=';
- $output = str_replace($exlink, $exlinkStyle, $input);
- return $output;
- }
- /**
- * detect and add style to anchor links.
- *
- * @author Juan Carlos Raña Trabado
- */
- public function detect_anchor_link($input)
- {
- $anchorlink = 'href="#';
- $anchorlinkStyle = 'class="wiki_anchor_link" href="#';
- $output = str_replace($anchorlink, $anchorlinkStyle, $input);
- return $output;
- }
- /**
- * detect and add style to mail links
- * author Juan Carlos Raña Trabado.
- */
- public function detect_mail_link($input)
- {
- $maillink = 'href="mailto';
- $maillinkStyle = 'class="wiki_mail_link" href="mailto';
- $output = str_replace($maillink, $maillinkStyle, $input);
- return $output;
- }
- /**
- * detect and add style to ftp links.
- *
- * @author Juan Carlos Raña Trabado
- */
- public function detect_ftp_link($input)
- {
- $ftplink = 'href="ftp';
- $ftplinkStyle = 'class="wiki_ftp_link" href="ftp';
- $output = str_replace($ftplink, $ftplinkStyle, $input);
- return $output;
- }
- /**
- * detect and add style to news links.
- *
- * @author Juan Carlos Raña Trabado
- */
- public function detect_news_link($input)
- {
- $newslink = 'href="news';
- $newslinkStyle = 'class="wiki_news_link" href="news';
- $output = str_replace($newslink, $newslinkStyle, $input);
- return $output;
- }
- /**
- * detect and add style to irc links.
- *
- * @author Juan Carlos Raña Trabado
- */
- public function detect_irc_link($input)
- {
- $irclink = 'href="irc';
- $irclinkStyle = 'class="wiki_irc_link" href="irc';
- $output = str_replace($irclink, $irclinkStyle, $input);
- return $output;
- }
- /**
- * This function allows users to have [link to a title]-style links like in most regular wikis.
- * It is true that the adding of links is probably the most anoying part of Wiki for the people
- * who know something about the wiki syntax.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- * Improvements [[]] and [[ | ]]by Juan Carlos Raña
- * Improvements internal wiki style and mark group by Juan Carlos Raña
- */
- public function make_wiki_link_clickable($input)
- {
- $groupId = api_get_group_id();
- //now doubles brackets
- $input_array = preg_split(
- "/(\[\[|\]\])/",
- $input,
- -1,
- PREG_SPLIT_DELIM_CAPTURE
- );
- foreach ($input_array as $key => $value) {
- //now doubles brackets
- if (isset($input_array[$key - 1]) &&
- $input_array[$key - 1] == '[[' && $input_array[$key + 1] == ']]'
- ) {
- // now full wikilink
- if (api_strpos($value, "|") !== false) {
- $full_link_array = explode("|", $value);
- $link = trim(strip_tags($full_link_array[0]));
- $title = trim($full_link_array[1]);
- } else {
- $link = trim(strip_tags($value));
- $title = trim($value);
- }
- //if wikilink is homepage
- if ($link == 'index') {
- $title = get_lang('DefaultTitle');
- }
- if ($link == get_lang('DefaultTitle')) {
- $link = 'index';
- }
- // 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
- if (self::checktitle(
- strtolower(str_replace(' ', '_', $link))
- )) {
- $link = api_html_entity_decode($link);
- $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>';
- } else {
- $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>';
- }
- unset($input_array[$key - 1]);
- unset($input_array[$key + 1]);
- }
- }
- $output = implode('', $input_array);
- return $output;
- }
- /**
- * This function saves a change in a wiki page.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- *
- * @param array $values
- *
- * @return language string saying that the changes are stored
- */
- public function save_wiki($values)
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $_course = $this->courseInfo;
- $time = api_get_utc_datetime();
- $session_id = api_get_session_id();
- $groupId = api_get_group_id();
- $userId = api_get_user_id();
- $groupInfo = GroupManager::get_group_properties($groupId);
- $course_id = api_get_course_int_id();
- $_clean = [
- 'task' => '',
- 'feedback1' => '',
- 'feedback2' => '',
- 'feedback3' => '',
- 'fprogress1' => '',
- 'fprogress2' => '',
- 'fprogress3' => '',
- 'max_text' => 0,
- 'max_version' => 0,
- 'delayedsubmit' => '',
- 'assignment' => 0,
- ];
- $pageId = intval($values['page_id']);
- // NOTE: visibility, visibility_disc and ratinglock_disc changes
- // are not made here, but through the interce buttons
- // cleaning the variables
- if (api_get_setting('htmlpurifier_wiki') == 'true') {
- //$purifier = new HTMLPurifier();
- $values['content'] = Security::remove_XSS($values['content']);
- }
- $version = intval($values['version']) + 1;
- $linkTo = self::links_to($values['content']); //and check links content
- //cleaning config variables
- if (!empty($values['task'])) {
- $_clean['task'] = $values['task'];
- }
- if (!empty($values['feedback1']) ||
- !empty($values['feedback2']) ||
- !empty($values['feedback3'])
- ) {
- $_clean['feedback1'] = $values['feedback1'];
- $_clean['feedback2'] = $values['feedback2'];
- $_clean['feedback3'] = $values['feedback3'];
- $_clean['fprogress1'] = $values['fprogress1'];
- $_clean['fprogress2'] = $values['fprogress2'];
- $_clean['fprogress3'] = $values['fprogress3'];
- }
- if (isset($values['initstartdate']) && $values['initstartdate'] == 1) {
- $_clean['startdate_assig'] = $values['startdate_assig'];
- } else {
- $_clean['startdate_assig'] = null;
- }
- if (isset($values['initenddate']) && $values['initenddate'] == 1) {
- $_clean['enddate_assig'] = $values['enddate_assig'];
- } else {
- $_clean['enddate_assig'] = null;
- }
- if (isset($values['delayedsubmit'])) {
- $_clean['delayedsubmit'] = $values['delayedsubmit'];
- }
- if (!empty($values['max_text']) || !empty($values['max_version'])) {
- $_clean['max_text'] = $values['max_text'];
- $_clean['max_version'] = $values['max_version'];
- }
- $values['assignment'] = isset($values['assignment']) ? $values['assignment'] : 0;
- $values['page_id'] = isset($values['page_id']) ? $values['page_id'] : 0;
- $params = [
- 'c_id' => $course_id,
- 'addlock' => 1,
- 'visibility' => 1,
- 'visibility_disc' => 1,
- 'addlock_disc' => 1,
- 'ratinglock_disc' => 1,
- 'page_id' => $pageId,
- 'reflink' => trim($values['reflink']),
- 'title' => trim($values['title']),
- 'content' => $values['content'],
- 'user_id' => $userId,
- 'group_id' => $groupId,
- 'dtime' => $time,
- 'assignment' => $values['assignment'],
- 'comment' => $values['comment'],
- 'progress' => $values['progress'],
- 'version' => $version,
- 'linksto' => $linkTo,
- 'user_ip' => $_SERVER['REMOTE_ADDR'],
- 'session_id' => $session_id,
- 'page_id' => $values['page_id'],
- 'editlock' => 0,
- 'is_editing' => 0,
- 'time_edit' => $time,
- 'tag' => '',
- ];
- $id = Database::insert($tbl_wiki, $params);
- if ($id > 0) {
- $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
- Database::query($sql);
- // insert into item_property
- api_item_property_update(
- $_course,
- TOOL_WIKI,
- $id,
- 'WikiAdded',
- $userId,
- $groupInfo
- );
- if ($values['page_id'] == 0) {
- $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
- WHERE c_id = '.$course_id.' AND iid ="'.$id.'"';
- Database::query($sql);
- }
- }
- // Update wiki config
- if ($values['reflink'] == 'index' && $version == 1) {
- $params = [
- 'c_id' => $course_id,
- 'page_id' => $id,
- 'task' => $_clean['task'],
- 'feedback1' => $_clean['feedback1'],
- 'feedback2' => $_clean['feedback2'],
- 'feedback3' => $_clean['feedback3'],
- 'fprogress1' => $_clean['fprogress1'],
- 'fprogress2' => $_clean['fprogress2'],
- 'fprogress3' => $_clean['fprogress3'],
- 'max_text' => intval($_clean['max_text']),
- 'max_version' => intval($_clean['max_version']),
- 'startdate_assig' => $_clean['startdate_assig'],
- 'enddate_assig' => $_clean['enddate_assig'],
- 'delayedsubmit' => $_clean['delayedsubmit'],
- ];
- Database::insert($tbl_wiki_conf, $params);
- } else {
- $params = [
- 'task' => $_clean['task'],
- 'feedback1' => $_clean['feedback1'],
- 'feedback2' => $_clean['feedback2'],
- 'feedback3' => $_clean['feedback3'],
- 'fprogress1' => $_clean['fprogress1'],
- 'fprogress2' => $_clean['fprogress2'],
- 'fprogress3' => $_clean['fprogress3'],
- 'max_text' => intval($_clean['max_text']),
- 'max_version' => intval($_clean['max_version']),
- 'startdate_assig' => $_clean['startdate_assig'],
- 'enddate_assig' => $_clean['enddate_assig'],
- 'delayedsubmit' => $_clean['delayedsubmit'],
- ];
- Database::update(
- $tbl_wiki_conf,
- $params,
- ['page_id = ? AND c_id = ?' => [$pageId, $course_id]]
- );
- }
- api_item_property_update(
- $_course,
- 'wiki',
- $id,
- 'WikiAdded',
- $userId,
- $groupInfo
- );
- self::check_emailcue($_clean['reflink'], 'P', $time, $userId);
- $this->setWikiData($id);
- return get_lang('Saved');
- }
- /**
- * This function restore a wikipage.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return string Message of success (to be printed on screen)
- */
- public function restore_wikipage(
- $r_page_id,
- $r_reflink,
- $r_title,
- $r_content,
- $r_group_id,
- $r_assignment,
- $r_progress,
- $c_version,
- $r_version,
- $r_linksto
- ) {
- $tbl_wiki = $this->tbl_wiki;
- $_course = $this->courseInfo;
- $r_user_id = api_get_user_id();
- $r_dtime = api_get_utc_datetime();
- $r_version = $r_version + 1;
- $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- $groupInfo = GroupManager::get_group_properties($r_group_id);
- $params = [
- 'c_id' => $course_id,
- 'page_id' => $r_page_id,
- 'reflink' => $r_reflink,
- 'title' => $r_title,
- 'content' => $r_content,
- 'user_id' => $r_user_id,
- 'group_id' => $r_group_id,
- 'dtime' => $r_dtime,
- 'assignment' => $r_assignment,
- 'comment' => $r_comment,
- 'progress' => $r_progress,
- 'version' => $r_version,
- 'linksto' => $r_linksto,
- 'user_ip' => $_SERVER['REMOTE_ADDR'],
- 'session_id' => $session_id,
- ];
- $id = Database::insert($tbl_wiki, $params);
- if ($id) {
- $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
- Database::query($sql);
- api_item_property_update(
- $_course,
- 'wiki',
- $id,
- 'WikiAdded',
- api_get_user_id(),
- $groupInfo
- );
- self::check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id);
- }
- return get_lang('PageRestored');
- }
- /**
- * This function delete a wiki.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return string Message of success (to be printed)
- */
- public function delete_wiki()
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_discuss = $this->tbl_wiki_discuss;
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $conditionSession = $this->condition_session;
- $groupFilter = $this->groupfilter;
- $course_id = $this->course_id;
- $sql = "SELECT page_id FROM $tbl_wiki
- WHERE c_id = $course_id AND $groupFilter $conditionSession
- ORDER BY id DESC";
- $result = Database::query($sql);
- $pageList = Database::store_result($result);
- if ($pageList) {
- foreach ($pageList as $pageData) {
- $pageId = $pageData['page_id'];
- $sql = "DELETE FROM $tbl_wiki_conf
- WHERE c_id = $course_id AND page_id = $pageId";
- Database::query($sql);
- $sql = "DELETE FROM $tbl_wiki_discuss
- WHERE c_id = $course_id AND publication_id = $pageId";
- Database::query($sql);
- }
- }
- $sql = "DELETE FROM $tbl_wiki_mailcue
- WHERE c_id = $course_id AND $groupFilter $conditionSession ";
- Database::query($sql);
- $sql = "DELETE FROM $tbl_wiki
- WHERE c_id = $course_id AND $groupFilter $conditionSession ";
- Database::query($sql);
- return get_lang('WikiDeleted');
- }
- /**
- * This function saves a new wiki page.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- *
- * @todo consider merging this with the function save_wiki into one single function.
- *
- * @return string Message of success
- */
- public function save_new_wiki($values)
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $assig_user_id = $this->assig_user_id;
- $_clean = [];
- // cleaning the variables
- $_clean['assignment'] = '';
- if (isset($values['assignment'])) {
- $_clean['assignment'] = $values['assignment'];
- }
- // session_id
- $session_id = api_get_session_id();
- // Unlike ordinary pages of pages of assignments.
- // Allow create a ordinary page although there is a assignment with the same name
- if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) {
- $page = str_replace(
- ' ',
- '_',
- $values['title']."_uass".$assig_user_id
- );
- } else {
- $page = str_replace(' ', '_', $values['title']);
- }
- $_clean['reflink'] = $page;
- $_clean['title'] = trim($values['title']);
- $_clean['content'] = $values['content'];
- if (api_get_setting('htmlpurifier_wiki') === 'true') {
- $purifier = new HTMLPurifier();
- $_clean['content'] = $purifier->purify($_clean['content']);
- }
- //re-check after strip_tags if the title is empty
- if (empty($_clean['title']) || empty($_clean['reflink'])) {
- return false;
- }
- if ($_clean['assignment'] == 2) {
- //config by default for individual assignment (students)
- //Identifies the user as a creator, not the teacher who created
- $_clean['user_id'] = intval($assig_user_id);
- $_clean['visibility'] = 0;
- $_clean['visibility_disc'] = 0;
- $_clean['ratinglock_disc'] = 0;
- } else {
- $_clean['user_id'] = api_get_user_id();
- $_clean['visibility'] = 1;
- $_clean['visibility_disc'] = 1;
- $_clean['ratinglock_disc'] = 1;
- }
- $_clean['comment'] = $values['comment'];
- $_clean['progress'] = $values['progress'];
- $_clean['version'] = 1;
- $groupId = api_get_group_id();
- $groupInfo = GroupManager::get_group_properties($groupId);
- //check wikilinks
- $_clean['linksto'] = self::links_to($_clean['content']);
- // cleaning config variables
- $_clean['task'] = isset($values['task']) ? $values['task'] : '';
- $_clean['feedback1'] = isset($values['feedback1']) ? $values['feedback1'] : '';
- $_clean['feedback2'] = isset($values['feedback2']) ? $values['feedback2'] : '';
- $_clean['feedback3'] = isset($values['feedback3']) ? $values['feedback3'] : '';
- $_clean['fprogress1'] = isset($values['fprogress1']) ? $values['fprogress1'] : '';
- $_clean['fprogress2'] = isset($values['fprogress2']) ? $values['fprogress2'] : '';
- $_clean['fprogress3'] = isset($values['fprogress3']) ? $values['fprogress3'] : '';
- if (isset($values['initstartdate']) && $values['initstartdate'] == 1) {
- $_clean['startdate_assig'] = $values['startdate_assig'];
- } else {
- $_clean['startdate_assig'] = null;
- }
- if (isset($values['initenddate']) && $values['initenddate'] == 1) {
- $_clean['enddate_assig'] = $values['enddate_assig'];
- } else {
- $_clean['enddate_assig'] = null;
- }
- $_clean['delayedsubmit'] = isset($values['delayedsubmit']) ? $values['delayedsubmit'] : '';
- $_clean['max_text'] = isset($values['max_text']) ? $values['max_text'] : '';
- $_clean['max_version'] = isset($values['max_version']) ? $values['max_version'] : '';
- $course_id = api_get_course_int_id();
- // Filter no _uass
- if (api_strtoupper(trim($values['title'])) === 'INDEX') {
- Display::addFlash(
- Display::return_message(
- get_lang('GoAndEditMainPage'),
- 'warning',
- false
- )
- );
- } else {
- $var = $_clean['reflink'];
- $group_id = intval($_GET['group_id']);
- if (!self::checktitle($var)) {
- return get_lang('WikiPageTitleExist').
- '<a href="index.php?action=edit&title='.$var.'&group_id='.$group_id.'">'.
- $values['title'].'</a>';
- } else {
- $dtime = api_get_utc_datetime();
- $params = [
- 'c_id' => $course_id,
- 'reflink' => $_clean['reflink'],
- 'title' => $_clean['title'],
- 'content' => $_clean['content'],
- 'user_id' => $_clean['user_id'],
- 'group_id' => $groupId,
- 'dtime' => $dtime,
- 'visibility' => $_clean['visibility'],
- 'visibility_disc' => $_clean['visibility_disc'],
- 'ratinglock_disc' => $_clean['ratinglock_disc'],
- 'assignment' => $_clean['assignment'],
- 'comment' => $_clean['comment'],
- 'progress' => $_clean['progress'],
- 'version' => $_clean['version'],
- 'linksto' => $_clean['linksto'],
- 'user_ip' => $_SERVER['REMOTE_ADDR'],
- 'session_id' => $session_id,
- 'addlock_disc' => 1,
- ];
- $id = Database::insert($tbl_wiki, $params);
- if ($id > 0) {
- $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id";
- Database::query($sql);
- //insert into item_property
- api_item_property_update(
- api_get_course_info(),
- TOOL_WIKI,
- $id,
- 'WikiAdded',
- api_get_user_id(),
- $groupInfo
- );
- $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
- WHERE c_id = '.$course_id.' AND id = "'.$id.'"';
- Database::query($sql);
- // insert wiki config
- $params = [
- 'c_id' => $course_id,
- 'page_id' => $id,
- 'task' => $_clean['task'],
- 'feedback1' => $_clean['feedback1'],
- 'feedback2' => $_clean['feedback2'],
- 'feedback3' => $_clean['feedback3'],
- 'fprogress1' => $_clean['fprogress1'],
- 'fprogress2' => $_clean['fprogress2'],
- 'fprogress3' => $_clean['fprogress3'],
- 'max_text' => $_clean['max_text'],
- 'max_version' => $_clean['max_version'],
- 'startdate_assig' => $_clean['startdate_assig'],
- 'enddate_assig' => $_clean['enddate_assig'],
- 'delayedsubmit' => $_clean['delayedsubmit'],
- ];
- Database::insert($tbl_wiki_conf, $params);
- $this->setWikiData($id);
- self::check_emailcue(0, 'A');
- return get_lang('NewWikiSaved');
- }
- }
- }
- }
- /**
- * @param FormValidator $form
- * @param array $row
- */
- public function setForm($form, $row = [])
- {
- $toolBar = api_is_allowed_to_edit(null, true)
- ? [
- 'ToolbarSet' => 'Wiki',
- 'Width' => '100%',
- 'Height' => '400',
- ]
- : [
- 'ToolbarSet' => 'WikiStudent',
- 'Width' => '100%',
- 'Height' => '400',
- 'UserStatus' => 'student',
- ];
- $form->addHtmlEditor(
- 'content',
- get_lang('Content'),
- false,
- false,
- $toolBar
- );
- //$content
- $form->addElement('text', 'comment', get_lang('Comments'));
- $progress = ['', 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
- $form->addElement(
- 'select',
- 'progress',
- get_lang('Progress'),
- $progress
- );
- if ((api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()) &&
- isset($row['reflink']) && $row['reflink'] != 'index'
- ) {
- $form->addElement(
- 'advanced_settings',
- 'advanced_params',
- get_lang('AdvancedParameters')
- );
- $form->addElement(
- 'html',
- '<div id="advanced_params_options" style="display:none">'
- );
- $form->addHtmlEditor(
- 'task',
- get_lang('DescriptionOfTheTask'),
- false,
- false,
- [
- 'ToolbarSet' => 'wiki_task',
- 'Width' => '100%',
- 'Height' => '200',
- ]
- );
- $form->addElement('label', null, get_lang('AddFeedback'));
- $form->addElement('textarea', 'feedback1', get_lang('Feedback1'));
- $form->addElement(
- 'select',
- 'fprogress1',
- get_lang('FProgress'),
- $progress
- );
- $form->addElement('textarea', 'feedback2', get_lang('Feedback2'));
- $form->addElement(
- 'select',
- 'fprogress2',
- get_lang('FProgress'),
- $progress
- );
- $form->addElement('textarea', 'feedback3', get_lang('Feedback3'));
- $form->addElement(
- 'select',
- 'fprogress3',
- get_lang('FProgress'),
- $progress
- );
- $form->addElement(
- 'checkbox',
- 'initstartdate',
- null,
- get_lang('StartDate'),
- ['id' => 'start_date_toggle']
- );
- $style = "display:block";
- $row['initstartdate'] = 1;
- if (empty($row['startdate_assig'])) {
- $style = "display:none";
- $row['initstartdate'] = null;
- }
- $form->addElement(
- 'html',
- '<div id="start_date" style="'.$style.'">'
- );
- $form->addDatePicker('startdate_assig', '');
- $form->addElement('html', '</div>');
- $form->addElement(
- 'checkbox',
- 'initenddate',
- null,
- get_lang('EndDate'),
- ['id' => 'end_date_toggle']
- );
- $style = "display:block";
- $row['initenddate'] = 1;
- if (empty($row['enddate_assig'])) {
- $style = "display:none";
- $row['initenddate'] = null;
- }
- $form->addHtml('<div id="end_date" style="'.$style.'">');
- $form->addDatePicker('enddate_assig', '');
- $form->addHtml('</div>');
- $form->addElement(
- 'checkbox',
- 'delayedsubmit',
- null,
- get_lang('AllowLaterSends')
- );
- $form->addElement('text', 'max_text', get_lang('NMaxWords'));
- $form->addElement('text', 'max_version', get_lang('NMaxVersion'));
- $form->addElement(
- 'checkbox',
- 'assignment',
- null,
- get_lang('CreateAssignmentPage')
- );
- $form->addElement('html', '</div>');
- }
- $form->addElement('hidden', 'page_id');
- $form->addElement('hidden', 'reflink');
- $form->addElement('hidden', 'version');
- $form->addElement('hidden', 'wpost_id', api_get_unique_id());
- }
- /**
- * This function displays the form for adding a new wiki page.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- *
- * @return string html code
- */
- public function display_new_wiki_form()
- {
- $url = api_get_self().'?'.api_get_cidreq(
- ).'&action=addnew&group_id='.api_get_group_id();
- $form = new FormValidator('wiki_new', 'post', $url);
- $form->addElement('text', 'title', get_lang('Title'));
- $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
- self::setForm($form);
- $title = isset($_GET['title']) ? Security::remove_XSS(
- $_GET['title']
- ) : '';
- $form->setDefaults(['title' => $title]);
- $form->addElement('button', 'SaveWikiNew', get_lang('Save'));
- $form->display();
- if ($form->validate()) {
- $values = $form->exportValues();
- if (isset($values['startdate_assig']) &&
- isset($values['enddate_assig']) &&
- strtotime($values['startdate_assig']) > strtotime(
- $values['enddate_assig']
- )
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang("EndDateCannotBeBeforeTheStartDate"),
- 'error',
- false
- )
- );
- } elseif (!self::double_post($_POST['wpost_id'])) {
- //double post
- } else {
- if (isset($values['assignment']) && $values['assignment'] == 1) {
- self::auto_add_page_users($values);
- }
- $return_message = self::save_new_wiki($values);
- if ($return_message == false) {
- Display::addFlash(
- Display::return_message(
- get_lang('NoWikiPageTitle'),
- 'error',
- false
- )
- );
- } else {
- Display::addFlash(
- Display::return_message(
- $return_message,
- 'confirmation',
- false
- )
- );
- }
- $wikiData = self::getWikiData();
- $redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq();
- header('Location: '.$redirectUrl);
- exit;
- }
- }
- }
- /**
- * This function displays a wiki entry.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- * @author Juan Carlos Raña Trabado
- *
- * @param string $newtitle
- *
- * @return string html code
- */
- public function display_wiki_entry($newtitle)
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $page = $this->page;
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- if ($newtitle) {
- $pageMIX = $newtitle; //display the page after it is created
- } else {
- $pageMIX = $page; //display current page
- }
- $filter = null;
- if (isset($_GET['view']) && $_GET['view']) {
- $_clean['view'] = Database::escape_string($_GET['view']);
- $filter = ' AND w.id="'.$_clean['view'].'"';
- }
- // First, check page visibility in the first page version
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($pageMIX).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result, 'ASSOC');
- $KeyVisibility = $row['visibility'];
- // second, show the last version
- $sql = 'SELECT * FROM '.$tbl_wiki.' w
- INNER JOIN '.$tbl_wiki_conf.' wc
- ON (wc.page_id = w.page_id AND wc.c_id = w.c_id)
- WHERE
- w.c_id = '.$course_id.' AND
- w.reflink = "'.Database::escape_string($pageMIX).'" AND
- w.session_id = '.$session_id.' AND
- w.'.$groupfilter.' '.$filter.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- // we do not need a while loop since we are always displaying the last version
- $row = Database::fetch_array($result, 'ASSOC');
- //log users access to wiki (page_id)
- if (!empty($row['page_id'])) {
- Event::addEvent(LOG_WIKI_ACCESS, LOG_WIKI_PAGE_ID, $row['page_id']);
- }
- //update visits
- if ($row['id']) {
- $sql = 'UPDATE '.$tbl_wiki.' SET hits=(hits+1)
- WHERE c_id = '.$course_id.' AND id='.$row['id'].'';
- Database::query($sql);
- }
- $groupInfo = GroupManager::get_group_properties(api_get_group_id());
- // if both are empty and we are displaying the index page then we display the default text.
- if ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- GroupManager::is_user_in_group(api_get_user_id(), $groupInfo) ||
- api_is_allowed_in_course()
- ) {
- //Table structure for better export to pdf
- $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
- $default_table_for_content_End = '</td></tr></table>';
- $content = $default_table_for_content_Start.
- sprintf(
- get_lang('DefaultContent'),
- api_get_path(WEB_IMG_PATH)
- ).
- $default_table_for_content_End;
- $title = get_lang('DefaultTitle');
- } else {
- return Display::addFlash(
- Display::return_message(
- get_lang('WikiStandBy'),
- 'normal',
- false
- )
- );
- }
- } else {
- $content = Security::remove_XSS($row['content']);
- $title = Security::remove_XSS($row['title']);
- }
- //assignment mode: identify page type
- $icon_assignment = null;
- if ($row['assignment'] == 1) {
- $icon_assignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDescExtra'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 2) {
- $icon_assignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- }
- // task mode
- $icon_task = null;
- if (!empty($row['task'])) {
- $icon_task = Display::return_icon(
- 'wiki_task.png',
- get_lang('StandardTask'),
- '',
- ICON_SIZE_SMALL
- );
- }
- // Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
- if ($KeyVisibility == "1" ||
- api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- ($row['assignment'] == 2 && $KeyVisibility == "0" && (api_get_user_id() == $row['user_id'])) ||
- api_is_allowed_in_course()
- ) {
- $actionsLeft = '';
- // menu edit page
- $editLink = '<a href="index.php?'.api_get_cidreq().'&action=edit&title='.api_htmlentities(urlencode($page)).'"'.self::is_active_navigation_tab('edit').'>'.
- Display::return_icon(
- 'edit.png',
- get_lang('EditThisPage'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- if (api_is_allowed_to_edit(false, true)) {
- $actionsLeft .= $editLink;
- } else {
- if ((api_is_allowed_in_course() ||
- GroupManager::is_user_in_group(
- api_get_user_id(),
- $groupInfo
- ))
- ) {
- $actionsLeft .= $editLink;
- } else {
- $actionsLeft .= '';
- }
- }
- $actionsRight = '';
- $protect_page = null;
- $lock_unlock_protect = null;
- // page action: protecting (locking) the page
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- if (self::check_protect_page() == 1) {
- $protect_page = Display::return_icon(
- 'lock.png',
- get_lang('PageLockedExtra'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_protect = 'unlock';
- } else {
- $protect_page = Display::return_icon(
- 'unlock.png',
- get_lang('PageUnlockedExtra'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_protect = 'lock';
- }
- }
- if ($row['id']) {
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_protect.'&title='.api_htmlentities(urlencode($page)).'">'.
- $protect_page.'</a>';
- }
- $visibility_page = null;
- $lock_unlock_visibility = null;
- //page action: visibility
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- if (self::check_visibility_page() == 1) {
- $visibility_page = Display::return_icon(
- 'visible.png',
- get_lang('ShowPageExtra'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_visibility = 'invisible';
- } else {
- $visibility_page = Display::return_icon(
- 'invisible.png',
- get_lang('HidePageExtra'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_visibility = 'visible';
- }
- }
- if ($row['id']) {
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_visibility.'&title='.api_htmlentities(urlencode($page)).'">'.
- $visibility_page.'</a>';
- }
- //page action: notification
- if (api_is_allowed_to_session_edit()) {
- if (self::check_notify_page($page) == 1) {
- $notify_page = Display::return_icon(
- 'messagebox_info.png',
- get_lang('NotifyByEmail'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_notify_page = 'unlocknotify';
- } else {
- $notify_page = Display::return_icon(
- 'mail.png',
- get_lang('CancelNotifyByEmail'),
- '',
- ICON_SIZE_MEDIUM
- );
- $lock_unlock_notify_page = 'locknotify';
- }
- }
- // Only available if row['id'] is set
- if ($row['id']) {
- if (api_is_allowed_to_session_edit(false, true) &&
- api_is_allowed_to_edit() ||
- GroupManager::is_user_in_group(
- api_get_user_id(),
- $groupInfo
- )
- ) {
- // menu discuss page
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=discuss&title='.api_htmlentities(
- urlencode($page)
- ).'" '.self::is_active_navigation_tab('discuss').'>'.
- Display::return_icon(
- 'discuss.png',
- get_lang('DiscussThisPage'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- //menu history
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=history&title='.api_htmlentities(
- urlencode($page)
- ).'" '.self::is_active_navigation_tab('history').'>'.
- Display::return_icon(
- 'history.png',
- get_lang('ShowPageHistory'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- //menu linkspages
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'action=links&title='.api_htmlentities(
- urlencode($page)
- ).'" '.self::is_active_navigation_tab('links').'>'.
- Display::return_icon(
- 'what_link_here.png',
- get_lang('LinksPages'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- //menu delete wikipage
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- $actionsRight .= '<a href="index.php?action=delete&'.api_get_cidreq().'&title='.api_htmlentities(
- urlencode($page)
- ).'"'.self::is_active_navigation_tab('delete').'>'.
- Display::return_icon(
- 'delete.png',
- get_lang('DeleteThisPage'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_notify_page.'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.
- $notify_page.'</a>';
- // Page action: copy last version to doc area
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export2doc&wiki_id='.$row['id'].'">'.
- Display::return_icon(
- 'export_to_documents.png',
- get_lang('ExportToDocArea'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf&wiki_id='.$row['id'].'">'.
- Display::return_icon(
- 'pdf.png',
- get_lang('ExportToPDF'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- $unoconv = api_get_configuration_value('unoconv.binaries');
- if ($unoconv) {
- $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).'wiki/index.php?action=export_to_doc_file&id='.$row['id'].'&'.api_get_cidreq().'">'.
- Display::return_icon(
- 'export_doc.png',
- get_lang('ExportToDoc'),
- [],
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- //export to print?>
- <script>
- function goprint() {
- var a = window.open('', '', 'width=800,height=600');
- a.document.open("text/html");
- a.document.write($('#wikicontent .panel-heading').html());
- a.document.write($('#wikicontent .panel-body').html());
- a.document.close();
- a.print();
- }
- </script>
- <?php
- $actionsRight .= Display::url(
- Display::return_icon(
- 'printer.png',
- get_lang('Print'),
- '',
- ICON_SIZE_MEDIUM
- ),
- '#',
- ['onclick' => "javascript: goprint();"]
- );
- }
- echo Display::toolbarAction(
- 'toolbar-wikistudent',
- [$actionsLeft, $actionsRight]
- );
- if (self::wiki_exist($title)) {
- $pageTitle = $icon_assignment.' '.
- $icon_task.' '.api_htmlentities($title);
- } else {
- $pageTitle = api_htmlentities($title);
- }
- $pageWiki = self::make_wiki_link_clickable(
- self::detect_external_link(
- self::detect_anchor_link(
- self::detect_mail_link(
- self::detect_ftp_link(
- self::detect_irc_link(
- self::detect_news_link($content)
- )
- )
- )
- )
- )
- );
- $footerWiki =
- get_lang('Progress').': '.($row['progress'] * 10).'% '.
- get_lang('Rating').': '.$row['score'].' '.
- get_lang('Words').': '.self::word_count($content);
- // wikicontent require to print wiki document
- echo '<div id="wikicontent">'.Display::panel($pageWiki, $pageTitle, $footerWiki).'</div>';
- } //end filter visibility
- }
- /**
- * This function counted the words in a document. Thanks Adeel Khan.
- *
- * @param string Document's text
- *
- * @return int Number of words
- */
- public function word_count($document)
- {
- $search = [
- '@<script[^>]*?>.*?</script>@si',
- '@<style[^>]*?>.*?</style>@siU',
- '@<div id="player.[^>]*?>.*?</div>@',
- '@<![\s\S]*?--[ \t\n\r]*>@',
- ];
- $document = preg_replace($search, '', $document);
- // strip all html tags
- $wc = strip_tags($document);
- $wc = html_entity_decode(
- $wc,
- ENT_NOQUOTES,
- 'UTF-8'
- ); // TODO:test also old html_entity_decode(utf8_encode($wc))
- // remove 'words' that don't consist of alphanumerical characters or punctuation. And fix accents and some letters
- $pattern = "#[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@|á|é|í|ó|ú|à|è|ì|ò|ù|ä|ë|ï|ö|ü|Á|É|Í|Ó|Ú|À|È|Ò|Ù|Ä|Ë|Ï|Ö|Ü|â|ê|î|ô|û|Â|Ê|Î|Ô|Û|ñ|Ñ|ç|Ç)]+#";
- $wc = trim(preg_replace($pattern, " ", $wc));
- // remove one-letter 'words' that consist only of punctuation
- $wc = trim(
- preg_replace(
- "#\s*[(\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]\s*#",
- " ",
- $wc
- )
- );
- // remove superfluous whitespace
- $wc = preg_replace("/\s\s+/", " ", $wc);
- // split string into an array of words
- $wc = explode(" ", $wc);
- // remove empty elements
- $wc = array_filter($wc);
- // return the number of words
- return count($wc);
- }
- /**
- * This function checks if wiki title exist.
- */
- public function wiki_exist($title)
- {
- $tbl_wiki = $this->tbl_wiki;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT id FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- title="'.Database::escape_string($title).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $cant = Database::num_rows($result);
- if ($cant > 0) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Checks if this navigation tab has to be set to active.
- *
- * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
- *
- * @return string html code
- */
- public function is_active_navigation_tab($paramwk)
- {
- if (isset($_GET['action']) && $_GET['action'] == $paramwk) {
- return ' class="active"';
- }
- }
- /**
- * Lock add pages.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- * return current database status of protect page and change it if get action
- */
- public function check_addnewpagelock()
- {
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT *
- FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_addlock = $row['addlock'];
- // Change status
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- if (isset($_GET['actionpage'])) {
- if ($_GET['actionpage'] == 'lockaddnew' && $status_addlock == 1) {
- $status_addlock = 0;
- }
- if ($_GET['actionpage'] == 'unlockaddnew' && $status_addlock == 0) {
- $status_addlock = 1;
- }
- $sql = 'UPDATE '.$tbl_wiki.' SET
- addlock="'.Database::escape_string($status_addlock).'"
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session;
- Database::query($sql);
- }
- $sql = 'SELECT *
- FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- return $row['addlock'];
- }
- /**
- * Protect page.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- * return current database status of protect page and change it if get action
- */
- public function check_protect_page()
- {
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $page = $this->page;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_editlock = $row['editlock'];
- $id = $row['page_id'];
- // Change status
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lock' && $status_editlock == 0) {
- $status_editlock = 1;
- }
- if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlock' && $status_editlock == 1) {
- $status_editlock = 0;
- }
- $sql = 'UPDATE '.$tbl_wiki.' SET
- editlock="'.Database::escape_string($status_editlock).'"
- WHERE c_id = '.$course_id.' AND page_id="'.$id.'"';
- Database::query($sql);
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- //show status
- return $row['editlock'];
- }
- /**
- * Visibility page.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- * return current database status of visibility and change it if get action
- */
- public function check_visibility_page()
- {
- $tbl_wiki = $this->tbl_wiki;
- $page = $this->page;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_visibility = $row['visibility'];
- //change status
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'visible' &&
- $status_visibility == 0
- ) {
- $status_visibility = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'invisible' &&
- $status_visibility == 1
- ) {
- $status_visibility = 0;
- }
- $sql = 'UPDATE '.$tbl_wiki.' SET
- visibility = "'.Database::escape_string($status_visibility).'"
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- Database::query($sql);
- // Although the value now is assigned to all (not only the first),
- // these three lines remain necessary.
- // They do that by changing the page state is
- // made when you press the button and not have to wait to change his page
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- if (empty($row['id'])) {
- $row['visibility'] = 1;
- }
- //show status
- return $row['visibility'];
- }
- /**
- * Visibility discussion.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return int current database status of discuss visibility
- * and change it if get action page
- */
- public function check_visibility_discuss()
- {
- $tbl_wiki = $this->tbl_wiki;
- $page = $this->page;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_visibility_disc = $row['visibility_disc'];
- //change status
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'showdisc' &&
- $status_visibility_disc == 0
- ) {
- $status_visibility_disc = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'hidedisc' &&
- $status_visibility_disc == 1
- ) {
- $status_visibility_disc = 0;
- }
- $sql = 'UPDATE '.$tbl_wiki.' SET
- visibility_disc="'.Database::escape_string($status_visibility_disc).'"
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- Database::query($sql);
- // Although the value now is assigned to all (not only the first),
- // these three lines remain necessary.
- // They do that by changing the page state is made when you press
- // the button and not have to wait to change his page
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- return $row['visibility_disc'];
- }
- /**
- * Lock add discussion.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return int current database status of lock dicuss and change if get action
- */
- public function check_addlock_discuss()
- {
- $tbl_wiki = $this->tbl_wiki;
- $page = $this->page;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_addlock_disc = $row['addlock_disc'];
- //change status
- if (api_is_allowed_to_edit() || api_is_platform_admin()) {
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'lockdisc' &&
- $status_addlock_disc == 0
- ) {
- $status_addlock_disc = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'unlockdisc' &&
- $status_addlock_disc == 1
- ) {
- $status_addlock_disc = 0;
- }
- $sql = 'UPDATE '.$tbl_wiki.' SET
- addlock_disc="'.Database::escape_string($status_addlock_disc).'"
- WHERE
- c_id = '.$course_id.' AND
- reflink = "'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- Database::query($sql);
- // Although the value now is assigned to all (not only the first),
- // these three lines remain necessary.
- // They do that by changing the page state is made when you press
- // the button and not have to wait to change his page
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- return $row['addlock_disc'];
- }
- /**
- * Lock rating discussion.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return int current database status of rating discuss and change it if get action
- */
- public function check_ratinglock_discuss()
- {
- $tbl_wiki = $this->tbl_wiki;
- $page = $this->page;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $status_ratinglock_disc = $row['ratinglock_disc'];
- //change status
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) {
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'lockrating' &&
- $status_ratinglock_disc == 0
- ) {
- $status_ratinglock_disc = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'unlockrating' &&
- $status_ratinglock_disc == 1
- ) {
- $status_ratinglock_disc = 0;
- }
- $sql = 'UPDATE '.$tbl_wiki.'
- SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'"
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- // Visibility. Value to all,not only for the first
- Database::query($sql);
- // Although the value now is assigned to all (not only the first),
- // these three lines remain necessary. They do that by changing the
- // page state is made when you press the button and not have to wait
- // to change his page
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- }
- return $row['ratinglock_disc'];
- }
- /**
- * Notify page changes.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @return int the current notification status
- */
- public function check_notify_page($reflink)
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $groupId = api_get_group_id();
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- $userId = api_get_user_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.$reflink.'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $id = $row['id'];
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND
- user_id="'.api_get_user_id().'" AND
- type="P"';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $idm = $row['id'];
- if (empty($idm)) {
- $status_notify = 0;
- } else {
- $status_notify = 1;
- }
- // Change status
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'locknotify' &&
- $status_notify == 0
- ) {
- $sql = "SELECT id FROM $tbl_wiki_mailcue
- WHERE c_id = $course_id AND id = $id AND user_id = $userId";
- $result = Database::query($sql);
- $exist = false;
- if (Database::num_rows($result)) {
- $exist = true;
- }
- if ($exist == false) {
- $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
- ($course_id, '".$id."','".api_get_user_id()."','P','".$groupId."','".$session_id."')";
- Database::query($sql);
- }
- $status_notify = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'unlocknotify' &&
- $status_notify == 1
- ) {
- $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
- WHERE
- id="'.$id.'" AND
- user_id="'.api_get_user_id().'" AND
- type="P" AND
- c_id = '.$course_id;
- Database::query($sql);
- $status_notify = 0;
- }
- return $status_notify;
- }
- /**
- * Notify discussion changes.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- *
- * @param string $reflink
- *
- * @return int current database status of rating discuss and change it if get action
- */
- public function check_notify_discuss($reflink)
- {
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $course_id = api_get_course_int_id();
- $groupId = api_get_group_id();
- $session_id = api_get_session_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.$reflink.'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $id = $row['id'];
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $idm = $row['id'];
- if (empty($idm)) {
- $status_notify_disc = 0;
- } else {
- $status_notify_disc = 1;
- }
- // change status
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'locknotifydisc' &&
- $status_notify_disc == 0
- ) {
- $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
- ($course_id, '".$id."','".api_get_user_id()."','D','".$groupId."','".$session_id."')";
- Database::query($sql);
- $status_notify_disc = 1;
- }
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'unlocknotifydisc' &&
- $status_notify_disc == 1
- ) {
- $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND
- user_id="'.api_get_user_id().'" AND
- type="D" AND
- c_id = '.$course_id;
- Database::query($sql);
- $status_notify_disc = 0;
- }
- return $status_notify_disc;
- }
- /**
- * Notify all changes.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- */
- public function check_notify_all()
- {
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $course_id = api_get_course_int_id();
- $groupId = api_get_group_id();
- $session_id = api_get_session_id();
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- user_id="'.api_get_user_id().'" AND
- type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'"';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $idm = $row['user_id'];
- if (empty($idm)) {
- $status_notify_all = 0;
- } else {
- $status_notify_all = 1;
- }
- //change status
- if (isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'locknotifyall' &&
- $status_notify_all == 0
- ) {
- $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES
- ($course_id, '".api_get_user_id()."','F','".$groupId."','".$session_id."')";
- Database::query($sql);
- $status_notify_all = 1;
- }
- if (isset($_GET['actionpage']) &&
- isset($_GET['actionpage']) &&
- $_GET['actionpage'] == 'unlocknotifyall' &&
- $status_notify_all == 1
- ) {
- $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- user_id="'.api_get_user_id().'" AND
- type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'" AND
- c_id = '.$course_id;
- Database::query($sql);
- $status_notify_all = 0;
- }
- //show status
- return $status_notify_all;
- }
- /**
- * Sends pending e-mails.
- */
- public function check_emailcue(
- $id_or_ref,
- $type,
- $lastime = '',
- $lastuser = ''
- ) {
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $_course = $this->courseInfo;
- $groupId = api_get_group_id();
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- $group_properties = GroupManager::get_group_properties($groupId);
- $group_name = $group_properties['name'];
- $allow_send_mail = false; //define the variable to below
- $email_assignment = null;
- if ($type == 'P') {
- //if modifying a wiki page
- //first, current author and time
- //Who is the author?
- $userinfo = api_get_user_info($lastuser);
- $email_user_author = get_lang('EditedBy').': '.$userinfo['complete_name'];
- //When ?
- $year = substr($lastime, 0, 4);
- $month = substr($lastime, 5, 2);
- $day = substr($lastime, 8, 2);
- $hours = substr($lastime, 11, 2);
- $minutes = substr($lastime, 14, 2);
- $seconds = substr($lastime, 17, 2);
- $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
- //second, extract data from first reg
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.$id_or_ref.'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $id = $row['id'];
- $email_page_name = $row['title'];
- if ($row['visibility'] == 1) {
- $allow_send_mail = true; //if visibility off - notify off
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND
- type="'.$type.'" OR
- type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'"';
- //type: P=page, D=discuss, F=full.
- $result = Database::query($sql);
- $emailtext = get_lang('EmailWikipageModified').
- '<strong>'.$email_page_name.'</strong> '.
- get_lang('Wiki');
- }
- } elseif ($type == 'D') {
- //if added a post to discuss
- //first, current author and time
- //Who is the author of last message?
- $userinfo = api_get_user_info($lastuser);
- $email_user_author = get_lang('AddedBy').': '.$userinfo['complete_name'];
- //When ?
- $year = substr($lastime, 0, 4);
- $month = substr($lastime, 5, 2);
- $day = substr($lastime, 8, 2);
- $hours = substr($lastime, 11, 2);
- $minutes = substr($lastime, 14, 2);
- $seconds = substr($lastime, 17, 2);
- $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
- //second, extract data from first reg
- $id = $id_or_ref; //$id_or_ref is id from tblwiki
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND id="'.$id.'"
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $email_page_name = $row['title'];
- if ($row['visibility_disc'] == 1) {
- $allow_send_mail = true; //if visibility off - notify off
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND
- type="'.$type.'" OR
- type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'"';
- //type: P=page, D=discuss, F=full
- $result = Database::query($sql);
- $emailtext = get_lang(
- 'EmailWikiPageDiscAdded'
- ).' <strong>'.$email_page_name.'</strong> '.get_lang(
- 'Wiki'
- );
- }
- } elseif ($type == 'A') {
- //for added pages
- $id = 0; //for tbl_wiki_mailcue
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.'
- ORDER BY id DESC'; //the added is always the last
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $email_page_name = $row['title'];
- //Who is the author?
- $userinfo = api_get_user_info($row['user_id']);
- $email_user_author = get_lang('AddedBy').': '.$userinfo['complete_name'];
- //When ?
- $year = substr($row['dtime'], 0, 4);
- $month = substr($row['dtime'], 5, 2);
- $day = substr($row['dtime'], 8, 2);
- $hours = substr($row['dtime'], 11, 2);
- $minutes = substr($row['dtime'], 14, 2);
- $seconds = substr($row['dtime'], 17, 2);
- $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
- if ($row['assignment'] == 0) {
- $allow_send_mail = true;
- } elseif ($row['assignment'] == 1) {
- $email_assignment = get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')';
- $allow_send_mail = true;
- } elseif ($row['assignment'] == 2) {
- $allow_send_mail = false; //Mode tasks: avoids notifications to all users about all users
- }
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND
- type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'"';
- //type: P=page, D=discuss, F=full
- $result = Database::query($sql);
- $emailtext = get_lang('EmailWikiPageAdded').' <strong>'.
- $email_page_name.'</strong> '.get_lang('In').' '.get_lang('Wiki');
- } elseif ($type == 'E') {
- $id = 0;
- $allow_send_mail = true;
- // Who is the author?
- $userinfo = api_get_user_info(api_get_user_id()); //current user
- $email_user_author = get_lang('DeletedBy').': '.$userinfo['complete_name'];
- //When ?
- $today = date('r'); //current time
- $email_date_changes = $today;
- $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
- WHERE
- c_id = '.$course_id.' AND
- id="'.$id.'" AND type="F" AND
- group_id="'.$groupId.'" AND
- session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=wiki
- $result = Database::query($sql);
- $emailtext = get_lang('EmailWikipageDedeleted');
- }
- ///make and send email
- if ($allow_send_mail) {
- while ($row = Database::fetch_array($result)) {
- $userinfo = api_get_user_info(
- $row['user_id']
- ); //$row['user_id'] obtained from tbl_wiki_mailcue
- $name_to = $userinfo['complete_name'];
- $email_to = $userinfo['email'];
- $sender_name = api_get_setting('emailAdministrator');
- $sender_email = api_get_setting('emailAdministrator');
- $email_subject = get_lang(
- 'EmailWikiChanges'
- ).' - '.$_course['official_code'];
- $email_body = get_lang('DearUser').' '.api_get_person_name(
- $userinfo['firstname'],
- $userinfo['lastname']
- ).',<br /><br />';
- if ($session_id == 0) {
- $email_body .= $emailtext.' <strong>'.$_course['name'].' - '.$group_name.'</strong><br /><br /><br />';
- } else {
- $email_body .= $emailtext.' <strong>'.$_course['name'].' ('.api_get_session_name(
- api_get_session_id()
- ).') - '.$group_name.'</strong><br /><br /><br />';
- }
- $email_body .= $email_user_author.' ('.$email_date_changes.')<br /><br /><br />';
- $email_body .= $email_assignment.'<br /><br /><br />';
- $email_body .= '<font size="-2">'.get_lang(
- 'EmailWikiChangesExt_1'
- ).': <strong>'.get_lang('NotifyChanges').'</strong><br />';
- $email_body .= get_lang(
- 'EmailWikiChangesExt_2'
- ).': <strong>'.get_lang(
- 'NotNotifyChanges'
- ).'</strong></font><br />';
- @api_mail_html(
- $name_to,
- $email_to,
- $email_subject,
- $email_body,
- $sender_name,
- $sender_email
- );
- }
- }
- }
- /**
- * Function export last wiki page version to document area.
- *
- * @param int $doc_id wiki page id
- *
- * @return mixed
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- */
- public function export2doc($doc_id)
- {
- $_course = $this->courseInfo;
- $groupId = api_get_group_id();
- $groupInfo = GroupManager::get_group_properties($groupId);
- $data = self::getWikiDataFromDb($doc_id);
- if (empty($data)) {
- return false;
- }
- $wikiTitle = $data['title'];
- $wikiContents = $data['content'];
- $template =
- '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}">
- <head>
- <title>{TITLE}</title>
- <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
- <style type="text/css" media="screen, projection">
- /*<![CDATA[*/
- {CSS}
- /*]]>*/
- </style>
- {ASCIIMATHML_SCRIPT}</head>
- <body dir="{TEXT_DIRECTION}">
- {CONTENT}
- </body>
- </html>';
- $css_file = api_get_path(SYS_CSS_PATH).'themes/'.api_get_setting('stylesheets').'/default.css';
- if (file_exists($css_file)) {
- $css = @file_get_contents($css_file);
- } else {
- $css = '';
- }
- // Fixing some bugs in css files.
- $root_rel = api_get_path(REL_PATH);
- $css_path = 'main/css/';
- $theme = api_get_setting('stylesheets').'/';
- $css = str_replace(
- 'behavior:url("/main/css/csshover3.htc");',
- '',
- $css
- );
- $css = str_replace('main/', $root_rel.'main/', $css);
- $css = str_replace(
- 'images/',
- $root_rel.$css_path.$theme.'images/',
- $css
- );
- $css = str_replace('../../img/', $root_rel.'main/img/', $css);
- $asciimathmal_script = (api_contains_asciimathml(
- $wikiContents
- ) || api_contains_asciisvg($wikiContents))
- ? '<script src="'.api_get_path(
- WEB_CODE_PATH
- ).'inc/lib/javascript/asciimath/ASCIIMathML.js" type="text/javascript"></script>'."\n" : '';
- $template = str_replace(
- [
- '{LANGUAGE}',
- '{ENCODING}',
- '{TEXT_DIRECTION}',
- '{TITLE}',
- '{CSS}',
- '{ASCIIMATHML_SCRIPT}',
- ],
- [
- api_get_language_isocode(),
- api_get_system_encoding(),
- api_get_text_direction(),
- $wikiTitle,
- $css,
- $asciimathmal_script,
- ],
- $template
- );
- if (0 != $groupId) {
- $groupPart = '_group'.$groupId; // and add groupId to put the same document title in different groups
- $group_properties = GroupManager::get_group_properties($groupId);
- $groupPath = $group_properties['directory'];
- } else {
- $groupPart = '';
- $groupPath = '';
- }
- $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(
- ).'/document'.$groupPath;
- $exportFile = api_replace_dangerous_char($wikiTitle).$groupPart;
- $wikiContents = trim(
- preg_replace(
- "/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/",
- "$1",
- $wikiContents
- )
- );
- //TODO: put link instead of title
- $wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
- // replace relative path by absolute path for courses, so you can see
- // items into this page wiki (images, mp3, etc..) exported in documents
- if (api_strpos(
- $wikiContents,
- '../..'.api_get_path(REL_COURSE_PATH)
- ) !== false) {
- $web_course_path = api_get_path(WEB_COURSE_PATH);
- $wikiContents = str_replace(
- '../..'.api_get_path(REL_COURSE_PATH),
- $web_course_path,
- $wikiContents
- );
- }
- $i = 1;
- //only export last version, but in new export new version in document area
- while (file_exists($exportDir.'/'.$exportFile.'_'.$i.'.html')) {
- $i++;
- }
- $wikiFileName = $exportFile.'_'.$i.'.html';
- $exportPath = $exportDir.'/'.$wikiFileName;
- file_put_contents($exportPath, $wikiContents);
- $doc_id = add_document(
- $_course,
- $groupPath.'/'.$wikiFileName,
- 'file',
- filesize($exportPath),
- $wikiTitle
- );
- api_item_property_update(
- $_course,
- TOOL_DOCUMENT,
- $doc_id,
- 'DocumentAdded',
- api_get_user_id(),
- $groupInfo
- );
- return $doc_id;
- }
- /**
- * Exports the wiki page to PDF.
- */
- public function export_to_pdf($id, $course_code)
- {
- if (!api_is_platform_admin()) {
- if (api_get_setting('students_export2pdf') !== 'true') {
- Display::addFlash(
- Display::return_message(
- get_lang('PDFDownloadNotAllowedForStudents'),
- 'error',
- false
- )
- );
- return false;
- }
- }
- $data = self::getWikiDataFromDb($id);
- $content_pdf = api_html_entity_decode(
- $data['content'],
- ENT_QUOTES,
- api_get_system_encoding()
- );
- //clean wiki links
- $content_pdf = trim(
- preg_replace(
- "/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/",
- "$1",
- $content_pdf
- )
- );
- //TODO: It should be better to display the link insted of the tile but it is hard for [[title]] links
- $title_pdf = api_html_entity_decode(
- $data['title'],
- ENT_QUOTES,
- api_get_system_encoding()
- );
- $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
- $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding());
- $html = '
- <!-- defines the headers/footers - this must occur before the headers/footers are set -->
- <!--mpdf
- <pageheader name="odds" content-left="'.$title_pdf.'" header-style-left="color: #880000; font-style: italic;" line="1" />
- <pagefooter name="odds" content-right="{PAGENO}/{nb}" line="1" />
- <!-- set the headers/footers - they will occur from here on in the document -->
- <!--mpdf
- <setpageheader name="odds" page="odd" value="on" show-this-page="1" />
- <setpagefooter name="odds" page="O" value="on" />
- mpdf-->'.$content_pdf;
- $css_file = api_get_path(SYS_CSS_PATH).'themes/'.api_get_setting('stylesheets').'/print.css';
- if (file_exists($css_file)) {
- $css = @file_get_contents($css_file);
- } else {
- $css = '';
- }
- $pdf = new PDF();
- $pdf->content_to_pdf($html, $css, $title_pdf, $course_code);
- exit;
- }
- /**
- * Function prevent double post (reload or F5).
- */
- public function double_post($wpost_id)
- {
- $postId = Session::read('wpost_id');
- if (!empty($postId)) {
- if ($wpost_id == $postId) {
- return false;
- } else {
- Session::write('wpost_id', $wpost_id);
- return true;
- }
- } else {
- Session::write('wpost_id', $wpost_id);
- return true;
- }
- }
- /**
- * Function wizard individual assignment.
- *
- * @author Juan Carlos Raña <herodoto@telefonica.net>
- */
- public function auto_add_page_users($values)
- {
- $assignment_type = $values['assignment'];
- $session_id = $this->session_id;
- $groupId = api_get_group_id();
- $groupInfo = GroupManager::get_group_properties($groupId);
- if ($groupId == 0) {
- //extract course members
- if (!empty($session_id)) {
- $a_users_to_add = CourseManager::get_user_list_from_course_code(
- api_get_course_id(),
- $session_id
- );
- } else {
- $a_users_to_add = CourseManager::get_user_list_from_course_code(
- api_get_course_id(),
- 0
- );
- }
- } else {
- //extract group members
- $subscribed_users = GroupManager::get_subscribed_users($groupInfo);
- $subscribed_tutors = GroupManager::get_subscribed_tutors(
- $groupInfo
- );
- $a_users_to_add_with_duplicates = array_merge(
- $subscribed_users,
- $subscribed_tutors
- );
- //remove duplicates
- $a_users_to_add = $a_users_to_add_with_duplicates;
- $a_users_to_add = array_unique($a_users_to_add);
- }
- $all_students_pages = [];
- // Data about teacher
- $userId = api_get_user_id();
- $userinfo = api_get_user_info($userId);
- $username = api_htmlentities(
- sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES)
- );
- $name = $userinfo['complete_name']." - ".$username;
- $photo = '<img src="'.$userinfo['avatar'].'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
- // teacher assignment title
- $title_orig = $values['title'];
- // teacher assignment reflink
- $link2teacher = $values['title'] = $title_orig."_uass".$userId;
- // first: teacher name, photo, and assignment description (original content)
- $content_orig_A = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6">
- <table border="0">
- <tr><td style="font-size:24px">'.get_lang('AssignmentDesc').'</td></tr>
- <tr><td>'.$photo.'<br />'.Display::tag(
- 'span',
- api_get_person_name(
- $userinfo['firstname'],
- $userinfo['lastname']
- ),
- ['title' => $username]
- ).'</td></tr>
- </table></div>';
- $content_orig_B = '<br/><div align="center" style="font-size:24px">'.
- get_lang('AssignmentDescription').': '.
- $title_orig.'</div><br/>'.Security::remove_XSS($_POST['content']);
- //Second: student list (names, photo and links to their works).
- //Third: Create Students work pages.
- foreach ($a_users_to_add as $o_user_to_add) {
- if ($o_user_to_add['user_id'] != $userId) {
- // except that puts the task
- $assig_user_id = $o_user_to_add['user_id'];
- // identifies each page as created by the student, not by teacher
- $userPicture = UserManager::getUserPicture($assig_user_id);
- $username = api_htmlentities(
- sprintf(
- get_lang('LoginX'),
- $o_user_to_add['username'],
- ENT_QUOTES
- )
- );
- $name = api_get_person_name(
- $o_user_to_add['firstname'],
- $o_user_to_add['lastname']
- )." . ".$username;
- $photo = '<img src="'.$userPicture.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />';
- $is_tutor_of_group = GroupManager::is_tutor_of_group(
- $assig_user_id,
- $groupInfo
- ); //student is tutor
- $is_tutor_and_member = GroupManager::is_tutor_of_group(
- $assig_user_id,
- $groupInfo
- ) &&
- GroupManager::is_subscribed($assig_user_id, $groupInfo);
- // student is tutor and member
- if ($is_tutor_and_member) {
- $status_in_group = get_lang('GroupTutorAndMember');
- } else {
- if ($is_tutor_of_group) {
- $status_in_group = get_lang('GroupTutor');
- } else {
- $status_in_group = " "; //get_lang('GroupStandardMember')
- }
- }
- if ($assignment_type == 1) {
- $values['title'] = $title_orig;
- $values['content'] = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6">
- <table border="0">
- <tr><td style="font-size:24px">'.get_lang('AssignmentWork').'</td></tr>
- <tr><td>'.$photo.'<br />'.$name.'</td></tr></table>
- </div>[['.$link2teacher.' | '.get_lang(
- 'AssignmentLinktoTeacherPage'
- ).']] ';
- //If $content_orig_B is added here, the task written by
- // the professor was copied to the page of each student.
- // TODO: config options
- // AssignmentLinktoTeacherPage
- $all_students_pages[] = '<li>'.
- Display::tag(
- 'span',
- strtoupper(
- $o_user_to_add['lastname']
- ).', '.$o_user_to_add['firstname'],
- ['title' => $username]
- ).
- ' [['.Security::remove_XSS(
- $_POST['title']
- )."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>';
- // don't change this line without guaranteeing
- // that users will be ordered by last names in the
- // following format (surname, name)
- $values['assignment'] = 2;
- }
- $this->assig_user_id = $assig_user_id;
- self::save_new_wiki($values);
- }
- }
- foreach ($a_users_to_add as $o_user_to_add) {
- if ($o_user_to_add['user_id'] == $userId) {
- $assig_user_id = $o_user_to_add['user_id'];
- if ($assignment_type == 1) {
- $values['title'] = $title_orig;
- $values['comment'] = get_lang('AssignmentDesc');
- sort($all_students_pages);
- $values['content'] = $content_orig_A.$content_orig_B.'<br/>
- <div align="center" style="font-size:18px; background-color: #F5F8FB; border:solid; border-color:#E6E6E6">
- '.get_lang('AssignmentLinkstoStudentsPage').'
- </div><br/>
- <div style="background-color: #F5F8FB; border:solid; border-color:#E6E6E6">
- <ol>'.implode($all_students_pages).'</ol>
- </div>
- <br/>';
- $values['assignment'] = 1;
- }
- $this->assig_user_id = $assig_user_id;
- self::save_new_wiki($values);
- }
- }
- }
- /**
- * Displays the results of a wiki search.
- *
- * @param string Search term
- * @param int Whether to search the contents (1) or just the titles (0)
- * @param int
- */
- public function display_wiki_search_results(
- $search_term,
- $search_content = 0,
- $all_vers = 0
- ) {
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $_course = $this->courseInfo;
- $course_id = api_get_course_int_id();
- echo '<legend>'.get_lang('WikiSearchResults').': '.Security::remove_XSS(
- $search_term
- );
- echo '</legend>';
- //only by professors when page is hidden
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if ($all_vers == '1') {
- if ($search_content == '1') {
- $sql = "SELECT * FROM ".$tbl_wiki."
- WHERE
- c_id = $course_id AND
- title LIKE '%".Database::escape_string($search_term)."%' OR
- content LIKE '%".Database::escape_string(
- $search_term
- )."%' AND ".$groupfilter.$condition_session;
- } else {
- $sql = "SELECT * FROM ".$tbl_wiki."
- WHERE
- c_id = $course_id AND
- title LIKE '%".Database::escape_string(
- $search_term
- )."%' AND ".$groupfilter.$condition_session;
- }
- } else {
- if ($search_content == '1') {
- // warning don't use group by reflink because don't return the last version
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE
- s1.c_id = $course_id AND
- title LIKE '%".Database::escape_string($search_term)."%' OR
- content LIKE '%".Database::escape_string($search_term)."%' AND
- id=(
- SELECT MAX(s2.id)
- FROM ".$tbl_wiki." s2
- WHERE
- s2.c_id = $course_id AND
- s1.reflink = s2.reflink AND
- ".$groupfilter.$condition_session.")";
- } else {
- // warning don't use group by reflink because don't return the last version
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE
- s1.c_id = $course_id AND
- title LIKE '%".Database::escape_string(
- $search_term
- )."%' AND
- id = (
- SELECT MAX(s2.id)
- FROM ".$tbl_wiki." s2
- WHERE
- s2.c_id = $course_id AND
- s1.reflink = s2.reflink AND
- ".$groupfilter.$condition_session.")";
- }
- }
- } else {
- if ($all_vers == '1') {
- if ($search_content == '1') {
- //search all pages and all versions
- $sql = "SELECT * FROM ".$tbl_wiki."
- WHERE
- c_id = $course_id AND
- visibility=1 AND
- title LIKE '%".Database::escape_string($search_term)."%' OR
- content LIKE '%".Database::escape_string($search_term)."%' AND
- ".$groupfilter.$condition_session;
- } else {
- $sql = "SELECT * FROM ".$tbl_wiki."
- WHERE
- c_id = $course_id AND
- visibility=1 AND
- title LIKE '%".Database::escape_string($search_term)."%' AND
- ".$groupfilter.$condition_session;
- }
- } else {
- if ($search_content == '1') {
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE
- s1.c_id = $course_id AND
- visibility=1 AND
- title LIKE '%".Database::escape_string($search_term)."%' OR
- content LIKE '%".Database::escape_string($search_term)."%' AND
- id=(
- SELECT MAX(s2.id)
- FROM ".$tbl_wiki." s2
- WHERE s2.c_id = $course_id AND
- s1.reflink = s2.reflink AND
- ".$groupfilter.$condition_session.")";
- } else {
- // warning don't use group by reflink because don't return the last version
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE
- s1.c_id = $course_id AND
- visibility=1 AND
- title LIKE '%".Database::escape_string($search_term)."%' AND
- id = (
- SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
- WHERE s2.c_id = $course_id AND
- s1.reflink = s2.reflink AND
- ".$groupfilter.$condition_session.")";
- }
- }
- }
- $result = Database::query($sql);
- //show table
- $rows = [];
- if (Database::num_rows($result) > 0) {
- while ($obj = Database::fetch_object($result)) {
- //get author
- $userinfo = api_get_user_info($obj->user_id);
- //get time
- $year = substr($obj->dtime, 0, 4);
- $month = substr($obj->dtime, 5, 2);
- $day = substr($obj->dtime, 8, 2);
- $hours = substr($obj->dtime, 11, 2);
- $minutes = substr($obj->dtime, 14, 2);
- $seconds = substr($obj->dtime, 17, 2);
- //get type assignment icon
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- $row = [];
- $row[] = $ShowAssignment;
- if ($all_vers == '1') {
- $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&view='.$obj->id.'&session_id='.api_htmlentities(
- urlencode($_GET['$session_id'])
- ).'&group_id='.api_htmlentities(
- urlencode($_GET['group_id'])
- ).'">'.
- api_htmlentities($obj->title).'</a>';
- } else {
- $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- $obj->title.'</a>';
- }
- $row[] = ($obj->user_id != 0 && $userinfo !== false) ? UserManager::getUserProfileLink(
- $userinfo
- ) : get_lang('Anonymous').' ('.$obj->user_ip.')';
- $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
- if ($all_vers == '1') {
- $row[] = $obj->version;
- } else {
- $showdelete = '';
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- $showdelete = ' <a href="'.api_get_self(
- ).'?'.api_get_cidreq(
- ).'&action=delete&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&group_id='.api_htmlentities(
- $_GET['group_id']
- ).'">'.
- Display::return_icon(
- 'delete.png',
- get_lang('Delete'),
- '',
- ICON_SIZE_SMALL
- );
- }
- $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=edit&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'edit.png',
- get_lang('EditPage'),
- '',
- ICON_SIZE_SMALL
- ).'</a>
- <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'discuss.png',
- get_lang('Discuss'),
- '',
- ICON_SIZE_SMALL
- ).'</a>
- <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'history.png',
- get_lang('History'),
- '',
- ICON_SIZE_SMALL
- ).'</a> <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'what_link_here.png',
- get_lang('LinksPages'),
- '',
- ICON_SIZE_SMALL
- ).'</a>'.$showdelete;
- }
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 1,
- 10,
- 'SearchPages_table',
- '',
- '',
- 'ASC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => $_GET['cidReq'],
- 'action' => $_GET['action'],
- 'group_id' => intval($_GET['group_id']),
- 'mode_table' => 'yes2',
- 'search_term' => $search_term,
- 'search_content' => $search_content,
- 'all_vers' => $all_vers,
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- if ($all_vers == '1') {
- $table->set_header(2, get_lang('Author'), true);
- $table->set_header(3, get_lang('Date'), true);
- $table->set_header(4, get_lang('Version'), true);
- } else {
- $table->set_header(
- 2,
- get_lang('Author').' ('.get_lang('LastVersion').')',
- true
- );
- $table->set_header(
- 3,
- get_lang('Date').' ('.get_lang('LastVersion').')',
- true
- );
- $table->set_header(
- 4,
- get_lang('Actions'),
- false,
- ['style' => 'width:130px;']
- );
- }
- $table->display();
- } else {
- echo get_lang('NoSearchResults');
- }
- }
- /**
- * Get wiki information.
- *
- * @param int|bool wiki id
- *
- * @return array wiki data
- */
- public function getWikiDataFromDb($id)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = api_get_course_int_id();
- if ($id === false) {
- return [];
- }
- $id = intval($id);
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND id = '.$id.' ';
- $result = Database::query($sql);
- $data = [];
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $data = $row;
- }
- return $data;
- }
- /**
- * @param string $refLink
- *
- * @return array
- */
- public function getLastWikiData($refLink)
- {
- $tbl_wiki = $this->tbl_wiki;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($refLink).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- return Database::fetch_array($result);
- }
- /**
- * Get wiki information.
- *
- * @param string wiki id
- * @param int $courseId
- *
- * @return array wiki data
- */
- public function getPageByTitle($title, $courseId = null)
- {
- $tbl_wiki = $this->tbl_wiki;
- if (empty($courseId)) {
- $courseId = api_get_course_int_id();
- } else {
- $courseId = intval($courseId);
- }
- if (empty($title) || empty($courseId)) {
- return [];
- }
- $title = Database::escape_string($title);
- $sql = "SELECT * FROM $tbl_wiki
- WHERE c_id = $courseId AND reflink = '$title'";
- $result = Database::query($sql);
- $data = [];
- if (Database::num_rows($result)) {
- $data = Database::fetch_array($result, 'ASSOC');
- }
- return $data;
- }
- /**
- * @param string $title
- * @param int $courseId
- * @param string
- * @param string
- *
- * @return bool
- */
- public function deletePage(
- $title,
- $courseId,
- $groupfilter = null,
- $condition_session = null
- ) {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_discuss = $this->tbl_wiki_discuss;
- $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $pageInfo = self::getPageByTitle($title, $courseId);
- if (!empty($pageInfo)) {
- $pageId = $pageInfo['id'];
- $sql = "DELETE FROM $tbl_wiki_conf
- WHERE c_id = $courseId AND page_id = $pageId";
- Database::query($sql);
- $sql = 'DELETE FROM '.$tbl_wiki_discuss.'
- WHERE c_id = '.$courseId.' AND publication_id = '.$pageId;
- Database::query($sql);
- $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
- WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.'';
- Database::query($sql);
- $sql = 'DELETE FROM '.$tbl_wiki.'
- WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.'';
- Database::query($sql);
- self::check_emailcue(0, 'E');
- return true;
- }
- return false;
- }
- /**
- * @return array
- */
- public function getAllWiki()
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $sql = "SELECT * FROM $tbl_wiki
- WHERE
- c_id = $course_id AND
- is_editing != '0' ".$condition_session;
- $result = Database::query($sql);
- return Database::store_result($result, 'ASSOC');
- }
- /**
- * @param int $isEditing
- */
- public function updateWikiIsEditing($isEditing)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $isEditing = Database::escape_string($isEditing);
- $sql = 'UPDATE '.$tbl_wiki.' SET
- is_editing = "0",
- time_edit = NULL
- WHERE
- c_id = '.$course_id.' AND
- is_editing="'.$isEditing.'" '.
- $condition_session;
- Database::query($sql);
- }
- /**
- * Release of blocked pages to prevent concurrent editions.
- *
- * @param int $userId
- * @param string $action
- */
- public function blockConcurrentEditions($userId, $action = null)
- {
- $result = self::getAllWiki();
- if (!empty($result)) {
- foreach ($result as $is_editing_block) {
- $max_edit_time = 1200; // 20 minutes
- $timestamp_edit = strtotime($is_editing_block['time_edit']);
- $time_editing = time() - $timestamp_edit;
- // First prevent concurrent users and double version
- if ($is_editing_block['is_editing'] == $userId) {
- Session::write('_version', $is_editing_block['version']);
- } else {
- Session::erase('_version');
- }
- // Second checks if has exceeded the time that a page may
- // be available or if a page was edited and saved by its author
- if ($time_editing > $max_edit_time ||
- ($is_editing_block['is_editing'] == $userId &&
- $action != 'edit')
- ) {
- self::updateWikiIsEditing($is_editing_block['is_editing']);
- }
- }
- }
- }
- /**
- * Showing wiki stats.
- */
- public function getStats()
- {
- if (!api_is_allowed_to_edit(false, true)) {
- return false;
- }
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $session_id = $this->session_id;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- echo '<div class="actions">'.get_lang('Statistics').'</div>';
- // Check all versions of all pages
- $total_words = 0;
- $total_links = 0;
- $total_links_anchors = 0;
- $total_links_mail = 0;
- $total_links_ftp = 0;
- $total_links_irc = 0;
- $total_links_news = 0;
- $total_wlinks = 0;
- $total_images = 0;
- $clean_total_flash = 0;
- $total_flash = 0;
- $total_mp3 = 0;
- $total_flv_p = 0;
- $total_flv = 0;
- $total_youtube = 0;
- $total_multimedia = 0;
- $total_tables = 0;
- $sql = "SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS
- FROM ".$tbl_wiki."
- WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_versions = $row['TOTAL_VERS'];
- $total_visits = intval($row['TOTAL_VISITS']);
- }
- $sql = "SELECT * FROM ".$tbl_wiki."
- WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_words = $total_words + self::word_count($row['content']);
- $total_links = $total_links + substr_count(
- $row['content'],
- "href="
- );
- $total_links_anchors = $total_links_anchors + substr_count(
- $row['content'],
- 'href="#'
- );
- $total_links_mail = $total_links_mail + substr_count(
- $row['content'],
- 'href="mailto'
- );
- $total_links_ftp = $total_links_ftp + substr_count(
- $row['content'],
- 'href="ftp'
- );
- $total_links_irc = $total_links_irc + substr_count(
- $row['content'],
- 'href="irc'
- );
- $total_links_news = $total_links_news + substr_count(
- $row['content'],
- 'href="news'
- );
- $total_wlinks = $total_wlinks + substr_count($row['content'], "[[");
- $total_images = $total_images + substr_count(
- $row['content'],
- "<img"
- );
- $clean_total_flash = preg_replace(
- '/player.swf/',
- ' ',
- $row['content']
- );
- $total_flash = $total_flash + substr_count(
- $clean_total_flash,
- '.swf"'
- );
- //.swf" end quotes prevent insert swf through flvplayer (is not counted)
- $total_mp3 = $total_mp3 + substr_count($row['content'], ".mp3");
- $total_flv_p = $total_flv_p + substr_count($row['content'], ".flv");
- $total_flv = $total_flv_p / 5;
- $total_youtube = $total_youtube + substr_count(
- $row['content'],
- "http://www.youtube.com"
- );
- $total_multimedia = $total_multimedia + substr_count(
- $row['content'],
- "video/x-msvideo"
- );
- $total_tables = $total_tables + substr_count(
- $row['content'],
- "<table"
- );
- }
- // Check only last version of all pages (current page)
- $sql = ' SELECT *, COUNT(*) AS TOTAL_PAGES, SUM(hits) AS TOTAL_VISITS_LV
- FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id)
- FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.')';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_pages = $row['TOTAL_PAGES'];
- $total_visits_lv = intval($row['TOTAL_VISITS_LV']);
- }
- $total_words_lv = 0;
- $total_links_lv = 0;
- $total_links_anchors_lv = 0;
- $total_links_mail_lv = 0;
- $total_links_ftp_lv = 0;
- $total_links_irc_lv = 0;
- $total_links_news_lv = 0;
- $total_wlinks_lv = 0;
- $total_images_lv = 0;
- $clean_total_flash_lv = 0;
- $total_flash_lv = 0;
- $total_mp3_lv = 0;
- $total_flv_p_lv = 0;
- $total_flv_lv = 0;
- $total_youtube_lv = 0;
- $total_multimedia_lv = 0;
- $total_tables_lv = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_words_lv = $total_words_lv + self::word_count(
- $row['content']
- );
- $total_links_lv = $total_links_lv + substr_count(
- $row['content'],
- "href="
- );
- $total_links_anchors_lv = $total_links_anchors_lv + substr_count(
- $row['content'],
- 'href="#'
- );
- $total_links_mail_lv = $total_links_mail_lv + substr_count(
- $row['content'],
- 'href="mailto'
- );
- $total_links_ftp_lv = $total_links_ftp_lv + substr_count(
- $row['content'],
- 'href="ftp'
- );
- $total_links_irc_lv = $total_links_irc_lv + substr_count(
- $row['content'],
- 'href="irc'
- );
- $total_links_news_lv = $total_links_news_lv + substr_count(
- $row['content'],
- 'href="news'
- );
- $total_wlinks_lv = $total_wlinks_lv + substr_count(
- $row['content'],
- "[["
- );
- $total_images_lv = $total_images_lv + substr_count(
- $row['content'],
- "<img"
- );
- $clean_total_flash_lv = preg_replace(
- '/player.swf/',
- ' ',
- $row['content']
- );
- $total_flash_lv = $total_flash_lv + substr_count(
- $clean_total_flash_lv,
- '.swf"'
- );
- //.swf" end quotes prevent insert swf through flvplayer (is not counted)
- $total_mp3_lv = $total_mp3_lv + substr_count(
- $row['content'],
- ".mp3"
- );
- $total_flv_p_lv = $total_flv_p_lv + substr_count(
- $row['content'],
- ".flv"
- );
- $total_flv_lv = $total_flv_p_lv / 5;
- $total_youtube_lv = $total_youtube_lv + substr_count(
- $row['content'],
- "http://www.youtube.com"
- );
- $total_multimedia_lv = $total_multimedia_lv + substr_count(
- $row['content'],
- "video/x-msvideo"
- );
- $total_tables_lv = $total_tables_lv + substr_count(
- $row['content'],
- "<table"
- );
- }
- //Total pages edited at this time
- $total_editing_now = 0;
- $sql = 'SELECT *, COUNT(*) AS TOTAL_EDITING_NOW
- FROM '.$tbl_wiki.' s1
- WHERE is_editing!=0 AND s1.c_id = '.$course_id.' AND
- id=(
- SELECT MAX(s2.id)
- FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- // Can not use group by because the mark is set in the latest version
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_editing_now = $row['TOTAL_EDITING_NOW'];
- }
- // Total hidden pages
- $total_hidden = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- visibility = 0 AND
- '.$groupfilter.$condition_session.'
- GROUP BY reflink';
- // or group by page_id. As the mark of hidden places it in all
- // versions of the page, I can use group by to see the first
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_hidden = $total_hidden + 1;
- }
- //Total protect pages
- $total_protected = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- editlock = 1 AND
- '.$groupfilter.$condition_session.'
- GROUP BY reflink';
- // or group by page_id. As the mark of protected page is the
- // first version of the page, I can use group by
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_protected = $total_protected + 1;
- }
- // Total empty versions.
- $total_empty_content = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- content="" AND
- '.$groupfilter.$condition_session.'';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_empty_content = $total_empty_content + 1;
- }
- //Total empty pages (last version)
- $total_empty_content_lv = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND content="" AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s1.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_empty_content_lv = $total_empty_content_lv + 1;
- }
- // Total locked discuss pages
- $total_lock_disc = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND addlock_disc=0 AND '.$groupfilter.$condition_session.'
- GROUP BY reflink'; //group by because mark lock in all vers, then always is ok
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_lock_disc = $total_lock_disc + 1;
- }
- // Total hidden discuss pages.
- $total_hidden_disc = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND visibility_disc=0 AND '.$groupfilter.$condition_session.'
- GROUP BY reflink';
- //group by because mark lock in all vers, then always is ok
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_hidden_disc = $total_hidden_disc + 1;
- }
- // Total versions with any short comment by user or system
- $total_comment_version = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND comment!="" AND '.$groupfilter.$condition_session.'';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_comment_version = $total_comment_version + 1;
- }
- // Total pages that can only be scored by teachers.
- $total_only_teachers_rating = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND
- ratinglock_disc = 0 AND
- '.$groupfilter.$condition_session.'
- GROUP BY reflink'; //group by because mark lock in all vers, then always is ok
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_only_teachers_rating = $total_only_teachers_rating + 1;
- }
- // Total pages scored by peers
- // put always this line alfter check num all pages and num pages rated by teachers
- $total_rating_by_peers = $total_pages - $total_only_teachers_rating;
- //Total pages identified as standard task
- $total_task = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
- WHERE '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND
- '.$tbl_wiki_conf.'.task!="" AND
- '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
- '.$tbl_wiki.'.'.$groupfilter.$condition_session;
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_task = $total_task + 1;
- }
- //Total pages identified as teacher page (wiki portfolio mode - individual assignment)
- $total_teacher_assignment = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND assignment=1 AND id=(
- SELECT MAX(s2.id)
- FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- //mark all versions, but do not use group by reflink because y want the pages not versions
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_teacher_assignment = $total_teacher_assignment + 1;
- }
- //Total pages identifies as student page (wiki portfolio mode - individual assignment)
- $total_student_assignment = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND assignment=2 AND
- id = (SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- //mark all versions, but do not use group by reflink because y want the pages not versions
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_student_assignment = $total_student_assignment + 1;
- }
- //Current Wiki status add new pages
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY addlock'; //group by because mark 0 in all vers, then always is ok
- $allpages = Database::query($sql);
- $wiki_add_lock = null;
- while ($row = Database::fetch_array($allpages)) {
- $wiki_add_lock = $row['addlock'];
- }
- if ($wiki_add_lock == 1) {
- $status_add_new_pag = get_lang('Yes');
- } else {
- $status_add_new_pag = get_lang('No');
- }
- // Creation date of the oldest wiki page and version
- $first_wiki_date = null;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- ORDER BY dtime ASC
- LIMIT 1';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $first_wiki_date = api_get_local_time($row['dtime']);
- }
- // Date of publication of the latest wiki version.
- $last_wiki_date = null;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- ORDER BY dtime DESC
- LIMIT 1';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $last_wiki_date = api_get_local_time($row['dtime']);
- }
- // Average score of all wiki pages. (If a page has not scored zero rated)
- $media_score = 0;
- $sql = "SELECT *, SUM(score) AS TOTAL_SCORE FROM ".$tbl_wiki."
- WHERE c_id = $course_id AND ".$groupfilter.$condition_session."
- GROUP BY reflink ";
- //group by because mark in all versions, then always is ok.
- // Do not use "count" because using "group by", would give a wrong value
- $allpages = Database::query($sql);
- $total_score = 0;
- while ($row = Database::fetch_array($allpages)) {
- $total_score = $total_score + $row['TOTAL_SCORE'];
- }
- if (!empty($total_pages)) {
- $media_score = $total_score / $total_pages;
- //put always this line alfter check num all pages
- }
- // Average user progress in his pages.
- $media_progress = 0;
- $sql = 'SELECT *, SUM(progress) AS TOTAL_PROGRESS
- FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=
- (
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.'
- )';
- // As the value is only the latest version I can not use group by
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_progress = $row['TOTAL_PROGRESS'];
- }
- if (!empty($total_pages)) {
- $media_progress = $total_progress / $total_pages;
- //put always this line alfter check num all pages
- }
- // Total users that have participated in the Wiki
- $total_users = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY user_id';
- //as the mark of user it in all versions of the page, I can use group by to see the first
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_users = $total_users + 1;
- }
- // Total of different IP addresses that have participated in the wiki
- $total_ip = 0;
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY user_ip';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $total_ip = $total_ip + 1;
- }
- echo '<table class="data_table">';
- echo '<thead>';
- echo '<tr>';
- echo '<th colspan="2">'.get_lang('General').'</th>';
- echo '</tr>';
- echo '</thead>';
- echo '<tr>';
- echo '<td>'.get_lang('StudentAddNewPages').'</td>';
- echo '<td>'.$status_add_new_pag.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('DateCreateOldestWikiPage').'</td>';
- echo '<td>'.$first_wiki_date.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('DateEditLatestWikiVersion').'</td>';
- echo '<td>'.$last_wiki_date.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('AverageScoreAllPages').'</td>';
- echo '<td>'.$media_score.' %</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('AverageMediaUserProgress').'</td>';
- echo '<td>'.$media_progress.' %</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalWikiUsers').'</td>';
- echo '<td>'.$total_users.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalIpAdress').'</td>';
- echo '<td>'.$total_ip.'</td>';
- echo '</tr>';
- echo '</table>';
- echo '<br/>';
- echo '<table class="data_table">';
- echo '<thead>';
- echo '<tr>';
- echo '<th colspan="2">'.get_lang('Pages').' '.get_lang(
- 'And'
- ).' '.get_lang('Versions').'</th>';
- echo '</tr>';
- echo '</thead>';
- echo '<tr>';
- echo '<td>'.get_lang('Pages').' - '.get_lang(
- 'NumContributions'
- ).'</td>';
- echo '<td>'.$total_pages.' ('.get_lang(
- 'Versions'
- ).': '.$total_versions.')</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('EmptyPages').'</td>';
- echo '<td>'.$total_empty_content_lv.' ('.get_lang(
- 'Versions'
- ).': '.$total_empty_content.')</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumAccess').'</td>';
- echo '<td>'.$total_visits_lv.' ('.get_lang(
- 'Versions'
- ).': '.$total_visits.')</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalPagesEditedAtThisTime').'</td>';
- echo '<td>'.$total_editing_now.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalHiddenPages').'</td>';
- echo '<td>'.$total_hidden.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumProtectedPages').'</td>';
- echo '<td>'.$total_protected.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('LockedDiscussPages').'</td>';
- echo '<td>'.$total_lock_disc.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('HiddenDiscussPages').'</td>';
- echo '<td>'.$total_hidden_disc.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalComments').'</td>';
- echo '<td>'.$total_comment_version.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalOnlyRatingByTeacher').'</td>';
- echo '<td>'.$total_only_teachers_rating.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalRatingPeers').'</td>';
- echo '<td>'.$total_rating_by_peers.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalTeacherAssignments').' - '.get_lang(
- 'PortfolioMode'
- ).'</td>';
- echo '<td>'.$total_teacher_assignment.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalStudentAssignments').' - '.get_lang(
- 'PortfolioMode'
- ).'</td>';
- echo '<td>'.$total_student_assignment.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('TotalTask').' - '.get_lang(
- 'StandardMode'
- ).'</td>';
- echo '<td>'.$total_task.'</td>';
- echo '</tr>';
- echo '</table>';
- echo '<br/>';
- echo '<table class="data_table">';
- echo '<thead>';
- echo '<tr>';
- echo '<th colspan="3">'.get_lang('ContentPagesInfo').'</th>';
- echo '</tr>';
- echo '<tr>';
- echo '<td></td>';
- echo '<td>'.get_lang('InTheLastVersion').'</td>';
- echo '<td>'.get_lang('InAllVersions').'</td>';
- echo '</tr>';
- echo '</thead>';
- echo '<tr>';
- echo '<td>'.get_lang('NumWords').'</td>';
- echo '<td>'.$total_words_lv.'</td>';
- echo '<td>'.$total_words.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumlinksHtmlImagMedia').'</td>';
- echo '<td>'.$total_links_lv.' ('.get_lang(
- 'Anchors'
- ).':'.$total_links_anchors_lv.', Mail:'.$total_links_mail_lv.', FTP:'.$total_links_ftp_lv.' IRC:'.$total_links_irc_lv.', News:'.$total_links_news_lv.', ... ) </td>';
- echo '<td>'.$total_links.' ('.get_lang(
- 'Anchors'
- ).':'.$total_links_anchors.', Mail:'.$total_links_mail.', FTP:'.$total_links_ftp.', IRC:'.$total_links_irc.', News:'.$total_links_news.', ... ) </td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumWikilinks').'</td>';
- echo '<td>'.$total_wlinks_lv.'</td>';
- echo '<td>'.$total_wlinks.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumImages').'</td>';
- echo '<td>'.$total_images_lv.'</td>';
- echo '<td>'.$total_images.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumFlash').'</td>';
- echo '<td>'.$total_flash_lv.'</td>';
- echo '<td>'.$total_flash.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumMp3').'</td>';
- echo '<td>'.$total_mp3_lv.'</td>';
- echo '<td>'.$total_mp3.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumFlvVideo').'</td>';
- echo '<td>'.$total_flv_lv.'</td>';
- echo '<td>'.$total_flv.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumYoutubeVideo').'</td>';
- echo '<td>'.$total_youtube_lv.'</td>';
- echo '<td>'.$total_youtube.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumOtherAudioVideo').'</td>';
- echo '<td>'.$total_multimedia_lv.'</td>';
- echo '<td>'.$total_multimedia.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.get_lang('NumTables').'</td>';
- echo '<td>'.$total_tables_lv.'</td>';
- echo '<td>'.$total_tables.'</td>';
- echo '</tr>';
- echo '</table>';
- }
- /**
- * @param string $action
- */
- public function getActiveUsers($action)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $_course = $this->courseInfo;
- echo '<div class="actions">'.get_lang('MostActiveUsers').'</div>';
- $sql = 'SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY user_id';
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- while ($obj = Database::fetch_object($allpages)) {
- $userinfo = api_get_user_info($obj->user_id);
- $row = [];
- if ($obj->user_id != 0 && $userinfo !== false) {
- $row[] = UserManager::getUserProfileLink($userinfo).'
- <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode(
- $obj->user_id
- ).
- '&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities(
- $_GET['group_id']
- ).'"></a>';
- } else {
- $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
- }
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode(
- $obj->user_id
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities(
- $_GET['group_id']
- ).'">'.$obj->NUM_EDIT.'</a>';
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 1,
- 10,
- 'MostActiveUsersA_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($action),
- 'session_id' => Security::remove_XSS($_GET['session_id']),
- 'group_id' => Security::remove_XSS($_GET['group_id']),
- ]
- );
- $table->set_header(0, get_lang('Author'), true);
- $table->set_header(
- 1,
- get_lang('Contributions'),
- true,
- ['style' => 'width:30px;']
- );
- $table->display();
- }
- }
- /**
- * @param string $page
- */
- public function getDiscuss($page)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $tbl_wiki_discuss = $this->tbl_wiki_discuss;
- if (api_get_session_id() != 0 &&
- api_is_allowed_to_session_edit(false, true) == false
- ) {
- api_not_allowed();
- }
- if (!$_GET['title']) {
- Display::addFlash(
- Display::return_message(
- get_lang("MustSelectPage"),
- 'error',
- false
- )
- );
- return;
- }
- // First extract the date of last version
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink = "'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $lastversiondate = api_get_local_time($row['dtime']);
- $lastuserinfo = api_get_user_info($row['user_id']);
- // Select page to discuss
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id ASC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $id = $row['id'];
- $firstuserid = $row['user_id'];
- if (isset($_POST['Submit']) && self::double_post($_POST['wpost_id'])) {
- $dtime = api_get_utc_datetime();
- $message_author = api_get_user_id();
- $params = [
- 'c_id' => $course_id,
- 'publication_id' => $id,
- 'userc_id' => $message_author,
- 'comment' => $_POST['comment'],
- 'p_score' => $_POST['rating'],
- 'dtime' => $dtime,
- ];
- $discussId = Database::insert($tbl_wiki_discuss, $params);
- if ($discussId) {
- $sql = "UPDATE $tbl_wiki_discuss SET id = iid WHERE iid = $discussId";
- Database::query($sql);
- }
- self::check_emailcue($id, 'D', $dtime, $message_author);
- header(
- 'Location: index.php?action=discuss&title='.api_htmlentities(urlencode($page)).'&'.api_get_cidreq()
- );
- exit;
- }
- // mode assignment: previous to show page type
- $icon_assignment = null;
- if ($row['assignment'] == 1) {
- $icon_assignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDescExtra'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 2) {
- $icon_assignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWorkExtra'),
- '',
- ICON_SIZE_SMALL
- );
- }
- $countWPost = null;
- $avg_WPost_score = null;
- // Show title and form to discuss if page exist
- if ($id != '') {
- // Show discussion to students if isn't hidden.
- // Show page to all teachers if is hidden.
- // Mode assignments: If is hidden, show pages to student only if student is the author
- if ($row['visibility_disc'] == 1 ||
- api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- ($row['assignment'] == 2 && $row['visibility_disc'] == 0 && (api_get_user_id() == $row['user_id']))
- ) {
- echo '<div id="wikititle">';
- // discussion action: protecting (locking) the discussion
- $addlock_disc = null;
- $lock_unlock_disc = null;
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if (self::check_addlock_discuss() == 1) {
- $addlock_disc = Display::return_icon(
- 'unlock.png',
- get_lang('UnlockDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_disc = 'unlockdisc';
- } else {
- $addlock_disc = Display::return_icon(
- 'lock.png',
- get_lang('LockDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_disc = 'lockdisc';
- }
- }
- echo '<span style="float:right">';
- echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_disc.'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.$addlock_disc.'</a>';
- echo '</span>';
- // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
- $visibility_disc = null;
- $hide_show_disc = null;
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if (self::check_visibility_discuss() == 1) {
- /// TODO: Fix Mode assignments: If is hidden, show discussion to student only if student is the author
- $visibility_disc = Display::return_icon(
- 'visible.png',
- get_lang('ShowDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $hide_show_disc = 'hidedisc';
- } else {
- $visibility_disc = Display::return_icon(
- 'invisible.png',
- get_lang('HideDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $hide_show_disc = 'showdisc';
- }
- }
- echo '<span style="float:right">';
- echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$hide_show_disc.'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.$visibility_disc.'</a>';
- echo '</span>';
- // discussion action: check add rating lock. Show/Hide list to rating for all student
- $lock_unlock_rating_disc = null;
- $ratinglock_disc = null;
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- if (self::check_ratinglock_discuss() == 1) {
- $ratinglock_disc = Display::return_icon(
- 'star.png',
- get_lang('UnlockRatingDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_rating_disc = 'unlockrating';
- } else {
- $ratinglock_disc = Display::return_icon(
- 'star_na.png',
- get_lang('LockRatingDiscussExtra'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_rating_disc = 'lockrating';
- }
- }
- echo '<span style="float:right">';
- echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_rating_disc.'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.$ratinglock_disc.'</a>';
- echo '</span>';
- // discussion action: email notification
- if (self::check_notify_discuss($page) == 1) {
- $notify_disc = Display::return_icon(
- 'messagebox_info.png',
- get_lang('NotifyDiscussByEmail'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_notify_disc = 'unlocknotifydisc';
- } else {
- $notify_disc = Display::return_icon(
- 'mail.png',
- get_lang('CancelNotifyDiscussByEmail'),
- '',
- ICON_SIZE_SMALL
- );
- $lock_unlock_notify_disc = 'locknotifydisc';
- }
- echo '<span style="float:right">';
- echo '<a href="index.php?'.api_get_cidreq().'&action=discuss&actionpage='.$lock_unlock_notify_disc.'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.$notify_disc.'</a>';
- echo '</span>';
- echo $icon_assignment.' '.api_htmlentities(
- $row['title']
- );
- if ($lastuserinfo !== false) {
- echo ' ('.get_lang('MostRecentVersionBy').' '.
- UserManager::getUserProfileLink($lastuserinfo).' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read average score
- }
- echo '</div>';
- if ($row['addlock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- //show comments but students can't add theirs
- ?>
- <div class="panel panel-default">
- <div class="panel-body">
- <form name="form1" method="post" action=""
- class="form-horizontal">
- <div class="form-group">
- <label
- class="col-sm-2 control-label">
- <?php echo get_lang('Comments'); ?>:</label>
- <div class="col-sm-10">
- <?php echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">'; //prevent double post?>
- <textarea class="form-control"
- name="comment" cols="80"
- rows="5"
- id="comment">
- </textarea>
- </div>
- </div>
- <div class="form-group">
- <?php
- //check if rating is allowed
- if ($row['ratinglock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- ?>
- <label
- class="col-sm-2 control-label"><?php echo get_lang('Rating'); ?>:</label>
- <div class="col-sm-10">
- <select name="rating" id="rating" class="selectpicker">
- <option value="-" selected>-</option>
- <option value="0">0</option>
- <option value="1">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- <option value="4">4</option>
- <option value="5">5</option>
- <option value="6">6</option>
- <option value="7">7</option>
- <option value="8">8</option>
- <option value="9">9</option>
- <option value="10">10</option>
- </select>
- </div>
- <?php
- } else {
- echo '<input type=hidden name="rating" value="-">';
- // must pass a default value to avoid rate automatically
- } ?>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <?php echo '<button class="btn btn-default" type="submit" name="Submit"> '.
- get_lang('Send').'</button>'; ?>
- </div>
- </div>
- </div>
- </div>
- </form>
- <?php
- }
- // end discuss lock
- echo '<hr noshade size="1">';
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT *
- FROM $tbl_wiki_discuss reviews, $user_table user
- WHERE
- reviews.c_id = $course_id AND
- reviews.publication_id='".$id."' AND
- user.user_id='".$firstuserid."'
- ORDER BY reviews.id DESC";
- $result = Database::query($sql);
- $countWPost = Database::num_rows($result);
- echo get_lang('NumComments').": ".$countWPost; //comment's numbers
- $sql = "SELECT SUM(p_score) as sumWPost
- FROM $tbl_wiki_discuss
- WHERE c_id = $course_id AND publication_id = '".$id."' AND NOT p_score='-'
- ORDER BY id DESC";
- $result2 = Database::query($sql);
- $row2 = Database::fetch_array($result2);
- $sql = "SELECT * FROM $tbl_wiki_discuss
- WHERE c_id = $course_id AND publication_id='".$id."' AND NOT p_score='-'";
- $result3 = Database::query($sql);
- $countWPost_score = Database::num_rows($result3);
- echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;
- if ($countWPost_score != 0) {
- $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score, 2).' / 10';
- } else {
- $avg_WPost_score = $countWPost_score;
- }
- echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
- $sql = 'UPDATE '.$tbl_wiki.' SET
- score = "'.Database::escape_string($avg_WPost_score).'"
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- // check if work ok. TODO:
- Database::query($sql);
- echo '<hr noshade size="1">';
- while ($row = Database::fetch_array($result)) {
- $userinfo = api_get_user_info($row['userc_id']);
- if (($userinfo['status']) == "5") {
- $author_status = get_lang('Student');
- } else {
- $author_status = get_lang('Teacher');
- }
- $name = $userinfo['complete_name'];
- $author_photo = '<img src="'.$userinfo['avatar'].'" alt="'.api_htmlentities($name).'" width="40" height="50" align="top" title="'.api_htmlentities($name).'" />';
- // stars
- $p_score = $row['p_score'];
- switch ($p_score) {
- case 0:
- $imagerating = Display::return_icon(
- 'rating/stars_0.gif'
- );
- break;
- case 1:
- $imagerating = Display::return_icon(
- 'rating/stars_5.gif'
- );
- break;
- case 2:
- $imagerating = Display::return_icon(
- 'rating/stars_10.gif'
- );
- break;
- case 3:
- $imagerating = Display::return_icon(
- 'rating/stars_15.gif'
- );
- break;
- case 4:
- $imagerating = Display::return_icon(
- 'rating/stars_20.gif'
- );
- break;
- case 5:
- $imagerating = Display::return_icon(
- 'rating/stars_25.gif'
- );
- break;
- case 6:
- $imagerating = Display::return_icon(
- 'rating/stars_30.gif'
- );
- break;
- case 7:
- $imagerating = Display::return_icon(
- 'rating/stars_35.gif'
- );
- break;
- case 8:
- $imagerating = Display::return_icon(
- 'rating/stars_40.gif'
- );
- break;
- case 9:
- $imagerating = Display::return_icon(
- 'rating/stars_45.gif'
- );
- break;
- case 10:
- $imagerating = Display::return_icon(
- 'rating/stars_50.gif'
- );
- break;
- }
- echo '<p><table>';
- echo '<tr>';
- echo '<td rowspan="2">'.$author_photo.'</td>';
- $userProfile = '';
- if ($userinfo !== false) {
- $userProfile = UserManager::getUserProfileLink(
- $userinfo
- );
- }
- echo '<td style=" color:#999999">'.$userProfile.' ('.$author_status.') '.
- api_get_local_time(
- $row['dtime']
- ).
- ' - '.get_lang(
- 'Rating'
- ).': '.$row['p_score'].' '.$imagerating.' </td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.api_htmlentities($row['comment']).'</td>';
- echo '</tr>';
- echo "</table>";
- }
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('LockByTeacher'),
- 'warning',
- false
- )
- );
- }
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('DiscussNotAvailable'),
- 'normal',
- false
- )
- );
- }
- }
- /**
- * Show all pages.
- */
- public function allPages($action)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $session_id = $this->session_id;
- $groupfilter = $this->groupfilter;
- $_course = $this->courseInfo;
- echo '<div class="actions">'.get_lang('AllPages');
- // menu delete all wiki
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- echo ' <a href="index.php?action=deletewiki&'.api_get_cidreq().'">'.
- Display::return_icon(
- 'delete.png',
- get_lang('DeleteWiki'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- echo '</div>';
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- // only by professors if page is hidden
- // warning don't use group by reflink because does not return the last version
- $sql = 'SELECT *
- FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.')';
- } else {
- // warning don't use group by reflink because does not return the last version
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE visibility=1 AND s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.' AND
- session_id='.$session_id.')';
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- while ($obj = Database::fetch_object($allpages)) {
- //get author
- $userinfo = api_get_user_info($obj->user_id);
- $username = api_htmlentities(
- sprintf(get_lang('LoginX'), $userinfo['username']),
- ENT_QUOTES
- );
- //get type assignment icon
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- //get icon task
- if (!empty($obj->task)) {
- $icon_task = Display::return_icon(
- 'wiki_task.png',
- get_lang('StandardTask'),
- '',
- ICON_SIZE_SMALL
- );
- } else {
- $icon_task = Display::return_icon('px_transparent.gif');
- }
- $row = [];
- $row[] = $ShowAssignment.$icon_task;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">
- '.api_htmlentities($obj->title).'</a>';
- if ($userinfo !== false) {
- $row[] = UserManager::getUserProfileLink($userinfo);
- } else {
- $row[] = get_lang('Anonymous').' ('.api_htmlentities(
- $obj->user_ip
- ).')';
- }
- $row[] = api_get_local_time(
- $obj->dtime
- );
- $showdelete = '';
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- $showdelete = ' <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=delete&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'delete.png',
- get_lang('Delete'),
- '',
- ICON_SIZE_SMALL
- );
- }
- if (api_is_allowed_to_session_edit(false, true)) {
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=edit&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'edit.png',
- get_lang('EditPage'),
- '',
- ICON_SIZE_SMALL
- ).'</a> <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'discuss.png',
- get_lang('Discuss'),
- '',
- ICON_SIZE_SMALL
- ).'</a> <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'history.png',
- get_lang('History'),
- '',
- ICON_SIZE_SMALL
- ).'</a>
- <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- Display::return_icon(
- 'what_link_here.png',
- get_lang('LinksPages'),
- '',
- ICON_SIZE_SMALL
- ).'</a>'.$showdelete;
- }
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 1,
- 10,
- 'AllPages_table',
- '',
- '',
- 'ASC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($action),
- 'group_id' => Security::remove_XSS($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- $table->set_header(
- 2,
- get_lang('Author').' ('.get_lang('LastVersion').')',
- true
- );
- $table->set_header(
- 3,
- get_lang('Date').' ('.get_lang('LastVersion').')',
- true
- );
- if (api_is_allowed_to_session_edit(false, true)) {
- $table->set_header(
- 4,
- get_lang('Actions'),
- true,
- ['style' => 'width:130px;']
- );
- }
- $table->display();
- }
- }
- /**
- * Get recent changes.
- *
- * @param string $page
- * @param string $action
- */
- public function recentChanges($page, $action)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- if (api_is_allowed_to_session_edit(false, true)) {
- if (self::check_notify_all() == 1) {
- $notify_all = Display::return_icon(
- 'messagebox_info.png',
- get_lang('NotifyByEmail'),
- '',
- ICON_SIZE_SMALL
- ).' '.get_lang('NotNotifyChanges');
- $lock_unlock_notify_all = 'unlocknotifyall';
- } else {
- $notify_all = Display::return_icon(
- 'mail.png',
- get_lang('CancelNotifyByEmail'),
- '',
- ICON_SIZE_SMALL
- ).' '.get_lang('NotifyChanges');
- $lock_unlock_notify_all = 'locknotifyall';
- }
- }
- echo '<div class="actions"><span style="float: right;">';
- echo '<a href="index.php?action=recentchanges&actionpage='.$lock_unlock_notify_all.'&'.api_get_cidreq().'&title='.api_htmlentities(
- urlencode($page)
- ).'">'.$notify_all.'</a>';
- echo '</span>'.get_lang('RecentChanges').'</div>';
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- //only by professors if page is hidden
- $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
- WHERE '.$tbl_wiki_conf.'.c_id= '.$course_id.' AND
- '.$tbl_wiki.'.c_id= '.$course_id.' AND
- '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
- '.$tbl_wiki.'.'.$groupfilter.$condition_session.'
- ORDER BY dtime DESC'; // new version
- } else {
- $sql = 'SELECT *
- FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- '.$groupfilter.$condition_session.' AND
- visibility=1
- ORDER BY dtime DESC';
- // old version TODO: Replace by the bottom line
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- $rows = [];
- while ($obj = Database::fetch_object($allpages)) {
- //get author
- $userinfo = api_get_user_info($obj->user_id);
- //get type assignment icon
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- // Get icon task
- if (!empty($obj->task)) {
- $icon_task = Display::return_icon(
- 'wiki_task.png',
- get_lang('StandardTask'),
- '',
- ICON_SIZE_SMALL
- );
- } else {
- $icon_task = Display::return_icon('px_transparent.gif');
- }
- $row = [];
- $row[] = api_get_local_time(
- $obj->dtime
- );
- $row[] = $ShowAssignment.$icon_task;
- $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&view='.$obj->id.'&session_id='.api_get_session_id(
- ).'&group_id='.api_get_group_id().'">'.
- api_htmlentities($obj->title).'</a>';
- $row[] = $obj->version > 1 ? get_lang('EditedBy') : get_lang(
- 'AddedBy'
- );
- if ($userinfo !== false) {
- $row[] = UserManager::getUserProfileLink($userinfo);
- } else {
- $row[] = get_lang('Anonymous').' ('.api_htmlentities(
- $obj->user_ip
- ).')';
- }
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 0,
- 10,
- 'RecentPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => api_get_course_id(),
- 'action' => Security::remove_XSS($action),
- 'session_id' => api_get_session_id(),
- 'group_id' => api_get_group_id(),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Date'),
- true,
- ['style' => 'width:200px;']
- );
- $table->set_header(
- 1,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(2, get_lang('Title'), true);
- $table->set_header(
- 3,
- get_lang('Actions'),
- true,
- ['style' => 'width:80px;']
- );
- $table->set_header(4, get_lang('Author'), true);
- $table->display();
- }
- }
- /**
- * What links here. Show pages that have linked this page.
- *
- * @param string $page
- */
- public function getLinks($page)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $_course = $this->courseInfo;
- $action = $this->action;
- if (!$_GET['title']) {
- Display::addFlash(
- Display::return_message(
- get_lang("MustSelectPage"),
- 'error',
- false
- )
- );
- } else {
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- //get type assignment icon
- $ShowAssignment = '';
- if ($row['assignment'] == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 0) {
- $ShowAssignment = Display::return_icon('px_transparent.gif');
- }
- //fix Title to reflink (link Main Page)
- if ($page == get_lang('DefaultTitle')) {
- $page = 'index';
- }
- echo '<div id="wikititle">';
- echo get_lang(
- 'LinksPagesFrom'
- ).': '.$ShowAssignment.' <a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($page)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- api_htmlentities($row['title']).'</a>';
- echo '</div>';
- //fix index to title Main page into linksto
- if ($page == 'index') {
- $page = str_replace(' ', '_', get_lang('DefaultTitle'));
- }
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- // only by professors if page is hidden
- //only by professors if page is hidden
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE s1.c_id = $course_id AND linksto LIKE '%".Database::escape_string(
- $page
- )."%' AND id=(
- SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
- WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";
- } else {
- //add blank space after like '%" " %' to identify each word
- $sql = "SELECT * FROM ".$tbl_wiki." s1
- WHERE s1.c_id = $course_id AND visibility=1 AND linksto LIKE '%".Database::escape_string(
- $page
- )."%' AND id=(
- SELECT MAX(s2.id) FROM ".$tbl_wiki." s2
- WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- $rows = [];
- while ($obj = Database::fetch_object($allpages)) {
- //get author
- $userinfo = api_get_user_info($obj->user_id);
- //get time
- $year = substr($obj->dtime, 0, 4);
- $month = substr($obj->dtime, 5, 2);
- $day = substr($obj->dtime, 8, 2);
- $hours = substr($obj->dtime, 11, 2);
- $minutes = substr($obj->dtime, 14, 2);
- $seconds = substr($obj->dtime, 17, 2);
- //get type assignment icon
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- $row = [];
- $row[] = $ShowAssignment;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- api_htmlentities($obj->title).'</a>';
- if ($userinfo !== false) {
- $row[] = UserManager::getUserProfileLink($userinfo);
- } else {
- $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
- }
- $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 1,
- 10,
- 'AllPages_table',
- '',
- '',
- 'ASC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($action),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- $table->set_header(2, get_lang('Author'), true);
- $table->set_header(3, get_lang('Date'), true);
- $table->display();
- }
- }
- }
- /**
- * @param string $action
- */
- public function getSearchPages($action)
- {
- echo '<div class="actions">'.get_lang('SearchPages').'</div>';
- if (isset($_GET['mode_table'])) {
- if (!isset($_GET['SearchPages_table_page_nr'])) {
- $_GET['search_term'] = isset($_POST['search_term']) ? $_POST['search_term'] : '';
- $_GET['search_content'] = isset($_POST['search_content']) ? $_POST['search_content'] : '';
- $_GET['all_vers'] = isset($_POST['all_vers']) ? $_POST['all_vers'] : '';
- }
- self::display_wiki_search_results(
- $_GET['search_term'],
- $_GET['search_content'],
- $_GET['all_vers']
- );
- } else {
- // initiate the object
- $form = new FormValidator(
- 'wiki_search',
- 'post',
- api_get_self().'?cidReq='.api_get_course_id(
- ).'&action='.api_htmlentities(
- $action
- ).'&session_id='.api_get_session_id(
- ).'&group_id='.api_get_group_id().'&mode_table=yes1'
- );
- // Setting the form elements
- $form->addText(
- 'search_term',
- get_lang('SearchTerm'),
- true,
- ['autofocus' => 'autofocus']
- );
- $form->addElement(
- 'checkbox',
- 'search_content',
- null,
- get_lang('AlsoSearchContent')
- );
- $form->addElement(
- 'checkbox',
- 'all_vers',
- null,
- get_lang('IncludeAllVersions')
- );
- $form->addButtonSearch(get_lang('Search'), 'SubmitWikiSearch');
- // setting the rules
- $form->addRule(
- 'search_term',
- get_lang('TooShort'),
- 'minlength',
- 3
- ); //TODO: before fixing the pagination rules worked, not now
- if ($form->validate()) {
- $form->display();
- $values = $form->exportValues();
- self::display_wiki_search_results(
- $values['search_term'],
- $values['search_content'],
- $values['all_vers']
- );
- } else {
- $form->display();
- }
- }
- }
- /**
- * @param int $userId
- * @param string $action
- */
- public function getUserContributions($userId, $action)
- {
- $_course = $this->courseInfo;
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $userId = intval($userId);
- $userinfo = api_get_user_info($userId);
- if ($userinfo !== false) {
- echo '<div class="actions">'.
- get_lang('UserContributions').': '.UserManager::getUserProfileLink($userinfo).
- '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.$userId.
- '&session_id='.$this->session_id.'&group_id='.$this->group_id.'">'.
- '</a></div>';
- }
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- //only by professors if page is hidden
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- '.$groupfilter.$condition_session.' AND
- user_id="'.$userId.'"';
- } else {
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- '.$groupfilter.$condition_session.' AND
- user_id="'.$userId.'" AND
- visibility=1';
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- $rows = [];
- while ($obj = Database::fetch_object($allpages)) {
- //get type assignment icon
- $ShowAssignment = '';
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDescExtra'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- $row = [];
- $row[] = api_get_local_time($obj->dtime);
- $row[] = $ShowAssignment;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&view='.$obj->id.'&session_id='.api_get_session_id(
- ).'&group_id='.api_get_group_id().'">'.
- api_htmlentities($obj->title).'</a>';
- $row[] = Security::remove_XSS($obj->version);
- $row[] = Security::remove_XSS($obj->comment);
- $row[] = Security::remove_XSS($obj->progress).' %';
- $row[] = Security::remove_XSS($obj->score);
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 2,
- 10,
- 'UsersContributions_table',
- '',
- '',
- 'ASC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($action),
- 'user_id' => intval($userId),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Date'),
- true,
- ['style' => 'width:200px;']
- );
- $table->set_header(
- 1,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(
- 2,
- get_lang('Title'),
- true,
- ['style' => 'width:200px;']
- );
- $table->set_header(
- 3,
- get_lang('Version'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(
- 4,
- get_lang('Comment'),
- true,
- ['style' => 'width:200px;']
- );
- $table->set_header(
- 5,
- get_lang('Progress'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(
- 6,
- get_lang('Rating'),
- true,
- ['style' => 'width:30px;']
- );
- $table->display();
- }
- }
- /**
- * @param string $action
- */
- public function getMostChangedPages($action)
- {
- $_course = $this->courseInfo;
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin()
- ) { //only by professors if page is hidden
- $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY reflink'; //TODO:check MAX and group by return last version
- } else {
- $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1
- GROUP BY reflink'; //TODO:check MAX and group by return last version
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- $rows = [];
- while ($obj = Database::fetch_object($allpages)) {
- //get type assignment icon
- $ShowAssignment = '';
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- $row = [];
- $row[] = $ShowAssignment;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- api_htmlentities($obj->title).'</a>';
- $row[] = $obj->MAX;
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 2,
- 10,
- 'MostChangedPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($action),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- $table->set_header(2, get_lang('Changes'), true);
- $table->display();
- }
- }
- /**
- * Restore page.
- *
- * @return bool
- */
- public function restorePage()
- {
- $userId = api_get_user_id();
- $_course = $this->courseInfo;
- $current_row = $this->getWikiData();
- $last_row = $this->getLastWikiData($this->page);
- if (empty($last_row)) {
- return false;
- }
- $PassEdit = false;
- /* Only teachers and platform admin can edit the index page.
- Only teachers and platform admin can edit an assignment teacher*/
- if (($current_row['reflink'] == 'index' ||
- $current_row['reflink'] == '' ||
- $current_row['assignment'] == 1) &&
- (!api_is_allowed_to_edit(false, true) &&
- $this->group_id == 0)
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyEditPagesCourseManager'),
- 'normal',
- false
- )
- );
- } else {
- // check if is a wiki group
- if ($current_row['group_id'] != 0) {
- $groupInfo = GroupManager::get_group_properties(
- $this->group_id
- );
- //Only teacher, platform admin and group members can edit a wiki group
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- GroupManager::is_user_in_group($userId, $groupInfo) ||
- api_is_allowed_in_course()
- ) {
- $PassEdit = true;
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyEditPagesGroupMembers'),
- 'normal',
- false
- )
- );
- }
- } else {
- $PassEdit = true;
- }
- // check if is an assignment
- //$icon_assignment = null;
- if ($current_row['assignment'] == 1) {
- Display::addFlash(
- Display::return_message(
- get_lang('EditAssignmentWarning'),
- 'normal',
- false
- )
- );
- } elseif ($current_row['assignment'] == 2) {
- if (($userId == $current_row['user_id']) == false) {
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- $PassEdit = true;
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('LockByTeacher'),
- 'normal',
- false
- )
- );
- $PassEdit = false;
- }
- } else {
- $PassEdit = true;
- }
- }
- //show editor if edit is allowed
- if ($PassEdit) {
- if ($current_row['editlock'] == 1 &&
- (api_is_allowed_to_edit(false, true) == false ||
- api_is_platform_admin() == false)
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang('PageLockedExtra'),
- 'normal',
- false
- )
- );
- } else {
- if ($last_row['is_editing'] != 0 && $last_row['is_editing'] != $userId) {
- // Checking for concurrent users
- $timestamp_edit = strtotime($last_row['time_edit']);
- $time_editing = time() - $timestamp_edit;
- $max_edit_time = 1200; // 20 minutes
- $rest_time = $max_edit_time - $time_editing;
- $userinfo = api_get_user_info($last_row['is_editing']);
- $is_being_edited = get_lang(
- 'ThisPageisBeginEditedBy'
- ).' <a href='.$userinfo['profile_url'].'>'.
- Display::tag(
- 'span',
- $userinfo['complete_name_with_username']
- ).
- get_lang('ThisPageisBeginEditedTryLater').' '.date(
- "i",
- $rest_time
- ).' '.get_lang('MinMinutes');
- Display::addFlash(
- Display::return_message(
- $is_being_edited,
- 'normal',
- false
- )
- );
- } else {
- Display::addFlash(
- Display::return_message(
- self::restore_wikipage(
- $current_row['page_id'],
- $current_row['reflink'],
- $current_row['title'],
- $current_row['content'],
- $current_row['group_id'],
- $current_row['assignment'],
- $current_row['progress'],
- $current_row['version'],
- $last_row['version'],
- $current_row['linksto']
- ).': <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($last_row['reflink'])
- ).'&session_id='.$last_row['session_id'].'&group_id='.$last_row['group_id'].'">'.
- api_htmlentities($last_row['title']).'</a>',
- 'confirmation',
- false
- )
- );
- }
- }
- }
- }
- }
- /**
- * @param int|bool $wikiId
- */
- public function setWikiData($wikiId)
- {
- $this->wikiData = self::getWikiDataFromDb($wikiId);
- }
- /**
- * @return array
- */
- public function getWikiData()
- {
- return $this->wikiData;
- }
- /**
- * Check last version.
- *
- * @param int $view
- *
- * @return bool
- */
- public function checkLastVersion($view)
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $page = $this->page;
- $_course = $this->courseInfo;
- if (empty($view)) {
- return false;
- }
- $current_row = $this->getWikiData();
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink = "'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id DESC'; //last version
- $result = Database::query($sql);
- $last_row = Database::fetch_array($result);
- if ($view < $last_row['id']) {
- $message = '<center>'.get_lang('NoAreSeeingTheLastVersion').'<br />
- '.get_lang("Version").' (
- <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($current_row['reflink'])
- ).'&group_id='.$current_row['group_id'].'&session_id='.$current_row['session_id'].'&view='.api_htmlentities(
- $_GET['view']
- ).'" title="'.get_lang('CurrentVersion').'">
- '.$current_row['version'].'
- </a> /
- <a href="index.php?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($last_row['reflink'])
- ).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'" title="'.get_lang(
- 'LastVersion'
- ).'">
- '.$last_row['version'].'
- </a>) <br />'.get_lang("ConvertToLastVersion").':
- <a href="index.php?cidReq='.$_course['id'].'&action=restorepage&title='.api_htmlentities(
- urlencode($last_row['reflink'])
- ).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'&view='.api_htmlentities(
- $_GET['view']
- ).'">'.
- get_lang("Restore").'</a></center>';
- Display::addFlash(
- Display::return_message($message, 'warning', false)
- );
- }
- }
- /**
- * Get most linked pages.
- */
- public function getMostLinked()
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- $_course = $this->courseInfo;
- echo '<div class="actions">'.get_lang('MostLinkedPages').'</div>';
- $pages = [];
- $linked = [];
- // Get name pages
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY reflink
- ORDER BY reflink ASC';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- if ($row['reflink'] == 'index') {
- $row['reflink'] = str_replace(
- ' ',
- '_',
- get_lang('DefaultTitle')
- );
- }
- $pages[] = $row['reflink'];
- }
- // Get name refs in last pages
- $sql = 'SELECT *
- FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.$condition_session.'
- )';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- //remove self reference
- $row['linksto'] = str_replace(
- $row["reflink"],
- " ",
- trim($row["linksto"])
- );
- $refs = explode(" ", trim($row["linksto"]));
- // Find linksto into reflink. If found ->page is linked
- foreach ($refs as $v) {
- if (in_array($v, $pages)) {
- if (trim($v) != "") {
- $linked[] = $v;
- }
- }
- }
- }
- $linked = array_unique($linked);
- //make a unique list. TODO:delete this line and count how many for each page
- //show table
- $rows = [];
- foreach ($linked as $linked_show) {
- $row = [];
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode(str_replace('_', ' ', $linked_show))
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- str_replace('_', ' ', $linked_show).'</a>';
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 0,
- 10,
- 'LinkedPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($this->action),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(0, get_lang('Title'), true);
- $table->display();
- }
- /**
- * Get orphan pages.
- */
- public function getOrphaned()
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- $_course = $this->courseInfo;
- echo '<div class="actions">'.get_lang('OrphanedPages').'</div>';
- $pages = [];
- $orphaned = [];
- //get name pages
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY reflink
- ORDER BY reflink ASC';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $pages[] = $row['reflink'];
- }
- //get name refs in last pages and make a unique list
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE
- s2.c_id = '.$course_id.' AND
- s1.reflink = s2.reflink AND
- '.$groupfilter.$condition_session.'
- )';
- $allpages = Database::query($sql);
- $array_refs_linked = [];
- while ($row = Database::fetch_array($allpages)) {
- $row['linksto'] = str_replace(
- $row["reflink"],
- " ",
- trim($row["linksto"])
- ); //remove self reference
- $refs = explode(" ", trim($row["linksto"]));
- foreach ($refs as $ref_linked) {
- if ($ref_linked == str_replace(
- ' ',
- '_',
- get_lang('DefaultTitle')
- )) {
- $ref_linked = 'index';
- }
- $array_refs_linked[] = $ref_linked;
- }
- }
- $array_refs_linked = array_unique($array_refs_linked);
- //search each name of list linksto into list reflink
- foreach ($pages as $v) {
- if (!in_array($v, $array_refs_linked)) {
- $orphaned[] = $v;
- }
- }
- $rows = [];
- foreach ($orphaned as $orphaned_show) {
- // get visibility status and title
- $sql = 'SELECT *
- FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- '.$groupfilter.$condition_session.' AND
- reflink="'.Database::escape_string($orphaned_show).'"
- GROUP BY reflink';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $orphaned_title = $row['title'];
- $orphaned_visibility = $row['visibility'];
- if ($row['assignment'] == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- '',
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 2) {
- $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- '',
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- }
- if (!api_is_allowed_to_edit(false, true) || !api_is_platform_admin(
- ) && $orphaned_visibility == 0) {
- continue;
- }
- //show table
- $row = [];
- $row[] = $ShowAssignment;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($orphaned_show)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- api_htmlentities($orphaned_title).'</a>';
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 1,
- 10,
- 'OrphanedPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($this->action),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- $table->display();
- }
- /**
- * Get wanted pages.
- */
- public function getWantedPages()
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- echo '<div class="actions">'.get_lang('WantedPages').'</div>';
- $pages = [];
- $wanted = [];
- //get name pages
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY reflink
- ORDER BY reflink ASC';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- if ($row['reflink'] == 'index') {
- $row['reflink'] = str_replace(
- ' ',
- '_',
- get_lang('DefaultTitle')
- );
- }
- $pages[] = $row['reflink'];
- }
- //get name refs in last pages
- $sql = 'SELECT * FROM '.$tbl_wiki.' s1
- WHERE s1.c_id = '.$course_id.' AND id=(
- SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
- WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.$condition_session.'
- )';
- $allpages = Database::query($sql);
- while ($row = Database::fetch_array($allpages)) {
- $refs = explode(" ", trim($row["linksto"]));
- // Find linksto into reflink. If not found ->page is wanted
- foreach ($refs as $v) {
- if (!in_array($v, $pages)) {
- if (trim($v) != "") {
- $wanted[] = $v;
- }
- }
- }
- }
- $wanted = array_unique($wanted); //make a unique list
- //show table
- $rows = [];
- foreach ($wanted as $wanted_show) {
- $row = [];
- $wanted_show = Security::remove_XSS($wanted_show);
- $row[] = '<a href="'.api_get_path(
- WEB_PATH
- ).'main/wiki/index.php?cidReq=&action=addnew&title='.str_replace(
- '_',
- ' ',
- $wanted_show
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities(
- $_GET['group_id']
- ).'" class="new_wiki_link">'.str_replace(
- '_',
- ' ',
- $wanted_show
- ).'</a>'; //meter un remove xss en lugar de htmlentities
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 0,
- 10,
- 'WantedPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($this->action),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(0, get_lang('Title'), true);
- $table->display();
- }
- /**
- * Most visited.
- */
- public function getMostVisited()
- {
- $tbl_wiki = $this->tbl_wiki;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- $_course = $this->courseInfo;
- echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin(
- )) { //only by professors if page is hidden
- $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
- WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
- GROUP BY reflink';
- } else {
- $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- '.$groupfilter.$condition_session.' AND
- visibility=1
- GROUP BY reflink';
- }
- $allpages = Database::query($sql);
- //show table
- if (Database::num_rows($allpages) > 0) {
- $rows = [];
- while ($obj = Database::fetch_object($allpages)) {
- //get type assignment icon
- $ShowAssignment = '';
- if ($obj->assignment == 1) {
- $ShowAssignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDesc'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 2) {
- $ShowAssignment = $ShowAssignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWork'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($obj->assignment == 0) {
- $ShowAssignment = Display::return_icon(
- 'px_transparent.gif'
- );
- }
- $row = [];
- $row[] = $ShowAssignment;
- $row[] = '<a href="'.api_get_self(
- ).'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(
- urlencode($obj->reflink)
- ).'&session_id='.api_htmlentities(
- $_GET['session_id']
- ).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
- api_htmlentities($obj->title).'</a>';
- $row[] = $obj->tsum;
- $rows[] = $row;
- }
- $table = new SortableTableFromArrayConfig(
- $rows,
- 2,
- 10,
- 'MostVisitedPages_table',
- '',
- '',
- 'DESC'
- );
- $table->set_additional_parameters(
- [
- 'cidReq' => Security::remove_XSS($_GET['cidReq']),
- 'action' => Security::remove_XSS($this->action),
- 'session_id' => intval($_GET['session_id']),
- 'group_id' => intval($_GET['group_id']),
- ]
- );
- $table->set_header(
- 0,
- get_lang('Type'),
- true,
- ['style' => 'width:30px;']
- );
- $table->set_header(1, get_lang('Title'), true);
- $table->set_header(2, get_lang('Visits'), true);
- $table->display();
- }
- }
- /**
- * Get actions bar.
- *
- * @return string
- */
- public function showActionBar()
- {
- $_course = $this->courseInfo;
- $session_id = $this->session_id;
- $groupId = $this->group_id;
- $page = $this->page;
- $actionsLeft = '';
- $actionsLeft .= '<a href="index.php?action=showpage&title=index&cidReq='.$_course['id'].'&session_id='.$session_id.'&group_id='.$groupId.'">'.
- Display::return_icon(
- 'home.png',
- get_lang('Home'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- if (api_is_allowed_to_session_edit(
- false,
- true
- ) && api_is_allowed_to_edit()) {
- // menu add page
- $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=addnew&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
- 'addnew'
- ).'>'
- .Display::return_icon(
- 'new_document.png',
- get_lang('AddNew'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- }
- $lock_unlock_addnew = null;
- $protect_addnewpage = null;
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- // page action: enable or disable the adding of new pages
- if (self::check_addnewpagelock() == 0) {
- $protect_addnewpage = Display::return_icon(
- 'off.png',
- get_lang('AddOptionProtected')
- );
- $lock_unlock_addnew = 'unlockaddnew';
- } else {
- $protect_addnewpage = Display::return_icon(
- 'on.png',
- get_lang('AddOptionUnprotected')
- );
- $lock_unlock_addnew = 'lockaddnew';
- }
- }
- // menu find
- $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=searchpages&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
- 'searchpages'
- ).'>'.
- Display::return_icon(
- 'search.png',
- get_lang('SearchPages'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- ///menu more
- $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=searchpages&session_id='.$session_id.'&group_id='.$groupId.'&action=more&title='.api_htmlentities(
- urlencode($page)
- ).'"'.self::is_active_navigation_tab('more').'>'.
- Display::return_icon(
- 'statistics.png',
- get_lang('Statistics'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- // menu all pages
- $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=allpages&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
- 'allpages'
- ).'>'.
- Display::return_icon(
- 'list_badges.png',
- get_lang('AllPages'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- // menu recent changes
- $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=recentchanges&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab(
- 'recentchanges'
- ).'>'.
- Display::return_icon(
- 'history.png',
- get_lang('RecentChanges'),
- '',
- ICON_SIZE_MEDIUM
- ).'</a>';
- echo Display::toolbarAction('toolbar-wiki', [$actionsLeft]);
- }
- /**
- * Showing warning.
- */
- public function deletePageWarning()
- {
- $page = $this->page;
- $course_id = $this->course_id;
- $groupfilter = $this->groupfilter;
- $condition_session = $this->condition_session;
- if (!$_GET['title']) {
- Display::addFlash(
- Display::return_message(
- get_lang('MustSelectPage'),
- 'error',
- false
- )
- );
- return;
- }
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- Display::addFlash(
- '<div id="wikititle">'.get_lang('DeletePageHistory').'</div>'
- );
- if ($page == "index") {
- Display::addFlash(
- Display::return_message(
- get_lang('WarningDeleteMainPage'),
- 'warning',
- false
- )
- );
- }
- $message = get_lang('ConfirmDeletePage')."
- <a href=\"index.php?".api_get_cidreq()."\">".get_lang("No")."</a>
- <a href=\"".api_get_self()."?".api_get_cidreq(
- )."&action=delete&title=".api_htmlentities(
- urlencode($page)
- )."&delete=yes\">".
- get_lang("Yes")."</a>";
- if (!isset($_GET['delete'])) {
- Display::addFlash(
- Display::return_message($message, 'warning', false)
- );
- }
- if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
- $result = self::deletePage(
- $page,
- $course_id,
- $groupfilter,
- $condition_session
- );
- if ($result) {
- Display::addFlash(
- Display::return_message(
- get_lang('WikiPageDeleted'),
- 'confirmation',
- false
- )
- );
- }
- }
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyAdminDeletePageWiki'),
- 'normal',
- false
- )
- );
- }
- }
- /**
- * Edit page.
- */
- public function editPage()
- {
- $tbl_wiki = $this->tbl_wiki;
- $tbl_wiki_conf = $this->tbl_wiki_conf;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $page = $this->page;
- $course_id = $this->course_id;
- $groupId = $this->group_id;
- $userId = api_get_user_id();
- if (api_get_session_id() != 0 &&
- api_is_allowed_to_session_edit(false, true) == false
- ) {
- api_not_allowed();
- }
- $sql = 'SELECT *
- FROM '.$tbl_wiki.' w INNER JOIN '.$tbl_wiki_conf.' c
- ON (w.c_id = c.c_id AND w.page_id = c.page_id)
- WHERE
- w.c_id = '.$course_id.' AND
- w.reflink= "'.Database::escape_string($page).'" AND
- w.'.$groupfilter.$condition_session.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- // we do not need a while loop since we are always displaying the last version
- if ($row['content'] == '' && $row['title'] == '' && $page == '') {
- Display::addFlash(
- Display::return_message(
- get_lang('MustSelectPage'),
- 'error',
- false
- )
- );
- return;
- } elseif ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
- // Table structure for better export to pdf
- $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
- $default_table_for_content_End = '</td></tr></table>';
- $content = $default_table_for_content_Start.sprintf(
- get_lang('DefaultContent'),
- api_get_path(WEB_IMG_PATH)
- ).$default_table_for_content_End;
- $title = get_lang('DefaultTitle');
- $page_id = 0;
- } else {
- $content = api_html_entity_decode($row['content']);
- $title = api_html_entity_decode($row['title']);
- $page_id = $row['page_id'];
- }
- // Only teachers and platform admin can edit the index page.
- // Only teachers and platform admin can edit an assignment teacher.
- // And users in groups
- if (($row['reflink'] == 'index' || $row['reflink'] == '' || $row['assignment'] == 1) &&
- (!api_is_allowed_to_edit(
- false,
- true
- ) && $groupId == 0) && !api_is_allowed_in_course()
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyEditPagesCourseManager'),
- 'error'
- )
- );
- } else {
- $PassEdit = false;
- // Check if is a wiki group
- if (!empty($groupId)) {
- $groupInfo = GroupManager::get_group_properties($groupId);
- //Only teacher, platform admin and group members can edit a wiki group
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- GroupManager::is_user_in_group($userId, $groupInfo)
- ) {
- $PassEdit = true;
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyEditPagesGroupMembers')
- )
- );
- }
- } else {
- $PassEdit = true;
- }
- $icon_assignment = null;
- // check if is a assignment
- if ($row['assignment'] == 1) {
- Display::addFlash(
- Display::return_message(get_lang('EditAssignmentWarning'))
- );
- $icon_assignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDescExtra'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($row['assignment'] == 2) {
- $icon_assignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWorkExtra'),
- '',
- ICON_SIZE_SMALL
- );
- if (($userId == $row['user_id']) == false) {
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- $PassEdit = true;
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('LockByTeacher'),
- 'warning'
- )
- );
- $PassEdit = false;
- }
- } else {
- $PassEdit = true;
- }
- }
- if ($PassEdit) {
- //show editor if edit is allowed <<<<<
- if ($row['editlock'] == 1 &&
- (api_is_allowed_to_edit(false, true) == false ||
- api_is_platform_admin() == false)
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang('PageLockedExtra')
- )
- );
- } else {
- // Check tasks
- if (!empty($row['startdate_assig']) && time() <
- api_strtotime($row['startdate_assig'])
- ) {
- $message = get_lang(
- 'TheTaskDoesNotBeginUntil'
- ).': '.api_get_local_time($row['startdate_assig']);
- Display::addFlash(
- Display::return_message(
- $message,
- 'warning'
- )
- );
- if (!api_is_allowed_to_edit(false, true)) {
- $this->redirectHome();
- }
- }
- if (!empty($row['enddate_assig']) &&
- time() > strtotime($row['enddate_assig']) &&
- $row['delayedsubmit'] == 0
- ) {
- $message = get_lang(
- 'TheDeadlineHasBeenCompleted'
- ).': '.api_get_local_time($row['enddate_assig']);
- Display::addFlash(
- Display::return_message(
- $message,
- 'warning'
- )
- );
- if (!api_is_allowed_to_edit(false, true)) {
- $this->redirectHome();
- }
- }
- if (!empty($row['max_version']) && $row['version'] >= $row['max_version']) {
- $message = get_lang('HasReachedMaxiNumVersions');
- Display::addFlash(
- Display::return_message(
- $message,
- 'warning'
- )
- );
- if (!api_is_allowed_to_edit(false, true)) {
- $this->redirectHome();
- }
- }
- if (!empty($row['max_text']) && $row['max_text'] <= self::word_count(
- $row['content']
- )) {
- $message = get_lang('HasReachedMaxNumWords');
- Display::addFlash(
- Display::return_message(
- $message,
- 'warning'
- )
- );
- if (!api_is_allowed_to_edit(false, true)) {
- $this->redirectHome();
- }
- }
- if (!empty($row['task'])) {
- //previous change 0 by text
- if (!empty($row['startdate_assig'])) {
- $message_task_startdate = get_lang('No');
- } else {
- $message_task_startdate = api_get_local_time(
- $row['startdate_assig']
- );
- }
- if (!empty($row['enddate_assig'])) {
- $message_task_enddate = get_lang('No');
- } else {
- $message_task_enddate = api_get_local_time(
- $row['enddate_assig']
- );
- }
- if ($row['delayedsubmit'] == 0) {
- $message_task_delayedsubmit = get_lang('No');
- } else {
- $message_task_delayedsubmit = get_lang('Yes');
- }
- if ($row['max_version'] == 0) {
- $message_task_max_version = get_lang('No');
- } else {
- $message_task_max_version = $row['max_version'];
- }
- if ($row['max_text'] == 0) {
- $message_task_max_text = get_lang('No');
- } else {
- $message_task_max_text = $row['max_text'];
- }
- // Comp message
- $message_task = '<b>'.get_lang(
- 'DescriptionOfTheTask'
- ).'</b><p>'.$row['task'].'</p><hr>';
- $message_task .= '<p>'.get_lang(
- 'StartDate'
- ).': '.$message_task_startdate.'</p>';
- $message_task .= '<p>'.get_lang(
- 'EndDate'
- ).': '.$message_task_enddate;
- $message_task .= ' ('.get_lang(
- 'AllowLaterSends'
- ).') '.$message_task_delayedsubmit.'</p>';
- $message_task .= '<p>'.get_lang(
- 'OtherSettings'
- ).': '.get_lang(
- 'NMaxVersion'
- ).': '.$message_task_max_version;
- $message_task .= ' '.get_lang(
- 'NMaxWords'
- ).': '.$message_task_max_text;
- // Display message
- Display::addFlash(
- Display::return_message(
- $message_task
- )
- );
- }
- $feedback_message = '';
- if ($row['progress'] == $row['fprogress1'] && !empty($row['fprogress1'])) {
- $feedback_message = '<b>'.get_lang(
- 'Feedback'
- ).'</b><p>'.api_htmlentities(
- $row['feedback1']
- ).'</p>';
- } elseif ($row['progress'] == $row['fprogress2'] && !empty($row['fprogress2'])) {
- $feedback_message = '<b>'.get_lang(
- 'Feedback'
- ).'</b><p>'.api_htmlentities(
- $row['feedback2']
- ).'</p>';
- } elseif ($row['progress'] == $row['fprogress3'] && !empty($row['fprogress3'])) {
- $feedback_message = '<b>'.get_lang(
- 'Feedback'
- ).'</b><p>'.api_htmlentities(
- $row['feedback3']
- ).'</p>';
- }
- if (!empty($feedback_message)) {
- Display::addFlash(
- Display::return_message(
- $feedback_message
- )
- );
- }
- // Previous checking for concurrent editions
- if ($row['is_editing'] == 0) {
- Display::addFlash(
- Display::return_message(
- get_lang('WarningMaxEditingTime')
- )
- );
- $time_edit = api_get_utc_datetime();
- $sql = 'UPDATE '.$tbl_wiki.' SET
- is_editing = "'.$userId.'",
- time_edit = "'.$time_edit.'"
- WHERE c_id = '.$course_id.' AND id="'.$row['id'].'"';
- Database::query($sql);
- } elseif ($row['is_editing'] != $userId) {
- $timestamp_edit = strtotime($row['time_edit']);
- $time_editing = time() - $timestamp_edit;
- $max_edit_time = 1200; // 20 minutes
- $rest_time = $max_edit_time - $time_editing;
- $userinfo = api_get_user_info($row['is_editing']);
- if ($userinfo !== false) {
- $is_being_edited = get_lang(
- 'ThisPageisBeginEditedBy'
- ).' '.UserManager::getUserProfileLink(
- $userinfo
- ).'
- '.get_lang(
- 'ThisPageisBeginEditedTryLater'
- ).' '.date("i", $rest_time).' '.get_lang(
- 'MinMinutes'
- ).'';
- }
- Display::addFlash(
- Display::return_message(
- $is_being_edited,
- 'normal',
- false
- )
- );
- $this->redirectHome();
- }
- // Form.
- $url = api_get_self().'?action=edit&title='.urlencode(
- $page
- ).'&session_id='.api_get_session_id(
- ).'&group_id='.api_get_group_id().'&'.api_get_cidreq();
- $form = new FormValidator('wiki', 'post', $url);
- $form->addElement(
- 'header',
- $icon_assignment.str_repeat(
- ' ',
- 3
- ).api_htmlentities($title)
- );
- self::setForm($form, $row);
- $form->addElement('hidden', 'title');
- $form->addButtonSave(get_lang('Save'), 'SaveWikiChange');
- $row['title'] = $title;
- $row['page_id'] = $page_id;
- $row['reflink'] = $page;
- $row['content'] = $content;
- $form->setDefaults($row);
- $form->display();
- // Saving a change
- if ($form->validate()) {
- $versionFromSession = Session::read('_version');
- if (empty($_POST['title'])) {
- Display::addFlash(
- Display::return_message(
- get_lang("NoWikiPageTitle"),
- 'error'
- )
- );
- } elseif (!self::double_post($_POST['wpost_id'])) {
- //double post
- } elseif ($_POST['version'] != '' && $versionFromSession != 0 && $_POST['version'] != $versionFromSession) {
- //prevent concurrent users and double version
- Display::addFlash(
- Display::return_message(
- get_lang("EditedByAnotherUser"),
- 'error'
- )
- );
- } else {
- $returnMessage = self::save_wiki(
- $form->exportValues()
- );
- Display::addFlash(
- Display::return_message(
- $returnMessage,
- 'confirmation'
- )
- );
- }
- $wikiData = self::getWikiData();
- $redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq(
- );
- header('Location: '.$redirectUrl);
- exit;
- }
- }
- }
- }
- }
- /**
- * Get history.
- */
- public function getHistory()
- {
- $tbl_wiki = $this->tbl_wiki;
- $condition_session = $this->condition_session;
- $groupfilter = $this->groupfilter;
- $page = $this->page;
- $course_id = $this->course_id;
- $session_id = $this->session_id;
- $userId = api_get_user_id();
- if (!$_GET['title']) {
- Display::addFlash(
- Display::return_message(
- get_lang("MustSelectPage"),
- 'error',
- false
- )
- );
- return;
- }
- /* First, see the property visibility that is at the last register and
- therefore we should select descending order.
- But to give ownership to each record,
- this is no longer necessary except for the title. TODO: check this*/
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- $KeyVisibility = null;
- $KeyAssignment = null;
- $KeyTitle = null;
- $KeyUserId = null;
- while ($row = Database::fetch_array($result)) {
- $KeyVisibility = $row['visibility'];
- $KeyAssignment = $row['assignment'];
- $KeyTitle = $row['title'];
- $KeyUserId = $row['user_id'];
- }
- $icon_assignment = null;
- if ($KeyAssignment == 1) {
- $icon_assignment = Display::return_icon(
- 'wiki_assignment.png',
- get_lang('AssignmentDescExtra'),
- '',
- ICON_SIZE_SMALL
- );
- } elseif ($KeyAssignment == 2) {
- $icon_assignment = Display::return_icon(
- 'wiki_work.png',
- get_lang('AssignmentWorkExtra'),
- '',
- ICON_SIZE_SMALL
- );
- }
- // Second, show
- //if the page is hidden and is a job only sees its author and professor
- if ($KeyVisibility == 1 ||
- api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- (
- $KeyAssignment == 2 && $KeyVisibility == 0 &&
- ($userId == $KeyUserId)
- )
- ) {
- // We show the complete history
- if (!isset($_POST['HistoryDifferences']) &&
- !isset($_POST['HistoryDifferences2'])
- ) {
- $sql = 'SELECT * FROM '.$tbl_wiki.'
- WHERE
- c_id = '.$course_id.' AND
- reflink="'.Database::escape_string($page).'" AND
- '.$groupfilter.$condition_session.'
- ORDER BY id DESC';
- $result = Database::query($sql);
- $title = $_GET['title'];
- $group_id = api_get_group_id();
- echo '<div id="wikititle">';
- echo $icon_assignment.' '.api_htmlentities(
- $KeyTitle
- );
- echo '</div>';
- echo '<form id="differences" method="POST" action="index.php?'.api_get_cidreq(
- ).'&action=history&title='.api_htmlentities(
- urlencode($title)
- ).'&session_id='.api_htmlentities(
- $session_id
- ).'&group_id='.api_htmlentities($group_id).'">';
- echo '<ul style="list-style-type: none;">';
- echo '<br/>';
- echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.
- get_lang('ShowDifferences').' '.get_lang(
- 'LinesDiff'
- ).'</button>';
- echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.
- get_lang('ShowDifferences').' '.get_lang(
- 'WordsDiff'
- ).'</button>';
- echo '<br/><br/>';
- $counter = 0;
- $total_versions = Database::num_rows($result);
- while ($row = Database::fetch_array($result)) {
- $userinfo = api_get_user_info($row['user_id']);
- $username = api_htmlentities(
- sprintf(get_lang('LoginX'), $userinfo['username']),
- ENT_QUOTES
- );
- echo '<li style="margin-bottom: 5px;">';
- ($counter == 0) ? $oldstyle = 'style="visibility: hidden;"' : $oldstyle = '';
- ($counter == 0) ? $newchecked = ' checked' : $newchecked = '';
- ($counter == $total_versions - 1) ? $newstyle = 'style="visibility: hidden;"' : $newstyle = '';
- ($counter == 1) ? $oldchecked = ' checked' : $oldchecked = '';
- echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
- echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
- echo '<a href="'.api_get_self(
- ).'?action=showpage&title='.api_htmlentities(
- urlencode($page)
- ).'&view='.$row['id'].'">';
- echo '<a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=showpage&title='.api_htmlentities(
- urlencode($page)
- ).'&view='.$row['id'].'">';
- echo api_get_local_time(
- $row['dtime']
- );
- echo '</a>';
- echo ' ('.get_lang('Version').' '.$row['version'].')';
- echo ' '.get_lang('By').' ';
- if ($userinfo !== false) {
- echo UserManager::getUserProfileLink($userinfo);
- } else {
- echo get_lang('Anonymous').' ('.api_htmlentities(
- $row['user_ip']
- ).')';
- }
- echo ' ( '.get_lang('Progress').': '.api_htmlentities(
- $row['progress']
- ).'%, ';
- $comment = $row['comment'];
- if (!empty($comment)) {
- $comment = api_substr($comment, 0, 100);
- if ($comment !== false) {
- $comment = api_htmlentities($comment);
- echo get_lang('Comments').': '.$comment;
- if (api_strlen($row['comment']) > 100) {
- echo '... ';
- }
- }
- } else {
- echo get_lang('Comments').': ---';
- }
- echo ' ) </li>';
- $counter++;
- } //end while
- echo '<br/>';
- echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang(
- 'ShowDifferences'
- ).' '.get_lang('LinesDiff').'</button>';
- echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang(
- 'ShowDifferences'
- ).' '.get_lang('WordsDiff').'</button>';
- echo '</ul></form>';
- } else { // We show the differences between two versions
- $version_old = [];
- if (isset($_POST['old'])) {
- $sql_old = "SELECT * FROM $tbl_wiki
- WHERE c_id = $course_id AND id='".Database::escape_string(
- $_POST['old']
- )."'";
- $result_old = Database::query($sql_old);
- $version_old = Database::fetch_array($result_old);
- }
- $sql_new = "SELECT * FROM $tbl_wiki
- WHERE
- c_id = $course_id AND
- id = '".Database::escape_string($_POST['new'])."'";
- $result_new = Database::query($sql_new);
- $version_new = Database::fetch_array($result_new);
- $oldTime = isset($version_old['dtime']) ? api_get_local_time($version_old['dtime']) : null;
- $oldContent = isset($version_old['content']) ? $version_old['content'] : null;
- if (isset($_POST['HistoryDifferences'])) {
- include 'diff.inc.php';
- //title
- echo '<div id="wikititle">'.api_htmlentities(
- $version_new['title']
- ).'
- <font size="-2"><i>('.get_lang('DifferencesNew').'</i>
- <font style="background-color:#aaaaaa">'.api_get_local_time($version_new['dtime']).'</font>
- <i>'.get_lang('DifferencesOld').'</i>
- <font style="background-color:#aaaaaa">'.$oldTime.'</font>
- ) '.get_lang('Legend').': <span class="diffAdded" >'.get_lang(
- 'WikiDiffAddedLine'
- ).'</span>
- <span class="diffDeleted" >'.get_lang(
- 'WikiDiffDeletedLine'
- ).'</span> <span class="diffMoved">'.get_lang(
- 'WikiDiffMovedLine'
- ).'</span></font>
- </div>';
- }
- if (isset($_POST['HistoryDifferences2'])) {
- //title
- echo '<div id="wikititle">'.api_htmlentities(
- $version_new['title']
- ).'
- <font size="-2"><i>('.get_lang(
- 'DifferencesNew'
- ).'</i> <font style="background-color:#aaaaaa">'.api_get_local_time($version_new['dtime']).'</font>
- <i>'.get_lang(
- 'DifferencesOld'
- ).'</i> <font style="background-color:#aaaaaa">'.$oldTime.'</font>)
- '.get_lang(
- 'Legend'
- ).': <span class="diffAddedTex" >'.get_lang(
- 'WikiDiffAddedTex'
- ).'</span>
- <span class="diffDeletedTex" >'.get_lang(
- 'WikiDiffDeletedTex'
- ).'</span></font></div>';
- }
- if (isset($_POST['HistoryDifferences'])) {
- echo '<table>'.diff(
- $oldContent,
- $version_new['content'],
- true,
- 'format_table_line'
- ).'</table>'; // format_line mode is better for words
- echo '<br />';
- echo '<strong>'.get_lang(
- 'Legend'
- ).'</strong><div class="diff">'."\n";
- echo '<table><tr>';
- echo '<td>';
- echo '</td><td>';
- echo '<span class="diffEqual" >'.get_lang(
- 'WikiDiffUnchangedLine'
- ).'</span><br />';
- echo '<span class="diffAdded" >'.get_lang(
- 'WikiDiffAddedLine'
- ).'</span><br />';
- echo '<span class="diffDeleted" >'.get_lang(
- 'WikiDiffDeletedLine'
- ).'</span><br />';
- echo '<span class="diffMoved" >'.get_lang(
- 'WikiDiffMovedLine'
- ).'</span><br />';
- echo '</td>';
- echo '</tr></table>';
- }
- if (isset($_POST['HistoryDifferences2'])) {
- $lines1 = [strip_tags($oldContent)]; //without <> tags
- $lines2 = [
- strip_tags(
- $version_new['content']
- ),
- ]; //without <> tags
- $diff = new Text_Diff($lines1, $lines2);
- $renderer = new Text_Diff_Renderer_inline();
- echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render(
- $diff
- ); // Code inline
- echo '<br />';
- echo '<strong>'.get_lang(
- 'Legend'
- ).'</strong><div class="diff">'."\n";
- echo '<table><tr>';
- echo '<td>';
- echo '</td><td>';
- echo '<span class="diffAddedTex" >'.get_lang(
- 'WikiDiffAddedTex'
- ).'</span><br />';
- echo '<span class="diffDeletedTex" >'.get_lang(
- 'WikiDiffDeletedTex'
- ).'</span><br />';
- echo '</td>';
- echo '</tr></table>';
- }
- }
- }
- }
- /**
- * Get stat tables.
- */
- public function getStatsTable()
- {
- $_course = $this->courseInfo;
- $session_id = $this->session_id;
- $groupId = $this->group_id;
- echo '<div class="actions">'.get_lang('More').'</div>';
- echo '<table border="0">';
- echo ' <tr>';
- echo ' <td>';
- echo ' <ul>';
- //Submenu Most active users
- echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mactiveusers&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'MostActiveUsers'
- ).'</a></li>';
- //Submenu Most visited pages
- echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mvisited&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'MostVisitedPages'
- ).'</a></li>';
- //Submenu Most changed pages
- echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=mostchanged&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'MostChangedPages'
- ).'</a></li>';
- echo ' </ul>';
- echo ' </td>';
- echo ' <td>';
- echo ' <ul>';
- // Submenu Orphaned pages
- echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=orphaned&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'OrphanedPages'
- ).'</a></li>';
- // Submenu Wanted pages
- echo ' <li><a href="index.php?cidReq='.$_course['code'].'&action=wanted&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'WantedPages'
- ).'</a></li>';
- // Submenu Most linked pages
- echo '<li><a href="index.php?cidReq='.$_course['code'].'&action=mostlinked&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'MostLinkedPages'
- ).'</a></li>';
- echo '</ul>';
- echo '</td>';
- echo '<td style="vertical-align:top">';
- echo '<ul>';
- // Submenu Statistics
- if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
- echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=statistics&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang(
- 'Statistics'
- ).'</a></li>';
- }
- echo ' </ul>';
- echo ' </td>';
- echo ' </tr>';
- echo '</table>';
- }
- /**
- * Kind of controller.
- *
- * @param string $action
- */
- public function handleAction($action)
- {
- $page = $this->page;
- switch ($action) {
- case 'export_to_pdf':
- if (isset($_GET['wiki_id'])) {
- self::export_to_pdf($_GET['wiki_id'], api_get_course_id());
- break;
- }
- break;
- case 'export2doc':
- if (isset($_GET['wiki_id'])) {
- $export2doc = self::export2doc($_GET['wiki_id']);
- if ($export2doc) {
- Display::addFlash(
- Display::return_message(
- get_lang('ThePageHasBeenExportedToDocArea'),
- 'confirmation',
- false
- )
- );
- }
- }
- break;
- case 'restorepage':
- self::restorePage();
- break;
- case 'more':
- self::getStatsTable();
- break;
- case 'statistics':
- self::getStats();
- break;
- case 'mactiveusers':
- self::getActiveUsers($action);
- break;
- case 'usercontrib':
- self::getUserContributions($_GET['user_id'], $action);
- break;
- case 'mostchanged':
- $this->getMostChangedPages($action);
- break;
- case 'mvisited':
- self::getMostVisited();
- break;
- case 'wanted':
- $this->getWantedPages();
- break;
- case 'orphaned':
- self::getOrphaned();
- break;
- case 'mostlinked':
- self::getMostLinked();
- break;
- case 'delete':
- self::deletePageWarning($page);
- break;
- case 'deletewiki':
- $title = '<div class="actions">'.get_lang(
- 'DeleteWiki'
- ).'</div>';
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- $message = get_lang('ConfirmDeleteWiki');
- $message .= '<p>
- <a href="index.php?'.api_get_cidreq().'">'.get_lang(
- 'No'
- ).'</a>
- |
- <a href="'.api_get_self().'?'.api_get_cidreq(
- ).'&action=deletewiki&delete=yes">'.
- get_lang('Yes').'</a>
- </p>';
- if (!isset($_GET['delete'])) {
- Display::addFlash(
- $title.Display::return_message(
- $message,
- 'warning',
- false
- )
- );
- }
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang("OnlyAdminDeleteWiki"),
- 'normal',
- false
- )
- );
- }
- if (api_is_allowed_to_edit(
- false,
- true
- ) || api_is_platform_admin()) {
- if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
- $return_message = self::delete_wiki();
- Display::addFlash(
- Display::return_message(
- $return_message,
- 'confirmation',
- false
- )
- );
- $this->redirectHome();
- }
- }
- break;
- case 'searchpages':
- self::getSearchPages($action);
- break;
- case 'links':
- self::getLinks($page);
- break;
- case 'addnew':
- if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(
- false,
- true
- ) == false) {
- api_not_allowed();
- }
- $groupInfo = GroupManager::get_group_properties(
- api_get_group_id()
- );
- echo '<div class="actions">'.get_lang('AddNew').'</div>';
- echo '<br/>';
- //first, check if page index was created. chektitle=false
- if (self::checktitle('index')) {
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- GroupManager::is_user_in_group(
- api_get_user_id(),
- $groupInfo
- ) ||
- api_is_allowed_in_course()
- ) {
- Display::addFlash(
- Display::return_message(
- get_lang('GoAndEditMainPage'),
- 'normal',
- false
- )
- );
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('WikiStandBy'),
- 'normal',
- false
- )
- );
- }
- } elseif (self::check_addnewpagelock(
- ) == 0 && (api_is_allowed_to_edit(
- false,
- true
- ) == false || api_is_platform_admin() == false)) {
- Display::addFlash(
- Display::return_message(
- get_lang('AddPagesLocked'),
- 'error',
- false
- )
- );
- } else {
- $groupInfo = GroupManager::get_group_properties(
- api_get_group_id()
- );
- if (api_is_allowed_to_edit(false, true) ||
- api_is_platform_admin() ||
- GroupManager::is_user_in_group(
- api_get_user_id(),
- $groupInfo
- ) ||
- $_GET['group_id'] == 0
- ) {
- self::display_new_wiki_form();
- } else {
- Display::addFlash(
- Display::return_message(
- get_lang('OnlyAddPagesGroupMembers'),
- 'normal',
- false
- )
- );
- }
- }
- break;
- case 'show':
- self::display_wiki_entry($page);
- break;
- case 'showpage':
- self::display_wiki_entry($page);
- break;
- case 'edit':
- self::editPage();
- break;
- case 'history':
- self::getHistory();
- break;
- case 'recentchanges':
- self::recentChanges($page, $action);
- break;
- case 'allpages':
- self::allPages($action);
- break;
- case 'discuss':
- self::getDiscuss($page);
- break;
- case 'export_to_doc_file':
- self::exportTo($_GET['id'], 'odt');
- exit;
- break;
- }
- }
- /**
- * Redirect to home.
- */
- public function redirectHome()
- {
- $redirectUrl = $this->url.'&action=showpage&title=index';
- header('Location: '.$redirectUrl.'&'.api_get_cidreq());
- exit;
- }
- /**
- * Export wiki content in a ODF.
- *
- * @param int $id
- * @param string int
- *
- * @return bool
- */
- public function exportTo($id, $format = 'doc')
- {
- $data = self::getWikiDataFromDb($id);
- if (isset($data['content']) && !empty($data['content'])) {
- Export::htmlToOdt($data['content'], $data['reflink'], $format);
- }
- return false;
- }
- }
|