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