wiki.inc.php 233 KB

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