wiki.inc.php 243 KB

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