wiki.inc.php 238 KB

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