index.php 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * The Dokeos wiki is a further development of the CoolWiki plugin.
  20. *
  21. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  22. * @Author Juan Carlos Raña <herodoto@telefonica.net>
  23. * @Copyright Ghent University
  24. * @Copyright Patrick Cool
  25. *
  26. * @package dokeos.wiki
  27. */
  28. // name of the language file that needs to be included
  29. $language_file = 'wiki';
  30. // security
  31. if(isset($_GET['id_session']))
  32. {
  33. $_SESSION['id_session'] = Security::remove_XSS($_GET['id_session']);
  34. }
  35. // including the global dokeos file
  36. include('../inc/global.inc.php');
  37. // section (for the tabs)
  38. $this_section=SECTION_COURSES;
  39. // including additional library scripts
  40. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  41. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  42. require_once (api_get_path(LIBRARY_PATH).'text.lib.php');
  43. require_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  44. require_once (api_get_path(LIBRARY_PATH).'security.lib.php');
  45. require_once (api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php');
  46. require_once (api_get_path(INCLUDE_PATH).'conf/mail.conf.php');
  47. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  48. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  49. // additional style information
  50. $htmlHeadXtra[] ='<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'wiki/css/default.css"/>';
  51. // Database table definition
  52. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  53. $tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS);
  54. $tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE);
  55. /*
  56. -----------------------------------------------------------
  57. Constants and variables
  58. -----------------------------------------------------------
  59. */
  60. $tool_name = get_lang('Wiki');
  61. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  62. /*
  63. ----------------------------------------------------------
  64. ACCESS
  65. -----------------------------------------------------------
  66. */
  67. api_protect_course_script();
  68. api_block_anonymous_users();
  69. /*
  70. -----------------------------------------------------------
  71. TRACKING
  72. -----------------------------------------------------------
  73. */
  74. event_access_tool(TOOL_WIKI);
  75. /*
  76. -----------------------------------------------------------
  77. HEADER & TITLE
  78. -----------------------------------------------------------
  79. */
  80. // If it is a group wiki then the breadcrumbs will be different.
  81. if ($_SESSION['_gid'] OR $_GET['group_id'])
  82. {
  83. if (isset($_SESSION['_gid']))
  84. {
  85. $_clean['group_id']=(int)$_SESSION['_gid'];
  86. }
  87. if (isset($_GET['group_id']))
  88. {
  89. $_clean['group_id']=(int)Database::escape_string($_GET['group_id']);
  90. }
  91. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  92. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  93. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  94. $add_group_to_title = ' ('.$group_properties['name'].')';
  95. $groupfilter='group_id="'.$_clean['group_id'].'"';
  96. //ensure this tool in groups whe it's private or deactivated
  97. if ($group_properties['wiki_state']==0)
  98. {
  99. echo api_not_allowed();
  100. }
  101. elseif ($group_properties['wiki_state']==2)
  102. {
  103. if (!api_is_allowed_to_edit() and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid']))
  104. {
  105. echo api_not_allowed();
  106. }
  107. }
  108. }
  109. else
  110. {
  111. $groupfilter='group_id=0';
  112. }
  113. Display::display_header($tool_name, 'Wiki');
  114. $is_allowed_to_edit = api_is_allowed_to_edit();
  115. //api_display_tool_title($tool_name.$add_group_to_title);
  116. /*
  117. -----------------------------------------------------------
  118. INITIALISATION
  119. -----------------------------------------------------------
  120. */
  121. //the page we are dealing with
  122. if (!isset($_GET['title'])){
  123. $page='index';
  124. }
  125. else
  126. {
  127. $page=Security::remove_XSS($_GET['title']);
  128. }
  129. // some titles are not allowed
  130. // $not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now
  131. /*
  132. ==============================================================================
  133. MAIN CODE
  134. ==============================================================================
  135. */
  136. // Tool introduction
  137. $fck_attribute['Width'] = '100%';
  138. $fck_attribute['Height'] = '300';
  139. $fck_attribute['ToolbarSet'] = 'Introduction';
  140. Display::display_introduction_section(TOOL_WIKI);
  141. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  142. /*
  143. -----------------------------------------------------------
  144. Wiki configuration settings
  145. -----------------------------------------------------------
  146. */
  147. $fck_attribute['Width'] = '100%';
  148. $fck_attribute['Height'] = '400';
  149. if(!api_is_allowed_to_edit())
  150. {
  151. $fck_attribute['Config']['UserStatus'] = 'student';
  152. $fck_attribute['ToolbarSet'] = 'Wiki_Student';
  153. }
  154. else
  155. {
  156. $fck_attribute['ToolbarSet'] = 'Wiki';
  157. }
  158. /*
  159. -----------------------------------------------------------
  160. ACTIONS
  161. -----------------------------------------------------------
  162. */
  163. // saving a change
  164. if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'')
  165. {
  166. if(empty($_POST['title']))
  167. {
  168. Display::display_error_message(get_lang("NoWikiPageTitle"));
  169. }
  170. else
  171. {
  172. $return_message=save_wiki();
  173. Display::display_confirmation_message($return_message, false);
  174. }
  175. }
  176. //saving a new wiki entry
  177. if (isset($_POST['SaveWikiNew']))
  178. {
  179. if(empty($_POST['title']))
  180. {
  181. Display::display_error_message(get_lang("NoWikiPageTitle"));
  182. }
  183. else
  184. {
  185. $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment
  186. if ($_clean['assignment']==1)
  187. {
  188. auto_add_page_users($_clean['assignment']);
  189. }
  190. else
  191. {
  192. $return_message=save_new_wiki();
  193. Display::display_confirmation_message($return_message, false);
  194. }
  195. }
  196. }
  197. // check last version
  198. if ($_GET['view'])
  199. {
  200. $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.Database::escape_string($_GET['view']).'"'; //current view
  201. $result=api_sql_query($sql,__LINE__,__FILE__);
  202. $current_row=Database::fetch_array($result);
  203. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; //last version
  204. $result=api_sql_query($sql,__LINE__,__FILE__);
  205. $last_row=Database::fetch_array($result);
  206. if ($_GET['view']<$last_row['id'])
  207. {
  208. $message= '(<a href="index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.$current_row['reflink'].'&view='.Security::remove_XSS($_GET['view']).'&group_id='.$current_row['group_id'].'" title="'.get_lang('CurrentVersion').'">'.$current_row['version'].'</a> / <a href="index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.$last_row['reflink'].'&group_id='.$last_row['group_id'].'" title="'.get_lang('LastVersion').'">'.$last_row['version'].'</a>) '.get_lang('NoAreSeeingTheLastVersion').'<br />'.get_lang("ConvertToLastVersion").': <a href="index.php?cidReq='.$_course[id].'&action=restorepage&amp;title='.$last_row['reflink'].'&view='.Security::remove_XSS($_GET['view']).'">'.get_lang("Restore").'</a>';
  209. Display::display_warning_message($message,false);
  210. }
  211. ///restore page
  212. if ($_GET['action']=='restorepage')
  213. {
  214. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher
  215. if(($current_row['reflink']=='index' || $current_row['reflink']=='' || $current_row['assignment']==1) && (!api_is_allowed_to_edit()))
  216. {
  217. Display::display_normal_message(get_lang('OnlyEditPagesCourseManager'));
  218. }
  219. else
  220. {
  221. $PassEdit=false;
  222. //check if is a wiki group
  223. if($current_row['group_id']!=0)
  224. {
  225. //Only teacher, platform admin and group members can edit a wiki group
  226. if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
  227. {
  228. $PassEdit=true;
  229. }
  230. else
  231. {
  232. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  233. }
  234. }
  235. else
  236. {
  237. $PassEdit=true;
  238. }
  239. // check if is an assignment
  240. if(stripslashes($current_row['assignment'])==1)
  241. {
  242. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  243. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  244. }
  245. elseif(stripslashes($current_row['assignment'])==2)
  246. {
  247. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  248. if((api_get_user_id()==$current_row['user_id'])==false)
  249. {
  250. if(api_is_allowed_to_edit() || api_is_platform_admin())
  251. {
  252. $PassEdit=true;
  253. }
  254. else
  255. {
  256. Display::display_warning_message(get_lang('LockByTeacher'));
  257. $PassEdit=false;
  258. }
  259. }
  260. else
  261. {
  262. $PassEdit=true;
  263. }
  264. }
  265. if($PassEdit) //show editor if edit is allowed
  266. {
  267. if (check_protect_page() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false))
  268. {
  269. Display::display_normal_message(get_lang('PageLockedExtra'));
  270. }
  271. else
  272. {
  273. Display::display_confirmation_message(restore_wikipage($current_row['reflink'], $current_row['title'], $current_row['content'], $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': <a href="index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.$last_row['reflink'].'&group_id='.$last_row['group_id'].'">'.$last_row['title'].'</a>',false);
  274. }
  275. }
  276. }
  277. }
  278. }
  279. if ($_GET['action']=='deletewiki'){
  280. if(api_is_allowed_to_edit() || api_is_platform_admin())
  281. {
  282. if ($_GET['delete'] == 'yes')
  283. {
  284. $return_message=delete_wiki();
  285. Display::display_confirmation_message($return_message);
  286. }
  287. }
  288. }
  289. if ($_GET['action']=='discuss' && $_POST['Submit'])
  290. {
  291. Display::display_confirmation_message(get_lang('CommentAdded'));
  292. }
  293. /*
  294. -----------------------------------------------------------
  295. WIKI WRAPPER
  296. -----------------------------------------------------------
  297. */
  298. echo "<div id='wikiwrapper'>";
  299. /** Actions bar (= action of the wiki tool, not of the page)**/
  300. echo '<div id="menuwiki">';
  301. echo '<table width="210">';
  302. echo '<tr>';
  303. echo '<td>';
  304. echo get_lang('Menu');
  305. echo '</td>';
  306. echo '</tr>';
  307. echo '<tr>';
  308. echo '<td>';
  309. //menu home
  310. echo '<ul><li><a href="index.php?cidReq='.$_course[id].'&action=show&amp;title=index&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('show').'>'.get_lang('HomeWiki').'</a></li>';
  311. //menu add page
  312. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=addnew&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('addnew').'>'.get_lang('AddNew').'</a></li>';
  313. //menu find
  314. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=searchpages&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('searchpages').'>'.get_lang('SearchPages').'</a></li>';
  315. //menu all pages
  316. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=allpages&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('allpages').'>'.get_lang('AllPages').'</a></li>';
  317. //menu recent changes
  318. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=recentchanges&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('recentchanges').'>'.get_lang('RecentChanges').'</a></li>';
  319. //menu delete all wiki
  320. if(api_is_allowed_to_edit() || api_is_platform_admin())
  321. {
  322. echo '<li><a href="index.php?action=deletewiki&amp;title='.$page.'"'.is_active_navigation_tab('deletewiki').'>'.get_lang('DeleteWiki').'</a></li>';
  323. }
  324. //menu more
  325. echo '<li><a href="index.php?action=more&amp;title='.$page.'"'.is_active_navigation_tab('more').'>'.get_lang('More').'</a></li>';
  326. echo '</ul>';
  327. echo '</td>';
  328. echo '</tr>';
  329. echo '</table>';
  330. echo '</div>';
  331. /*
  332. -----------------------------------------------------------
  333. MAIN WIKI AREA
  334. -----------------------------------------------------------
  335. */
  336. echo "<div id='mainwiki'>";
  337. /** menuwiki (= actions of the page, not of the wiki tool) **/
  338. if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted')))
  339. {
  340. echo "<div class='actions'>";
  341. //menu show page
  342. echo '<a href="index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.$page.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('showpage').'>'.Display::display_icon('lp_document.png',get_lang('ShowThisPage')).' '.get_lang('Page').'</a>';
  343. //menu edit page
  344. if ($_clean['group_id'])
  345. {
  346. echo '<a href="index.php?cidReq='.$_course[id].'&action=edit&amp;title='.$page.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('edit').'>'.Display::display_icon('lp_quiz.png',get_lang('EditThisPage')).' '.get_lang('EditPage').'</a>';
  347. }
  348. else
  349. {
  350. echo '<a href="index.php?cidReq='.$_course[id].'&action=edit&amp;title='.$page.'"'.is_active_navigation_tab('edit').'>'.Display::display_icon('lp_quiz.png',get_lang('EditThisPage')).' '.get_lang('EditPage').'</a>';
  351. }
  352. //menu discuss page
  353. echo '<a href="index.php?action=discuss&amp;title='.$page.'"'.is_active_navigation_tab('discuss').'>'.Display::display_icon('comment_bubble.gif',get_lang('DiscussThisPage')).' '.get_lang('Discuss').'</a>';
  354. //menu history
  355. if ($_clean['group_id']!=0)
  356. {
  357. echo '<a href="index.php?cidReq='.$_course[id].'&action=history&amp;title='.$page.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('history').'>'.Display::display_icon('history.gif',get_lang('ShowPageHistory')).' '.get_lang('History').'</a>';
  358. }
  359. else
  360. {
  361. echo '<a href="index.php?cidReq='.$_course[id].'&action=history&amp;title='.$page.'"'.is_active_navigation_tab('history').'>'.Display::display_icon('history.gif',get_lang('ShowPageHistory')).' '.get_lang('History').'</a>';
  362. }
  363. //menu linkspages
  364. echo '<a href="index.php?action=links&amp;title='.$page.'"'.is_active_navigation_tab('links').'>'.Display::display_icon('lp_link.png',get_lang('ShowLinksPages')).' '.get_lang('LinksPages').'</a>';
  365. //menu delete wikipage
  366. if(api_is_allowed_to_edit() || api_is_platform_admin())
  367. {
  368. echo '<a href="index.php?action=delete&amp;title='.$page.'"'.is_active_navigation_tab('delete').'>'.Display::display_icon('delete.gif',get_lang('DeleteThisPage')).' '.get_lang('Delete').'</a>';
  369. }
  370. echo '</div>';
  371. }
  372. /////////////////////// more options /////////////////////// Juan Carlos Raña Trabado
  373. if ($_GET['action']=='more')
  374. {
  375. echo '<div class="actions">'.get_lang('More').'</div>';
  376. if(api_is_allowed_to_edit() || api_is_platform_admin())
  377. {
  378. //TODO: config area and private stats
  379. }
  380. echo '<table border="0">';
  381. echo '<tr>';
  382. echo '<td>';
  383. echo '<ul>';
  384. //Submenu Most active users
  385. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mactiveusers&group_id='.$_clean['group_id'].'">'.get_lang('MostActiveUsers').'</a></li>';
  386. //Submenu Most visited pages
  387. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mvisited&group_id='.$_clean['group_id'].'">'.get_lang('MostVisitedPages').'</a></li>';
  388. //Submenu Most changed pages
  389. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mostchanged&group_id='.$_clean['group_id'].'">'.get_lang('MostChangedPages').'</a></li>';
  390. echo '</ul>';
  391. echo '</td>';
  392. echo '<td>';
  393. echo '<ul>';
  394. //Submenu Orphaned pages
  395. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=orphaned&group_id='.$_clean['group_id'].'">'.get_lang('OrphanedPages').'</a></li>';
  396. //Submenu Wanted pages
  397. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=wanted&group_id='.$_clean['group_id'].'">'.get_lang('WantedPages').'</a></li>';
  398. echo '</ul>';
  399. echo'</td>';
  400. echo '</tr>';
  401. echo '</table>';
  402. //Submenu Most linked pages
  403. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mostlinked&group_id='.$_clean['group_id'].'">'.get_lang('MostLinkedPages').'</a></li>';//TODO
  404. //Submenu Dead end pages
  405. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=deadend&group_id='.$_clean['group_id'].'">'.get_lang('DeadEndPages').'</a></li>';//TODO
  406. //Submenu Most new pages (not versions)
  407. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mnew&group_id='.$_clean['group_id'].'">'.get_lang('MostNewPages').'</a></li>';//TODO
  408. //Submenu Most long pages
  409. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mnew&group_id='.$_clean['group_id'].'">'.get_lang('MostLongPages').'</a></li>';//TODO
  410. //Submenu Protected pages
  411. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=protected&group_id='.$_clean['group_id'].'">'.get_lang('ProtectedPages').'</a></li>';//TODO
  412. //Submenu Hidden pages
  413. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=hidden&group_id='.$_clean['group_id'].'">'.get_lang('HiddenPages').'</a></li>';//TODO
  414. //Submenu Most discuss pages
  415. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mdiscuss&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussPages').'</a></li>';//TODO
  416. //Submenu Best scored pages
  417. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mscored&group_id='.$_clean['group_id'].'">'.get_lang('BestScoredPages').'</a></li>';//TODO
  418. //Submenu Pages with more progress
  419. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mprogress&group_id='.$_clean['group_id'].'">'.get_lang('MProgressPages').'</a></li>';//TODO
  420. //Submenu Most active users in discuss
  421. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mactiveusers&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussUsers').'</a></li>';//TODO
  422. //Submenu Individual assignments
  423. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=assignments&group_id='.$_clean['group_id'].'">'.get_lang('Assignments').'</a></li>';//TODO
  424. //Submenu Delayed assignments
  425. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=delayed&group_id='.$_clean['group_id'].'">'.get_lang('DelayedAssignments').'</a></li>';//TODO
  426. //Submenu Random page
  427. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mrandom&group_id='.$_clean['group_id'].'">'.get_lang('RandomPage').'</a></li>';//TODO
  428. }
  429. /////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado
  430. if ($_GET['action']=='mactiveusers')
  431. {
  432. echo '<div class="actions">'.get_lang('MostActiveUsers').'</div>';
  433. $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY user_id';
  434. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  435. //show table
  436. if (mysql_num_rows($allpages) > 0)
  437. {
  438. $row = array ();
  439. while ($obj = mysql_fetch_object($allpages))
  440. {
  441. $userinfo=Database::get_user_info_from_id($obj->user_id);
  442. $row = array ();
  443. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a><a href="'.api_get_self().'?cidReq='.$_course[id].'&action=usercontrib&user_id='.urlencode($row['user_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'"></a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  444. $row[] ='<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=usercontrib&user_id='.urlencode($obj->user_id).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->NUM_EDIT.'</a>';
  445. $rows[] = $row;
  446. }
  447. $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC');
  448. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  449. $table->set_header(0,get_lang('Author'), true, array ('style' => 'width:30px;'));
  450. $table->set_header(1,get_lang('Contributions'), true);
  451. $table->display();
  452. }
  453. }
  454. /////////////////////// User contributions /////////////////////// Juan Carlos Raña Trabado
  455. if ($_GET['action']=='usercontrib')
  456. {
  457. $userinfo=Database::get_user_info_from_id(Security::remove_XSS($_GET['user_id']));
  458. echo '<div class="actions">'.get_lang('UserContributions').': <a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a><a href="'.api_get_self().'?cidReq='.$_course[id].'&action=usercontrib&user_id='.urlencode($row['user_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'"></a></div>';
  459. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  460. {
  461. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'"';
  462. }
  463. else
  464. {
  465. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'" AND visibility=1';
  466. }
  467. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  468. //show table
  469. if (mysql_num_rows($allpages) > 0)
  470. {
  471. $row = array ();
  472. while ($obj = mysql_fetch_object($allpages))
  473. {
  474. //get author
  475. $userinfo=Database::get_user_info_from_id($obj->user_id);
  476. //get time
  477. $year = substr($obj->dtime, 0, 4);
  478. $month = substr($obj->dtime, 5, 2);
  479. $day = substr($obj->dtime, 8, 2);
  480. $hours = substr($obj->dtime, 11,2);
  481. $minutes = substr($obj->dtime, 14,2);
  482. $seconds = substr($obj->dtime, 17,2);
  483. //get type assignment icon
  484. if($obj->assignment==1)
  485. {
  486. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  487. }
  488. elseif ($obj->assignment==2)
  489. {
  490. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  491. }
  492. elseif ($obj->assignment==0)
  493. {
  494. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  495. }
  496. $row = array ();
  497. $row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
  498. $row[] =$ShowAssignment;
  499. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&view='.$obj->id.'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
  500. $row[] =$obj->version;
  501. $row[] =$obj->comment;
  502. //$row[] =strlen($obj->comment)>30 ? substr($obj->comment,0,30).'...' : $obj->comment;
  503. $row[] =$obj->progress.' %';
  504. $row[] =$obj->score;
  505. //if(api_is_allowed_to_edit() || api_is_platform_admin())
  506. //{
  507. //$row[] =$obj->user_ip;
  508. //}
  509. $rows[] = $row;
  510. }
  511. $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC');
  512. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'user_id'=>Security::remove_XSS($_GET['user_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  513. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  514. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  515. $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;'));
  516. $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;'));
  517. $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;'));
  518. $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;'));
  519. $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;'));
  520. //if(api_is_allowed_to_edit() || api_is_platform_admin())
  521. //{
  522. //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;'));
  523. //}
  524. $table->display();
  525. }
  526. }
  527. /////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado
  528. if ($_GET['action']=='mostchanged')
  529. {
  530. echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
  531. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  532. {
  533. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink';
  534. }
  535. else
  536. {
  537. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink';
  538. }
  539. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  540. //show table
  541. if (mysql_num_rows($allpages) > 0)
  542. {
  543. $row = array ();
  544. while ($obj = mysql_fetch_object($allpages))
  545. {
  546. //get type assignment icon
  547. if($obj->assignment==1)
  548. {
  549. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  550. }
  551. elseif ($obj->assignment==2)
  552. {
  553. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentWork').'" />';
  554. }
  555. elseif ($obj->assignment==0)
  556. {
  557. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  558. }
  559. $row = array ();
  560. $row[] =$ShowAssignment;
  561. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
  562. $row[] = $obj->MAX;
  563. $rows[] = $row;
  564. }
  565. $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC');
  566. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  567. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  568. $table->set_header(1,get_lang('Title'), true);
  569. $table->set_header(2,get_lang('Changes'), true);
  570. $table->display();
  571. }
  572. }
  573. /////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado
  574. if ($_GET['action']=='mvisited')
  575. {
  576. echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
  577. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  578. {
  579. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink';
  580. }
  581. else
  582. {
  583. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink';
  584. }
  585. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  586. //show table
  587. if (mysql_num_rows($allpages) > 0)
  588. {
  589. $row = array ();
  590. while ($obj = mysql_fetch_object($allpages))
  591. {
  592. //get type assignment icon
  593. if($obj->assignment==1)
  594. {
  595. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  596. }
  597. elseif ($obj->assignment==2)
  598. {
  599. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  600. }
  601. elseif ($obj->assignment==0)
  602. {
  603. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  604. }
  605. $row = array ();
  606. $row[] =$ShowAssignment;
  607. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
  608. $row[] = $obj->tsum;
  609. $rows[] = $row;
  610. }
  611. $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC');
  612. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  613. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  614. $table->set_header(1,get_lang('Title'), true);
  615. $table->set_header(2,get_lang('Visits'), true);
  616. $table->display();
  617. }
  618. }
  619. /////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado
  620. if ($_GET['action']=='wanted')
  621. {
  622. echo '<div class="actions">'.get_lang('WantedPages').'</div>';
  623. $pages = array();
  624. $refs = array();
  625. $sort_wanted=array();
  626. //get name pages
  627. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC';
  628. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  629. while ($row=Database::fetch_array($allpages))
  630. {
  631. $pages[] = $row['reflink'];
  632. }
  633. //get name refs in last pages and make a unique list
  634. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)';
  635. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  636. while ($row=Database::fetch_array($allpages))
  637. {
  638. //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check
  639. $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " "
  640. $refs = array_merge($refs, $rf);
  641. if ($n++ > 299)
  642. {
  643. $refs = array_unique($refs);
  644. $n=0;
  645. } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
  646. }
  647. //sort linksto. Find linksto into reflink. If not found ->page is wanted
  648. natcasesort($refs);
  649. echo '<ul>';
  650. foreach($refs as $v)
  651. {
  652. if(!in_array($v, $pages))
  653. {
  654. if (trim($v)!="")
  655. {
  656. echo '<li><a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq=&action=addnew&title='.urlencode(str_replace('_',' ',$v)).'&group_id='.Security::remove_XSS($_GET['group_id']).'" class="new_wiki_link">'.str_replace('_',' ',$v).'</a></li>';
  657. }
  658. }
  659. }
  660. echo '</ul>';
  661. }
  662. /////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado
  663. if ($_GET['action']=='orphaned')
  664. {
  665. echo '<div class="actions">'.get_lang('OrphanedPages').'</div>';
  666. $pages = array();
  667. $refs = array();
  668. $orphaned = array();
  669. //get name pages
  670. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC';
  671. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  672. while ($row=Database::fetch_array($allpages))
  673. {
  674. $pages[] = $row['reflink'];
  675. }
  676. //get name refs in last pages and make a unique list
  677. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)';
  678. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  679. while ($row=Database::fetch_array($allpages))
  680. {
  681. //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check
  682. $rf = explode(" ", trim($row["linksto"])); //fix replace explode("\n", trim($row["linksto"])) with explode(" ", trim($row["linksto"]))
  683. $refs = array_merge($refs, $rf);
  684. if ($n++ > 299)
  685. {
  686. $refs = array_unique($refs);
  687. $n=0;
  688. } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
  689. }
  690. //search each name of list linksto into list reflink
  691. foreach($pages as $v)
  692. {
  693. if(!in_array($v, $refs))
  694. {
  695. $orphaned[] = $v;
  696. }
  697. }
  698. //change reflink by title
  699. foreach($orphaned as $vshow)
  700. {
  701. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  702. {
  703. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" GROUP BY reflink';
  704. }
  705. else
  706. {
  707. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" AND visibility=1 GROUP BY reflink';
  708. }
  709. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  710. echo '<ul>';
  711. while ($row=Database::fetch_array($allpages))
  712. {
  713. //fix assignment icon
  714. if($row['assignment']==1)
  715. {
  716. $ShowAssignment='<img src="../img/wiki/assignment.gif" />';
  717. }
  718. elseif ($row['assignment']==2)
  719. {
  720. $ShowAssignment='<img src="../img/wiki/works.gif" />';
  721. }
  722. elseif ($row['assignment']==0)
  723. {
  724. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  725. }
  726. echo '<li>'.$ShowAssignment.'<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($row['reflink']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$row['title'].'</a></li>';
  727. }
  728. echo '</ul>';
  729. }
  730. }
  731. /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado
  732. if ($_GET['action']=='delete')
  733. {
  734. echo '<div style="overflow:hidden">';
  735. if(api_is_allowed_to_edit() || api_is_platform_admin())
  736. {
  737. echo '<div id="wikititle">'.get_lang('DeletePageHistory').'</div>';
  738. if($page=="index")
  739. {
  740. Display::display_warning_message(get_lang('WarningDeleteMainPage'),false);
  741. }
  742. $message = get_lang('ConfirmDeletePage')."</p>"."<p>"."<a href=\"index.php\">".get_lang("No")."</a>"."&nbsp;&nbsp;|&nbsp;&nbsp;"."<a href=\"".api_get_self()."?action=delete&amp;title=".$page."&amp;delete=yes\">".get_lang("Yes")."</a>"."</p>";
  743. if (!isset ($_GET['delete']))
  744. {
  745. Display::display_warning_message($message,false);
  746. }
  747. if ($_GET['delete'] == 'yes')
  748. {
  749. $sql='DELETE '.$tbl_wiki_discuss.' FROM '.$tbl_wiki.', '.$tbl_wiki_discuss.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_discuss.'.publication_id='.$tbl_wiki.'.id';
  750. api_sql_query($sql,__FILE__,__LINE__);
  751. $sql='DELETE '.$tbl_wiki_mailcue.' FROM '.$tbl_wiki.', '.$tbl_wiki_mailcue.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_mailcue.'.id='.$tbl_wiki.'.id';
  752. api_sql_query($sql,__FILE__,__LINE__);
  753. $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.'';
  754. api_sql_query($sql,__FILE__,__LINE__);
  755. check_emailcue(0, 'E');
  756. Display::display_confirmation_message(get_lang('WikiPageDeleted'));
  757. }
  758. }
  759. else
  760. {
  761. Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki"));
  762. }
  763. echo '</div>';
  764. }
  765. /////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado
  766. if ($_GET['action']=='deletewiki')
  767. {
  768. echo '<div class="actions">'.get_lang('DeleteWiki').'</div>';
  769. echo '<div style="overflow:hidden">';
  770. if(api_is_allowed_to_edit() || api_is_platform_admin())
  771. {
  772. $message = get_lang('ConfirmDeleteWiki');
  773. $message .= '<p>
  774. <a href="index.php">'.get_lang('No').'</a>
  775. &nbsp;&nbsp;|&nbsp;&nbsp;
  776. <a href="'.api_get_self().'?action=deletewiki&amp;delete=yes">'.get_lang('Yes').'</a>
  777. </p>';
  778. if (!isset($_GET['delete']))
  779. {
  780. Display::display_warning_message($message,false);
  781. }
  782. }
  783. else
  784. {
  785. Display::display_normal_message(get_lang("OnlyAdminDeleteWiki"));
  786. }
  787. echo '</div>';
  788. }
  789. /////////////////////// search wiki pages ///////////////////////
  790. if ($_GET['action']=='searchpages')
  791. {
  792. echo '<div class="actions">'.get_lang('SearchPages').'</div>';
  793. echo '<div style="overflow:hidden">';
  794. // initiate the object
  795. $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action='.Security::remove_XSS($_GET['action']).'&group_id='.Security::remove_XSS($_GET['group_id']));
  796. // settting the form elements
  797. $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles"');
  798. $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent'));
  799. $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"');
  800. // setting the rules
  801. $form->addRule('search_term', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  802. $form->addRule('search_term', get_lang('TooShort'),'minlength',3);
  803. if ($form->validate())
  804. {
  805. $form->display();
  806. $values = $form->exportValues();
  807. display_wiki_search_results($values['search_term'], $values['search_content']);
  808. }
  809. else
  810. {
  811. $form->display();
  812. }
  813. echo '</div>';
  814. }
  815. /////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado
  816. if ($_GET['action']=='links')
  817. {
  818. if (!$_GET['title'])
  819. {
  820. echo '<div id="wikititle"> </div>';
  821. Display::display_error_message(get_lang("MustSelectPage"));
  822. }
  823. else
  824. {
  825. $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.'';
  826. $result=api_sql_query($sql,__FILE__,__LINE__);
  827. $row=Database::fetch_array($result);
  828. //get type assignment icon
  829. if($row['assignment']==1)
  830. {
  831. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  832. }
  833. elseif ($row['assignment']==2)
  834. {
  835. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  836. }
  837. elseif ($row['assignment']==0)
  838. {
  839. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  840. }
  841. //fix Title to reflink (link Main Page)
  842. if ($page==get_lang('DefaultTitle'))
  843. {
  844. $page='index';
  845. }
  846. echo '<div id="wikititle">';
  847. echo $LinksPagesFrom.': '.$ShowAssignment.' <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.Security::remove_XSS($page).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($row['title']).'</a>';
  848. echo '</div>';
  849. //fix index to title Main page into linksto
  850. if ($page=='index')
  851. {
  852. $page=str_replace(' ','_',get_lang('DefaultTitle'));
  853. }
  854. //table
  855. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  856. {
  857. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)"; //add blank space after like '%" " %' to identify each word.
  858. }
  859. else
  860. {
  861. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND visibility=1 AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)"; //add blank space after like '%" " %' to identify each word
  862. }
  863. $allpages=api_sql_query($sql,__LINE__,__FILE__);
  864. //show table
  865. if (mysql_num_rows($allpages) > 0)
  866. {
  867. $row = array ();
  868. while ($obj = mysql_fetch_object($allpages))
  869. {
  870. //get author
  871. $userinfo=Database::get_user_info_from_id($obj->user_id);
  872. //get time
  873. $year = substr($obj->dtime, 0, 4);
  874. $month = substr($obj->dtime, 5, 2);
  875. $day = substr($obj->dtime, 8, 2);
  876. $hours = substr($obj->dtime, 11,2);
  877. $minutes = substr($obj->dtime, 14,2);
  878. $seconds = substr($obj->dtime, 17,2);
  879. //get type assignment icon
  880. if($obj->assignment==1)
  881. {
  882. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  883. }
  884. elseif ($obj->assignment==2)
  885. {
  886. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  887. }
  888. elseif ($obj->assignment==0)
  889. {
  890. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  891. }
  892. $row = array ();
  893. $row[] =$ShowAssignment;
  894. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($obj->title).'</a>';
  895. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  896. $row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
  897. $rows[] = $row;
  898. }
  899. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  900. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  901. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  902. $table->set_header(1,get_lang('Title'), true);
  903. $table->set_header(2,get_lang('Author'), true);
  904. $table->set_header(3,get_lang('Date'), true);
  905. $table->display();
  906. }
  907. }
  908. }
  909. /////////////////////// adding a new page ///////////////////////
  910. // Display the form for adding a new wiki page
  911. if ($_GET['action']=='addnew')
  912. {
  913. echo '<div class="actions">'.get_lang('AddNew').'</div>';
  914. //first, check if page index was created. chektitle=false
  915. if (checktitle('index'))
  916. {
  917. if(api_is_allowed_to_edit() || api_is_platform_admin())
  918. {
  919. Display::display_normal_message(get_lang('GoAndEditMainPage'));
  920. }
  921. else
  922. {
  923. return Display::display_normal_message(get_lang('WikiStandBy'));
  924. }
  925. }
  926. elseif (check_addnewpagelock() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false))
  927. {
  928. Display::display_error_message(get_lang('AddPagesLocked'));
  929. }
  930. else
  931. {
  932. if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0)
  933. {
  934. display_new_wiki_form();
  935. }
  936. else
  937. {
  938. Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers'));
  939. }
  940. }
  941. }
  942. /////////////////////// show home page ///////////////////////
  943. if (!$_GET['action'] OR $_GET['action']=='show' AND !$_POST['SaveWikiNew'])
  944. {
  945. display_wiki_entry();
  946. }
  947. /////////////////////// show current page ///////////////////////
  948. if ($_GET['action']=='showpage' AND !$_POST['SaveWikiNew'])
  949. {
  950. display_wiki_entry();
  951. }
  952. /////////////////////// edit current page ///////////////////////
  953. if ($_GET['action']=='edit')
  954. {
  955. $_clean['group_id']=(int)$_SESSION['_gid'];
  956. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
  957. $result=api_sql_query($sql,__LINE__,__FILE__);
  958. $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
  959. if ($row['content']=='' AND $row['title']=='' AND $page='index')
  960. {
  961. $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH));
  962. $title=get_lang('DefaultTitle');
  963. }
  964. else
  965. {
  966. $content=$row['content'];
  967. $title=$row['title'];
  968. }
  969. echo '<div id="wikititle">';
  970. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.$title.'</div>';
  971. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher
  972. if(($row['reflink']=='index' || $row['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit()))
  973. {
  974. Display::display_error_message(get_lang('OnlyEditPagesCourseManager'));
  975. }
  976. else
  977. {
  978. $PassEdit=false;
  979. //check if is a wiki group
  980. if($_clean['group_id']!=0)
  981. {
  982. //Only teacher, platform admin and group members can edit a wiki group
  983. if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
  984. {
  985. $PassEdit=true;
  986. }
  987. else
  988. {
  989. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  990. }
  991. }
  992. else
  993. {
  994. $PassEdit=true;
  995. }
  996. // check if is a assignment
  997. if(stripslashes($row['assignment'])==1)
  998. {
  999. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  1000. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1001. }
  1002. elseif(stripslashes($row['assignment'])==2)
  1003. {
  1004. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1005. if((api_get_user_id()==$row['user_id'])==false)
  1006. {
  1007. if(api_is_allowed_to_edit() || api_is_platform_admin())
  1008. {
  1009. $PassEdit=true;
  1010. }
  1011. else
  1012. {
  1013. Display::display_warning_message(get_lang('LockByTeacher'));
  1014. $PassEdit=false;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. $PassEdit=true;
  1020. }
  1021. }
  1022. if($PassEdit) //show editor if edit is allowed
  1023. {
  1024. if (check_protect_page() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false))
  1025. {
  1026. Display::display_normal_message(get_lang('PageLockedExtra'));
  1027. }
  1028. else
  1029. {
  1030. echo '<div id="wikicontent">';
  1031. echo '<form name="form1" method="post" action="'.api_get_self().'?action=showpage&amp;title='.$page.'&group_id='.Security::remove_XSS($_GET['group_id']).'">';
  1032. echo '<input type="hidden" name="reflink" value="'.$page.'">';
  1033. echo '<input type="hidden" name="title" value="'.stripslashes($title).'">';
  1034. api_disp_html_area('content',stripslashes($content),'300px');
  1035. echo '<br/>';
  1036. echo '<br/>';
  1037. //if(api_is_allowed_to_edit() || api_is_platform_admin()) //off for now
  1038. //{
  1039. echo get_lang('Comments').':&nbsp;&nbsp;<input type="text" name="comment">&nbsp;&nbsp;&nbsp;';
  1040. //}
  1041. echo '<INPUT TYPE="hidden" NAME="assignment" VALUE="'.stripslashes($row['assignment']).'"/>';
  1042. //echo '<INPUT TYPE="hidden" NAME="startdate_assig" VALUE="'.stripslashes($row['startdate_assig']).'"/>'; //off for now
  1043. //echo '<INPUT TYPE="hidden" NAME="enddate_assig" VALUE="'.stripslashes($row['enddate_assig']).'"/>'; //off for now
  1044. //echo '<INPUT TYPE="hidden" NAME="delayedsubmit" VALUE="'.stripslashes($row['delayedsubmit']).'"/>'; //off for now
  1045. echo '<INPUT TYPE="hidden" NAME="version" VALUE="'.stripslashes($row['version']).'"/>'; //get current version
  1046. echo get_lang('Progress').':&nbsp;&nbsp;<select name="progress" id="progress">';
  1047. echo '<option value="'.stripslashes($row['progress']).'" selected>'.stripslashes($row['progress']).'</option>';
  1048. echo '<option value="10">10</option>
  1049. <option value="20">20</option>
  1050. <option value="30">30</option>
  1051. <option value="40">40</option>
  1052. <option value="50">50</option>
  1053. <option value="60">60</option>
  1054. <option value="70">70</option>
  1055. <option value="80">80</option>
  1056. <option value="90">90</option>
  1057. <option value="100">100</option>
  1058. </select> %';
  1059. echo '<br/><br/>';
  1060. echo '<input type="hidden" NAME="SaveWikiChange" value="'.get_lang('langSave').'">'; //for save icon
  1061. echo '<button class="save" type="submit" name="SaveWikiChange">'.get_lang('langSave').'</button>';//for save button
  1062. echo '</form>';
  1063. echo '</div>';
  1064. }
  1065. }
  1066. }
  1067. }
  1068. /////////////////////// page history ///////////////////////
  1069. if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences']))
  1070. {
  1071. echo '<div style="overflow:hidden">';
  1072. $_clean['group_id']=(int)$_SESSION['_gid'];
  1073. //First, see the property visibility that is at the last register and therefore we should select descending order. But to give ownership to each record, this is no longer necessary except for the title. TODO: check this
  1074. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
  1075. $result=api_sql_query($sql,__LINE__,__FILE__);
  1076. while ($row=Database::fetch_array($result))
  1077. {
  1078. $KeyVisibility=$row['visibility'];
  1079. $KeyAssignment=$row['assignment'];
  1080. $KeyTitle=$row['title'];
  1081. $KeyUserId=$row['user_id'];
  1082. }
  1083. if($KeyAssignment==1)
  1084. {
  1085. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1086. }
  1087. elseif($KeyAssignment==2)
  1088. {
  1089. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1090. }
  1091. //Second, show
  1092. //if the page is hidden and is a job only sees its author and professor
  1093. if($KeyVisibility==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($KeyAssignment==2 && $KeyVisibility==0 && (api_get_user_id()==$KeyUserId)))
  1094. {
  1095. // We show the complete history
  1096. if (!$_POST['HistoryDifferences'] && !$_POST['HistoryDifferences2'] )
  1097. {
  1098. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
  1099. $result=api_sql_query($sql,__LINE__,__FILE__);
  1100. $title = Security::remove_XSS($_GET['title']);
  1101. $group_id = Security::remove_XSS($_GET['group_id']);
  1102. echo '<div id="wikititle">';
  1103. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.$KeyTitle;
  1104. echo '</div>';
  1105. echo '<div id="wikicontent">';
  1106. echo '<form id="differences" method="POST" action="index.php?cidReq='.$_course[id].'&action=history&title='.$title.'&group_id='.$group_id.'">';
  1107. echo '<ul style="list-style-type: none;">';
  1108. echo '<br/>';
  1109. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1110. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1111. echo '<br/><br/>';
  1112. $counter=0;
  1113. $total_versions=Database::num_rows($result);
  1114. while ($row=Database::fetch_array($result))
  1115. {
  1116. $userinfo=Database::get_user_info_from_id($row['user_id']);
  1117. $year = substr($row['dtime'], 0, 4);
  1118. $month = substr($row['dtime'], 5, 2);
  1119. $day = substr($row['dtime'], 8, 2);
  1120. $hours=substr($row['dtime'], 11,2);
  1121. $minutes=substr($row['dtime'], 14,2);
  1122. $seconds=substr($row['dtime'], 17,2);
  1123. echo '<li style="margin-bottom: 5px;">';
  1124. ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle='';
  1125. ($counter==0) ? $newchecked=' checked':$newchecked='';
  1126. ($counter==$total_versions-1) ? $newstyle='style="visibility: hidden;"':$newstyle='';
  1127. ($counter==1) ? $oldchecked=' checked':$oldchecked='';
  1128. echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
  1129. echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
  1130. echo '<a href="'.api_get_self().'?action=showpage&amp;title='.$page.'&amp;view='.$row['id'].'">';
  1131. echo '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&amp;title='.$page.'&amp;view='.$row['id'].'&group_id='.$group_id.'">';
  1132. echo $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1133. echo '</a>';
  1134. echo ' ('.get_lang('Version').' '.$row['version'].')';
  1135. echo ' '.get_lang('By').' ';
  1136. if ($row['user_id']<>0)
  1137. {
  1138. echo '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>';
  1139. }
  1140. else
  1141. {
  1142. echo get_lang('Anonymous').' ('.$row[user_ip].')';
  1143. }
  1144. echo ' ( '.get_lang('Progress').': '.$row['progress'].'%, ';
  1145. $comment=$row['comment'];
  1146. if (!empty($comment))
  1147. {
  1148. echo get_lang('Comments').': '.substr(htmlentities($row['comment']),0,100);
  1149. if (strlen($row['comment'])>100)
  1150. {
  1151. echo '... ';
  1152. }
  1153. }
  1154. else
  1155. {
  1156. echo get_lang('Comments').': ---';
  1157. }
  1158. echo ' ) </li>';
  1159. $counter++;
  1160. } //end while
  1161. echo '<br/>';
  1162. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1163. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1164. echo '</ul></form></div>';
  1165. }
  1166. // We show the differences between two versions
  1167. else
  1168. {
  1169. $sql_old="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['old'])."'";
  1170. $result_old=api_sql_query($sql_old,__LINE__,__FILE__);
  1171. $version_old=Database::fetch_array($result_old);
  1172. $sql_new="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['new'])."'";
  1173. $result_new=api_sql_query($sql_new,__LINE__,__FILE__);
  1174. $version_new=Database::fetch_array($result_new);
  1175. if(isset($_POST['HistoryDifferences']))
  1176. {
  1177. include('diff.inc.php');
  1178. //title
  1179. echo '<div id="wikititle">'.stripslashes($version_new['title']).' <font size="-2"><i>('.get_lang('DifferencesNew').'</i> <font style="background-color:#aaaaaa">'.stripslashes($version_new['dtime']).'</font> <i>'.get_lang('DifferencesOld').'</i> <font style="background-color:#aaaaaa">'.stripslashes($version_old['dtime']).'</font>) '.get_lang('Legend').': <span class="diffAdded" >'.get_lang(WikiDiffAddedLine).'</span> <span class="diffDeleted" >'.get_lang(WikiDiffDeletedLine).'</span> <span class="diffMoved" >'.get_lang(WikiDiffMovedLine).'</span></font></div>';
  1180. }
  1181. if(isset($_POST['HistoryDifferences2']))
  1182. {
  1183. require_once 'Text/Diff.php';
  1184. require_once 'Text/Diff/Renderer/inline.php';
  1185. //title
  1186. echo '<div id="wikititle">'.stripslashes($version_new['title']).' <font size="-2"><i>('.get_lang('DifferencesNew').'</i> <font style="background-color:#aaaaaa">'.stripslashes($version_new['dtime']).'</font> <i>'.get_lang('DifferencesOld').'</i> <font style="background-color:#aaaaaa">'.stripslashes($version_old['dtime']).'</font>) '.get_lang('Legend').': <span class="diffAddedTex" >'.get_lang(WikiDiffAddedTex).'</span> <span class="diffDeletedTex" >'.get_lang(WikiDiffDeletedTex).'</span></font></div>';
  1187. }
  1188. echo '<div class="diff"><br /><br />';
  1189. if(isset($_POST['HistoryDifferences']))
  1190. {
  1191. echo '<table>'.diff( stripslashes($version_old['content']), stripslashes($version_new['content']), true, 'format_table_line' ).'</table>'; // format_line mode is better for words
  1192. echo '</div>';
  1193. echo '<br />';
  1194. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1195. echo '<table><tr>';
  1196. echo '<td>';
  1197. echo '</td><td>';
  1198. echo '<span class="diffEqual" >'.get_lang('WikiDiffUnchangedLine').'</span><br />';
  1199. echo '<span class="diffAdded" >'.get_lang('WikiDiffAddedLine').'</span><br />';
  1200. echo '<span class="diffDeleted" >'.get_lang('WikiDiffDeletedLine').'</span><br />';
  1201. echo '<span class="diffMoved" >'.get_lang('WikiDiffMovedLine').'</span><br />';
  1202. echo '</td>';
  1203. echo '</tr></table>';
  1204. echo '</div>';
  1205. }
  1206. if(isset($_POST['HistoryDifferences2']))
  1207. {
  1208. $lines1 = array(strip_tags($version_old['content'])); //without <> tags
  1209. $lines2 = array(strip_tags($version_new['content'])); //without <> tags
  1210. $diff = &new Text_Diff($lines1, $lines2);
  1211. $renderer = &new Text_Diff_Renderer_inline();
  1212. echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render($diff); // Code inline
  1213. //echo '<div class="diffEqual">'.html_entity_decode($renderer->render($diff)).'</div>'; // Html inline. By now, turned off by problems in comparing pages separated by more than one version
  1214. echo '</div>';
  1215. echo '<br />';
  1216. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1217. echo '<table><tr>';
  1218. echo '<td>';
  1219. echo '</td><td>';
  1220. echo '<span class="diffAddedTex" >'.get_lang('WikiDiffAddedTex').'</span><br />';
  1221. echo '<span class="diffDeletedTex" >'.get_lang('WikiDiffDeletedTex').'</span><br />';
  1222. echo '</td>';
  1223. echo '</tr></table>';
  1224. echo '</div>';
  1225. }
  1226. }
  1227. }
  1228. echo '</div>';
  1229. }
  1230. /////////////////////// recent changes ///////////////////////
  1231. //
  1232. //rss feed. TODO
  1233. //
  1234. if ($_GET['action']=='recentchanges')
  1235. {
  1236. $_clean['group_id']=(int)$_SESSION['_gid'];
  1237. if (check_notify_all())
  1238. {
  1239. $notify_all= '<a href="index.php?action=recentchanges&amp;actionpage=notify_all&amp;title='.$page.'"><img src="../img/wiki/send_mail_checked.gif" title="'.get_lang('FullNotifyByEmail').'" alt="'.get_lang('FullNotifyByEmail').'" style="vertical-align:middle;" />'.get_lang('NotNotifyChanges').'</a>';
  1240. }
  1241. else
  1242. {
  1243. $notify_all= '<a href="index.php?action=recentchanges&amp;actionpage=notify_all&amp;title='.$page.'"><img src="../img/wiki/send_mail.gif" title="'.get_lang('FullCancelNotifyByEmail').'" alt="'.get_lang('FullCancelNotifyByEmail').'" style="vertical-align:middle;"/>'.get_lang('NotifyChanges').'</a>';
  1244. }
  1245. echo '<div class="actions"><span style="float: right;">'.$notify_all.'</span>'.get_lang('RecentChanges').'</div>';
  1246. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  1247. {
  1248. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY dtime DESC';
  1249. }
  1250. else
  1251. {
  1252. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 ORDER BY dtime DESC';
  1253. }
  1254. $allpages=api_sql_query($sql,__LINE__,__FILE__);
  1255. //show table
  1256. if (mysql_num_rows($allpages) > 0)
  1257. {
  1258. $row = array ();
  1259. while ($obj = mysql_fetch_object($allpages))
  1260. {
  1261. //get author
  1262. $userinfo=Database::get_user_info_from_id($obj->user_id);
  1263. //get time
  1264. $year = substr($obj->dtime, 0, 4);
  1265. $month = substr($obj->dtime, 5, 2);
  1266. $day = substr($obj->dtime, 8, 2);
  1267. $hours = substr($obj->dtime, 11,2);
  1268. $minutes = substr($obj->dtime, 14,2);
  1269. $seconds = substr($obj->dtime, 17,2);
  1270. //get type assignment icon
  1271. if($obj->assignment==1)
  1272. {
  1273. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  1274. }
  1275. elseif ($obj->assignment==2)
  1276. {
  1277. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  1278. }
  1279. elseif ($obj->assignment==0)
  1280. {
  1281. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  1282. }
  1283. $row = array ();
  1284. $row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.':'.$minutes.":".$seconds;
  1285. $row[] =$ShowAssignment;
  1286. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&amp;view='.$obj->id.'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
  1287. $row[] =$obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
  1288. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  1289. $rows[] = $row;
  1290. }
  1291. $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC');
  1292. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1293. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  1294. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1295. $table->set_header(2,get_lang('Title'), true);
  1296. $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;'));
  1297. $table->set_header(4,get_lang('Author'), true);
  1298. $table->display();
  1299. }
  1300. }
  1301. /////////////////////// all pages ///////////////////////
  1302. if ($_GET['action']=='allpages')
  1303. {
  1304. echo '<div class="actions">'.get_lang('AllPages').'</div>';
  1305. $_clean['group_id']=(int)$_SESSION['_gid'];
  1306. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  1307. {
  1308. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; // warning don't use group by reflink because don't return the last version
  1309. }
  1310. else
  1311. {
  1312. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; // warning don't use group by reflink because don't return the last version
  1313. }
  1314. $allpages=api_sql_query($sql,__LINE__,__FILE__);
  1315. //show table
  1316. if (mysql_num_rows($allpages) > 0)
  1317. {
  1318. $row = array ();
  1319. while ($obj = mysql_fetch_object($allpages))
  1320. {
  1321. //get author
  1322. $userinfo=Database::get_user_info_from_id($obj->user_id);
  1323. //get time
  1324. $year = substr($obj->dtime, 0, 4);
  1325. $month = substr($obj->dtime, 5, 2);
  1326. $day = substr($obj->dtime, 8, 2);
  1327. $hours = substr($obj->dtime, 11,2);
  1328. $minutes = substr($obj->dtime, 14,2);
  1329. $seconds = substr($obj->dtime, 17,2);
  1330. //get type assignment icon
  1331. if($obj->assignment==1)
  1332. {
  1333. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  1334. }
  1335. elseif ($obj->assignment==2)
  1336. {
  1337. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  1338. }
  1339. elseif ($obj->assignment==0)
  1340. {
  1341. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  1342. }
  1343. $row = array ();
  1344. $row[] =$ShowAssignment;
  1345. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($obj->title).'</a>';
  1346. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  1347. $row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1348. $rows[] = $row;
  1349. }
  1350. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  1351. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1352. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1353. $table->set_header(1,get_lang('Title'), true);
  1354. $table->set_header(2,get_lang('Author'), true);
  1355. $table->set_header(3,get_lang('Date'), true);
  1356. $table->display();
  1357. }
  1358. }
  1359. /////////////////////// discuss pages ///////////////////////
  1360. if ($_GET['action']=='discuss')
  1361. {
  1362. //first extract the date of last version
  1363. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
  1364. $result=api_sql_query($sql,__LINE__,__FILE__);
  1365. $row=Database::fetch_array($result);
  1366. $lastversiondate=$row['dtime'];
  1367. $lastuserinfo=Database::get_user_info_from_id($row['user_id']);
  1368. //select page to discuss
  1369. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  1370. $result=api_sql_query($sql,__LINE__,__FILE__);
  1371. $row=Database::fetch_array($result);
  1372. $id=$row['id'];
  1373. $firstuserid=$row['user_id'];
  1374. //mode assignment: previous to show page type
  1375. if(stripslashes($row['assignment'])==1)
  1376. {
  1377. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1378. }
  1379. elseif(stripslashes($row['assignment'])==2)
  1380. {
  1381. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1382. }
  1383. //Show title and form to discuss if page exist
  1384. if ($id!='')
  1385. {
  1386. //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
  1387. if($row['visibility_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id'])))
  1388. {
  1389. echo '<div id="wikititle">';
  1390. // discussion action: protecting (locking) the discussion
  1391. if (check_addlock_discuss())
  1392. {
  1393. if(api_is_allowed_to_edit() || api_is_platform_admin())
  1394. {
  1395. $addlock_disc= '<img src="../img/wiki/lock.gif" title="'.get_lang('LockDiscussExtra').'" alt="'.get_lang('LockDiscussExtra').'" />';
  1396. }
  1397. else
  1398. {
  1399. $addlock_disc= '<img src="../img/wiki/lock.gif" title="'.get_lang('LockDiscussExtra').'" alt="'.get_lang('LockDiscussExtra').'" />';
  1400. }
  1401. }
  1402. else
  1403. {
  1404. if(api_is_allowed_to_edit() || api_is_platform_admin())
  1405. {
  1406. $addlock_disc= '<img src="../img/wiki/unlock.gif" title="'.get_lang('UnlockDiscussExtra').'" alt="'.get_lang('UnlockDiscussExtra').'" />';
  1407. }
  1408. }
  1409. echo '<span style="float:right">';
  1410. echo '<a href="index.php?action=discuss&amp;actionpage=addlock_disc&amp;title='.$page.'">'.$addlock_disc.'</a>';
  1411. echo '</span>';
  1412. // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
  1413. if (check_visibility_discuss())
  1414. {
  1415. //Mode assignments: If is hidden, show pages to student only if student is the author
  1416. if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
  1417. {
  1418. $visibility_disc= '<img src="../img/wiki/invisible.gif" title="'.get_lang('HideDiscussExtra').'" alt="'.get_lang('HideDiscussExtra').'" />';
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if(api_is_allowed_to_edit() || api_is_platform_admin())
  1424. {
  1425. $visibility_disc= '<img src="../img/wiki/visible.gif" title="'.get_lang('ShowDiscussExtra').'" alt="'.get_lang('ShowDiscussExtra').'" />';
  1426. }
  1427. }
  1428. echo '<span style="float:right">';
  1429. echo '<a href="index.php?action=discuss&amp;actionpage=visibility_disc&amp;title='.$page.'">'.$visibility_disc.'</a>';
  1430. echo '</span>';
  1431. //discussion action: check add rating lock. Show/Hide list to rating for all student
  1432. if (check_ratinglock_discuss())
  1433. {
  1434. //Mode assignment: only the teacher can assign scoring
  1435. if(($row['assignment']==2 && $row['ratinglock_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
  1436. {
  1437. $ratinglock_disc= '<img src="../img/wiki/rating_na.gif" title="'.get_lang('LockRatingDiscussExtra').'" alt="'.get_lang('LockRatingDiscussExtra').'" />';
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if(api_is_allowed_to_edit() || api_is_platform_admin())
  1443. {
  1444. $ratinglock_disc= '<img src="../img/wiki/rating.gif" title="'.get_lang('UnlockRatingDiscussExtra').'" alt="'.get_lang('UnlockRatingDiscussExtra').'" />';
  1445. }
  1446. }
  1447. echo '<span style="float:right">';
  1448. echo '<a href="index.php?action=discuss&amp;actionpage=ratinglock_disc&amp;title='.$page.'">'.$ratinglock_disc.'</a>';
  1449. echo '</span>';
  1450. //discussion action: email notification
  1451. if (check_notify_discuss($page))
  1452. {
  1453. $notify_disc= '<img src="../img/wiki/send_mail_checked.gif" title="'.get_lang('NotifyDiscussByEmail').'" alt="'.get_lang('NotifyDiscussByEmail').'" />';
  1454. }
  1455. else
  1456. {
  1457. $notify_disc= '<img src="../img/wiki/send_mail.gif" title="'.get_lang('CancelNotifyDiscussByEmail').'" alt="'.get_lang('CancelNotifyDiscussByEmail').'" />';
  1458. }
  1459. echo '<span style="float:right">';
  1460. echo '<a href="index.php?action=discuss&amp;actionpage=notify_disc&amp;title='.$page.'">'.$notify_disc.'</a>';
  1461. echo '</span>';
  1462. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.$row['title'];
  1463. echo ' ('.get_lang('MostRecentVersionBy').' <a href="../user/userInfo.php?uInfo='.$lastuserinfo['user_id'].'">'.$lastuserinfo['firstname'].' '.$lastuserinfo['lastname'].'</a> '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read avg score
  1464. echo '</div>';
  1465. if($row['addlock_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin()) //show comments but students can't add theirs
  1466. {
  1467. ?>
  1468. <form name="form1" method="post" action="">
  1469. <table>
  1470. <tr>
  1471. <td valign="top" ><?php echo get_lang('Comments');?>:</td>
  1472. <td><textarea name="comment" cols="80" rows="5" id="comment"></textarea></td>
  1473. </tr>
  1474. <tr>
  1475. <?php
  1476. //check if rating is allowed
  1477. if($row['ratinglock_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin())
  1478. {
  1479. ?>
  1480. <td><?php echo get_lang('Rating');?>: </td>
  1481. <td valign="top"><select name="rating" id="rating">
  1482. <option value="-" selected>-</option>
  1483. <option value="0">0</option>
  1484. <option value="1">1</option>
  1485. <option value="2">2</option>
  1486. <option value="3">3</option>
  1487. <option value="4">4</option>
  1488. <option value="5">5</option>
  1489. <option value="6">6</option>
  1490. <option value="7">7</option>
  1491. <option value="8">8</option>
  1492. <option value="9">9</option>
  1493. <option value="10">10</option>
  1494. </select></td>
  1495. <?php
  1496. }
  1497. else
  1498. {
  1499. echo '<input type=hidden name="rating" value="-">';// must pass a default value to avoid rate automatically
  1500. }
  1501. ?>
  1502. </tr>
  1503. <tr>
  1504. <td>&nbsp;</td>
  1505. <td> <?php echo '<button class="save" type="submit" name="Submit"> '.get_lang('Send').'</button>'; ?></td>
  1506. </tr>
  1507. </table>
  1508. </form>
  1509. <?php
  1510. if (isset($_POST['Submit']))
  1511. {
  1512. $dtime = date( "Y-m-d H:i:s" );
  1513. $message_author=api_get_user_id();
  1514. $sql="INSERT INTO $tbl_wiki_discuss (publication_id, userc_id, comment, p_score, dtime) VALUES ('".$id."','".$message_author."','".$_POST['comment']."','".$_POST['rating']."','".$dtime."')";
  1515. $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1516. check_emailcue($id, 'D', $dtime, $message_author);
  1517. }
  1518. }//end discuss lock
  1519. echo '<hr noshade size="1">';
  1520. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  1521. $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' ORDER BY id DESC";
  1522. $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1523. $countWPost = Database::num_rows($result);
  1524. echo get_lang('NumComments').": ".$countWPost; //comment's numbers
  1525. $sql="SELECT SUM(p_score) as sumWPost FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-' ORDER BY id DESC";
  1526. $result2=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1527. $row2=Database::fetch_array($result2);
  1528. $sql="SELECT * FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-'";
  1529. $result3=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1530. $countWPost_score= Database::num_rows($result3);
  1531. echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;//
  1532. if ($countWPost_score!=0)
  1533. {
  1534. $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10';
  1535. }
  1536. else
  1537. {
  1538. $avg_WPost_score = $countWPost_score;
  1539. }
  1540. echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
  1541. $sql='UPDATE '.$tbl_wiki.' SET score="'.Database::escape_string($avg_WPost_score).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; // check if work ok. TODO
  1542. api_sql_query($sql,__FILE__,__LINE__);
  1543. echo '<hr noshade size="1">';
  1544. //echo '<div style="overflow:auto; height:170px;">';
  1545. while ($row=Database::fetch_array($result))
  1546. {
  1547. $userinfo=Database::get_user_info_from_id($row['userc_id']);
  1548. if (($userinfo['status'])=="5")
  1549. {
  1550. $author_status=get_lang('Student');
  1551. }
  1552. else
  1553. {
  1554. $author_status=get_lang('Teacher');
  1555. }
  1556. require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php');
  1557. $user_id=$row['userc_id'];
  1558. $name=$userinfo['lastname']." ".$userinfo['firstname'];
  1559. $attrb=array();
  1560. if ($user_id<>0)
  1561. {
  1562. $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
  1563. $image_repository = $image_path['dir'];
  1564. $existing_image = $image_path['file'];
  1565. $author_photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1566. }
  1567. else
  1568. {
  1569. $author_photo= '<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1570. }
  1571. //stars
  1572. $p_score=$row['p_score'];
  1573. switch($p_score){
  1574. case 0:
  1575. $imagerating='<img src="../img/wiki/rating/stars_0.gif"/>';
  1576. break;
  1577. case 1:
  1578. $imagerating='<img src="../img/wiki/rating/stars_5.gif"/>';
  1579. break;
  1580. case 2:
  1581. $imagerating='<img src="../img/wiki/rating/stars_10.gif"/>';
  1582. break;
  1583. case 3:
  1584. $imagerating='<img src="../img/wiki/rating/stars_15.gif"/>';
  1585. break;
  1586. case 4:
  1587. $imagerating='<img src="../img/wiki/rating/stars_20.gif"/>';
  1588. break;
  1589. case 5:
  1590. $imagerating='<img src="../img/wiki/rating/stars_25.gif"/>';
  1591. break;
  1592. case 6:
  1593. $imagerating='<img src="../img/wiki/rating/stars_30.gif"/>';
  1594. break;
  1595. case 7:
  1596. $imagerating='<img src="../img/wiki/rating/stars_35.gif"/>';
  1597. break;
  1598. case 8:
  1599. $imagerating='<img src="../img/wiki/rating/stars_40.gif"/>';
  1600. break;
  1601. case 9:
  1602. $imagerating='<img src="../img/wiki/rating/stars_45.gif"/>';
  1603. break;
  1604. case 10:
  1605. $imagerating='<img src="../img/wiki/rating/stars_50.gif"/>';
  1606. break;
  1607. }
  1608. echo '<p><table>';
  1609. echo '<tr>';
  1610. echo '<td rowspan="2">'.$author_photo.'</td>';
  1611. echo '<td style=" color:#999999"><a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a> ('.$author_status.') '.$row['dtime'].' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' </td>';
  1612. echo '</tr>';
  1613. echo '<tr>';
  1614. echo '<td>'.$row['comment'].'</td>';
  1615. echo '</tr>';
  1616. echo "</table>";
  1617. echo '<hr noshade size="1">';
  1618. }
  1619. // echo"</div>";
  1620. }
  1621. else
  1622. {
  1623. Display::display_warning_message(get_lang('LockByTeacher'),false);
  1624. }
  1625. }
  1626. else
  1627. {
  1628. Display::display_normal_message(get_lang('DiscussNotAvailable'));
  1629. }
  1630. }
  1631. echo "</div>"; // echo "<div id='mainwiki'>";
  1632. echo "</div>"; // echo "<div id='wikiwrapper'>";
  1633. /*
  1634. ==============================================================================
  1635. FOOTER
  1636. ==============================================================================
  1637. */
  1638. //$_SESSION['_gid'];
  1639. Display::display_footer();
  1640. /*
  1641. ==============================================================================
  1642. FUNCTIONS
  1643. ==============================================================================
  1644. */
  1645. /**
  1646. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1647. * @desc This function checks weither the proposed reflink is not in use yet. It is a recursive function because every newly created reflink suggestion
  1648. * has to be checked also
  1649. */
  1650. function createreflink($testvalue)
  1651. {
  1652. global $groupfilter;
  1653. $counter='';
  1654. while (!checktitle($testvalue.$counter))
  1655. {
  1656. $counter++;
  1657. echo $counter."-".$testvalue.$counter."<br />";
  1658. }
  1659. // the reflink has not been found yet, so it is OK
  1660. return $testvalue.$counter;
  1661. }
  1662. /**
  1663. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1664. **/
  1665. function checktitle($paramwk)
  1666. {
  1667. global $tbl_wiki;
  1668. global $groupfilter;
  1669. $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($paramwk)))).'" AND '.$groupfilter.''; // TODO: check if need entity
  1670. $result=api_sql_query($sql,__FILE__,__LINE__);
  1671. $numberofresults=Database::num_rows($result);
  1672. if ($numberofresults==0) // the value has not been found and is this available
  1673. {
  1674. return true;
  1675. }
  1676. else // the value has been found
  1677. {
  1678. return false;
  1679. }
  1680. }
  1681. /**
  1682. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1683. * check wikilinks that has a page
  1684. **/
  1685. function links_to($input)
  1686. {
  1687. $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE);
  1688. $all_links = array();
  1689. foreach ($input_array as $key=>$value)
  1690. {
  1691. if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]')
  1692. {
  1693. if (strpos($value, "|") != false)
  1694. {
  1695. $full_link_array=explode("|", $value);
  1696. $link=trim($full_link_array[0]);
  1697. $title=trim($full_link_array[1]);
  1698. }
  1699. else
  1700. {
  1701. $link=$value;
  1702. $title=$value;
  1703. }
  1704. unset($input_array[$key-1]);
  1705. unset($input_array[$key+1]);
  1706. $all_links[]= Database::escape_string(str_replace(' ','_',$link)).' '; //replace blank spaces by _ within the links. But to remove links at the end add a blank space
  1707. }
  1708. }
  1709. $output=implode($all_links);
  1710. return $output;
  1711. }
  1712. /*
  1713. detect and add style to external links
  1714. author Juan Carlos Raña Trabado
  1715. **/
  1716. function detect_external_link($input)
  1717. {
  1718. $exlink='href=';
  1719. $exlinkStyle='class="wiki_link_ext" href=';
  1720. $output=str_replace($exlink, $exlinkStyle, $input);
  1721. return $output;
  1722. }
  1723. /*
  1724. detect and add style to anchor links
  1725. author Juan Carlos Raña Trabado
  1726. **/
  1727. function detect_anchor_link($input)
  1728. {
  1729. $anchorlink='href="#';
  1730. $anchorlinkStyle='class="wiki_anchor_link" href="#';
  1731. $output=str_replace($anchorlink, $anchorlinkStyle, $input);
  1732. return $output;
  1733. }
  1734. /*
  1735. detect and add style to mail links
  1736. author Juan Carlos Raña Trabado
  1737. **/
  1738. function detect_mail_link($input)
  1739. {
  1740. $maillink='href="mailto';
  1741. $maillinkStyle='class="wiki_mail_link" href="mailto';
  1742. $output=str_replace($maillink, $maillinkStyle, $input);
  1743. return $output;
  1744. }
  1745. /*
  1746. detect and add style to ftp links
  1747. author Juan Carlos Raña Trabado
  1748. **/
  1749. function detect_ftp_link($input)
  1750. {
  1751. $ftplink='href="ftp';
  1752. $ftplinkStyle='class="wiki_ftp_link" href="ftp';
  1753. $output=str_replace($ftplink, $ftplinkStyle, $input);
  1754. return $output;
  1755. }
  1756. /*
  1757. detect and add style to news links
  1758. author Juan Carlos Raña Trabado
  1759. **/
  1760. function detect_news_link($input)
  1761. {
  1762. $newslink='href="news';
  1763. $newslinkStyle='class="wiki_news_link" href="news';
  1764. $output=str_replace($newslink, $newslinkStyle, $input);
  1765. return $output;
  1766. }
  1767. /*
  1768. detect and add style to irc links
  1769. author Juan Carlos Raña Trabado
  1770. **/
  1771. function detect_irc_link($input)
  1772. {
  1773. $irclink='href="irc';
  1774. $irclinkStyle='class="wiki_irc_link" href="irc';
  1775. $output=str_replace($irclink, $irclinkStyle, $input);
  1776. return $output;
  1777. }
  1778. /*
  1779. * This function allows users to have [link to a title]-style links like in most regular wikis.
  1780. * It is true that the adding of links is probably the most anoying part of Wiki for the people
  1781. * who know something about the wiki syntax.
  1782. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1783. * Improvements [[]] and [[ | ]]by Juan Carlos Raña
  1784. * Improvements internal wiki style and mark group by Juan Carlos Raña
  1785. **/
  1786. function make_wiki_link_clickable($input)
  1787. {
  1788. if (isset($_SESSION['_gid']))
  1789. {
  1790. $_clean['group_id']=(int)$_SESSION['_gid'];
  1791. }
  1792. if (isset($_GET['group_id']))
  1793. {
  1794. $_clean['group_id']=(int)Security::remove_XSS($_GET['group_id']);
  1795. }
  1796. $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE); //now doubles brackets
  1797. foreach ($input_array as $key=>$value)
  1798. {
  1799. if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') //now doubles brackets
  1800. {
  1801. if ($_clean['group_id']==0)
  1802. {
  1803. $titleg_ex='';
  1804. }
  1805. else
  1806. {
  1807. $titleg_ex='<sup>(g'.$_clean['group_id'].')</sup>';
  1808. }
  1809. //now full wikilink
  1810. if (strpos($value, "|") != false)
  1811. {
  1812. $full_link_array=explode("|", $value);
  1813. $link=trim($full_link_array[0]);
  1814. $title=trim($full_link_array[1]);
  1815. }
  1816. else
  1817. {
  1818. $link=$value;
  1819. $title=$value;
  1820. }
  1821. //if wikilink is homepage
  1822. if($link=='index'){
  1823. $title=get_lang('DefaultTitle');
  1824. }
  1825. if ($link==get_lang('DefaultTitle')){
  1826. $link='index';
  1827. }
  1828. // 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
  1829. if (checktitle(strtolower(str_replace(' ','_',$link))))
  1830. {
  1831. $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq='.$_course[id].'&action=addnew&amp;title='.urldecode($link).'&group_id='.$_clean['group_id'].'" class="new_wiki_link">'.$title.$titleg_ex.'</a>';
  1832. }
  1833. else
  1834. {
  1835. $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.strtolower(str_replace(' ','_',$link)).'&group_id='.$_clean['group_id'].'" class="wiki_link">'.$title.$titleg_ex.'</a>';
  1836. }
  1837. unset($input_array[$key-1]);
  1838. unset($input_array[$key+1]);
  1839. }
  1840. }
  1841. $output=implode('',$input_array);
  1842. return $output;
  1843. }
  1844. /**
  1845. * This function saves a change in a wiki page
  1846. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1847. * @return language string saying that the changes are stored
  1848. **/
  1849. function save_wiki()
  1850. {
  1851. global $tbl_wiki;
  1852. // NOTE: visibility, visibility_disc and ratinglock_disc changes are not made here, but through the interce buttons
  1853. // cleaning the variables
  1854. $_clean['reflink']=Database::escape_string($_POST['reflink']);
  1855. $_clean['title']=Database::escape_string($_POST['title']);
  1856. $_clean['content']= html_entity_decode(Database::escape_string(stripslashes($_POST['content'])));
  1857. $_clean['user_id']=(int)Database::escape_string(api_get_user_id());
  1858. $_clean['assignment']=Database::escape_string($_POST['assignment']);
  1859. $_clean['comment']=Database::escape_string($_POST['comment']);
  1860. $_clean['progress']=Database::escape_string($_POST['progress']);
  1861. $_clean['version']=Database::escape_string($_POST['version']);
  1862. $_clean['version']=$_clean['version']+1;//sum 1 here instead of adding in Database::escape_string($_POST['version']), to avoid failures in the sum when there is heavy use of the database
  1863. $_clean['linksto'] = links_to($_clean['content']); //and check links content
  1864. $dtime = date( "Y-m-d H:i:s" );
  1865. if (isset($_SESSION['_gid']))
  1866. {
  1867. $_clean['group_id']=Database::escape_string($_SESSION['_gid']);
  1868. }
  1869. if (isset($_GET['group_id']))
  1870. {
  1871. $_clean['group_id']=Database::escape_string($_GET['group_id']);
  1872. }
  1873. $sql="INSERT INTO ".$tbl_wiki." (reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$dtime."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."')";
  1874. $result=api_sql_query($sql);
  1875. $Id = Database::insert_id();
  1876. api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id());
  1877. check_emailcue($_clean['reflink'], 'P', $dtime, $_clean['user_id']);
  1878. return get_lang('ChangesStored');
  1879. }
  1880. /**
  1881. * This function restore a wikipage
  1882. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1883. **/
  1884. function restore_wikipage($r_reflink, $r_title, $r_content, $r_group_id, $r_assignment, $r_progress, $c_version, $r_version, $r_linksto)
  1885. {
  1886. global $tbl_wiki;
  1887. $r_user_id= api_get_user_id();
  1888. $r_dtime = date( "Y-m-d H:i:s" );
  1889. $r_version = $r_version+1;
  1890. $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
  1891. $sql="INSERT INTO ".$tbl_wiki." (reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip) VALUES ('".$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'])."')";
  1892. $result=api_sql_query($sql);
  1893. $Id = Database::insert_id();
  1894. api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id());
  1895. check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id);
  1896. return get_lang('PageRestored');
  1897. }
  1898. /**
  1899. * This function delete a wiki
  1900. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1901. **/
  1902. function delete_wiki()
  1903. {
  1904. global $tbl_wiki, $tbl_wiki_discuss, $tbl_wiki_mailcue, $groupfilter;
  1905. //identify the first id by group = identify wiki
  1906. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY id DESC';
  1907. $allpages=api_sql_query($sql,__FILE__,__LINE__);
  1908. while ($row=Database::fetch_array($allpages)) {
  1909. $id = $row['id'];
  1910. $group_id = $row['group_id'];
  1911. }
  1912. api_sql_query('DELETE FROM '.$tbl_wiki_discuss.' WHERE publication_id="'.$id.'"' ,__FILE__,__LINE__);
  1913. api_sql_query('DELETE FROM '.$tbl_wiki_mailcue.' WHERE group_id="'.$group_id.'"' ,__FILE__,__LINE__);
  1914. api_sql_query('DELETE FROM '.$tbl_wiki.' WHERE '.$groupfilter.'',__FILE__,__LINE__);
  1915. return get_lang('WikiDeleted');
  1916. }
  1917. /**
  1918. * This function saves a new wiki page.
  1919. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1920. * @todo consider merging this with the function save_wiki into one single function.
  1921. **/
  1922. function save_new_wiki()
  1923. {
  1924. global $tbl_wiki;
  1925. global $assig_user_id; //need for assignments mode
  1926. // cleaning the variables
  1927. $_clean['assignment']=Database::escape_string($_POST['assignment']);
  1928. if($_clean['assignment']==2 || $_clean['assignment']==1) // Unlike ordinary pages of pages of assignments. Allow create a ordinary page although there is a assignment with the same name
  1929. {
  1930. $_clean['reflink']=Database::escape_string(str_replace(' ','_',$_POST['title']."_uass".$assig_user_id));
  1931. }
  1932. else
  1933. {
  1934. $_clean['reflink']=Database::escape_string(str_replace(' ','_',$_POST['title']));
  1935. }
  1936. $_clean['title']=Database::escape_string($_POST['title']);
  1937. $_clean['content']= html_entity_decode(Database::escape_string(stripslashes($_POST['content'])));
  1938. if($_clean['assignment']==2) //config by default for individual assignment (students)
  1939. {
  1940. $_clean['user_id']=(int)Database::escape_string($assig_user_id);//Identifies the user as a creator, not the teacher who created
  1941. $_clean['visibility']=0;
  1942. $_clean['visibility_disc']=0;
  1943. $_clean['ratinglock_disc']=0;
  1944. }
  1945. else
  1946. {
  1947. $_clean['user_id']=(int)Database::escape_string(api_get_user_id());
  1948. $_clean['visibility']=1;
  1949. $_clean['visibility_disc']=1;
  1950. $_clean['ratinglock_disc']=1;
  1951. }
  1952. $_clean['comment']=Database::escape_string($_POST['comment']);
  1953. $_clean['progress']=Database::escape_string($_POST['progress']);
  1954. $_clean['version']=1;
  1955. if (isset($_SESSION['_gid']))
  1956. {
  1957. $_clean['group_id']=(int)$_SESSION['_gid'];
  1958. }
  1959. if (isset($_GET['group_id']))
  1960. {
  1961. $_clean['group_id']=(int)Database::escape_string($_GET['group_id']);
  1962. }
  1963. $_clean['linksto'] = links_to($_clean['content']); //check wikilinks
  1964. //filter no _uass
  1965. if(eregi("_uass",$_POST['title']) || (strtoupper(trim($_POST['title']))==strtoupper ('index') || strtoupper(trim(htmlentities($_POST['title'])))==strtoupper(htmlentities(get_lang('DefaultTitle')))))
  1966. {
  1967. $message= get_lang('GoAndEditMainPage');
  1968. Display::display_warning_message($message,false);
  1969. }
  1970. else
  1971. {
  1972. $var=$_clean['reflink'];
  1973. $group_id=Security::remove_XSS($_GET['group_id']);
  1974. if(!checktitle($var))
  1975. {
  1976. return get_lang('WikiPageTitleExist').'<a href="index.php?action=edit&amp;title='.$var.'&group_id='.$group_id.'">'.$_POST['title'].'</a>';
  1977. }
  1978. else
  1979. {
  1980. $dtime = date( "Y-m-d H:i:s" );
  1981. $sql="INSERT INTO ".$tbl_wiki." (reflink, title, content, user_id, group_id, dtime, visibility, visibility_disc, ratinglock_disc, assignment, comment, progress, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$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'])."')";
  1982. $result=api_sql_query($sql,__LINE__,__FILE__);
  1983. $Id = Database::insert_id();
  1984. api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id());
  1985. check_emailcue(0, 'A');
  1986. return get_lang('NewWikiSaved').'<a href="index.php?action=showpage&amp;title='.$_clean['reflink'].'&group_id='.$group_id.'">'.$_POST['title'].'</a>';
  1987. }
  1988. }//end filter no _uass
  1989. }
  1990. /**
  1991. * This function displays the form for adding a new wiki page.
  1992. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  1993. * @return html code
  1994. **/
  1995. function display_new_wiki_form()
  1996. {
  1997. ?>
  1998. <script language="JavaScript" type="text/JavaScript">
  1999. <!--
  2000. function Send(form)
  2001. {
  2002. if (form.title.value == "")
  2003. {
  2004. alert("<?php echo get_lang('NoWikiPageTitle');?>"); form.title.focus();return false;
  2005. }
  2006. form.submit();
  2007. }
  2008. //-->
  2009. </script>
  2010. <?php
  2011. echo '<form name="form1" method="post" action="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&amp;title='.$page.'&group_id='.Security::remove_XSS($_GET['group_id']).'">';
  2012. echo '<div id="wikititle">';
  2013. echo '<span class="form_required">*</span> '.get_lang(Title).': <input type="text" name="title" value="'.urldecode($_GET['title']).'">';
  2014. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2015. {
  2016. $_clean['group_id']=(int)$_SESSION['_gid']; // TODO: check if delete ?
  2017. echo '&nbsp;<img src="../img/wiki/assignment.gif" />&nbsp;'.get_lang('DefineAssignmentPage').'&nbsp;<input type="checkbox" name="assignment" value="1">'; // 1= teacher 2 =student
  2018. //by now turned off
  2019. //echo'<div style="border:groove">';
  2020. //echo '&nbsp;'.get_lang('StartDate').': <INPUT TYPE="text" NAME="startdate_assig" VALUE="0000-00-00 00:00:00">(yyyy-mm-dd hh:mm:ss)'; //by now turned off
  2021. //echo '&nbsp;'.get_lang('EndDate').': <INPUT TYPE="text" NAME="enddate_assig" VALUE="0000-00-00 00:00:00">(yyyy-mm-dd hh:mm:ss)'; //by now turned off
  2022. //echo '<br />&nbsp;'.get_lang('AllowLaterSends').'&nbsp;<INPUT TYPE="checkbox" NAME="delayedsubmit" VALUE="0">'; //by now turned off
  2023. //echo'</div>';
  2024. }
  2025. echo '</div>';
  2026. echo '<div id="wikicontent">';
  2027. api_disp_html_area('content','','300px');
  2028. echo '<br/>';
  2029. echo '<br/>';
  2030. echo get_lang('Comments').':&nbsp;&nbsp;<input type="text" name="comment" value="'.stripslashes($row['comment']).'"><br /><br />';
  2031. echo get_lang('Progress').':&nbsp;&nbsp;<select name="progress" id="progress">
  2032. <option value="0" selected>0</option>
  2033. <option value="10">10</option>
  2034. <option value="20">20</option>
  2035. <option value="30">30</option>
  2036. <option value="40">40</option>
  2037. <option value="50">50</option>
  2038. <option value="60">60</option>
  2039. <option value="70">70</option>
  2040. <option value="80">80</option>
  2041. <option value="90">90</option>
  2042. <option value="100">100</option>
  2043. </select> %';
  2044. echo '<br/><br/>';
  2045. echo '<input type="hidden" name="SaveWikiNew" value="'.get_lang('langSave').'">'; //for save icon
  2046. echo '<button class="save" type="submit" name="SaveWikiNew" " onClick="return Send(this.form)">'.get_lang('langSave').'</button>'; //for button icon
  2047. echo '</div>';
  2048. echo '</form>';
  2049. }
  2050. /**
  2051. * This function displays a wiki entry
  2052. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  2053. * @return html code
  2054. **/
  2055. function display_wiki_entry()
  2056. {
  2057. global $tbl_wiki;
  2058. global $groupfilter;
  2059. global $page;
  2060. $_clean['group_id']=(int)$_SESSION['_gid'];
  2061. if ($_GET['view'])
  2062. {
  2063. $_clean['view']=(int)Database::escape_string($_GET['view']);
  2064. $filter=" AND id='".$_clean['view']."'";
  2065. }
  2066. //first, check page visibility in the first page version
  2067. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2068. $result=api_sql_query($sql,__LINE__,__FILE__);
  2069. $row=Database::fetch_array($result);
  2070. $KeyVisibility=$row['visibility'];
  2071. // second, show the last version
  2072. $sql="SELECT * FROM ".$tbl_wiki."WHERE reflink='".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))."' AND $groupfilter $filter ORDER BY id DESC";
  2073. $result=api_sql_query($sql,__LINE__,__FILE__);
  2074. $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
  2075. //update visits
  2076. if($row['id'])
  2077. {
  2078. $sql='UPDATE '.$tbl_wiki.' SET hits=(hits+1) WHERE id='.$row['id'].'';
  2079. api_sql_query($sql,__FILE__,__LINE__);
  2080. }
  2081. // if both are empty and we are displaying the index page then we display the default text.
  2082. if ($row['content']=='' AND $row['title']=='' AND $page='index')
  2083. {
  2084. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2085. {
  2086. $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH));
  2087. $title=get_lang('DefaultTitle');
  2088. }
  2089. else
  2090. {
  2091. return Display::display_normal_message(get_lang('WikiStandBy'));
  2092. }
  2093. }
  2094. else
  2095. {
  2096. $content=$row['content'];
  2097. $title=$row['title'];
  2098. }
  2099. //assignment mode: for identify page type
  2100. if(stripslashes($row['assignment'])==1)
  2101. {
  2102. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  2103. }
  2104. elseif(stripslashes($row['assignment'])==2)
  2105. {
  2106. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  2107. }
  2108. //Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
  2109. if($KeyVisibility=="1" || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id'])))
  2110. {
  2111. echo '<div id="wikititle">';
  2112. // page action: enable or disable the adding of new pages
  2113. if (check_addnewpagelock())
  2114. {
  2115. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2116. {
  2117. $protect_addnewpage= '<img src="../img/wiki/lockadd.gif" title="'.get_lang('AddOptionProtected').'" alt="'.get_lang('AddOptionProtected').'" />';
  2118. }
  2119. }
  2120. else
  2121. {
  2122. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2123. {
  2124. $protect_addnewpage= '<img src="../img/wiki/unlockadd.gif" title="'.get_lang('AddOptionUnprotected').'" alt="'.get_lang('AddOptionUnprotected').'" />';
  2125. }
  2126. }
  2127. echo '<span style="float:right">';
  2128. echo '<a href="index.php?action=show&amp;actionpage=addlock&amp;title='.$page.'">'.$protect_addnewpage.'</a> ';
  2129. echo '</span>';
  2130. // page action: protecting (locking) the page
  2131. if (check_protect_page())
  2132. {
  2133. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2134. {
  2135. $protect_page= '<img src="../img/wiki/lock.gif" title="'.get_lang('PageLockedExtra').'" alt="'.get_lang('PageLockedExtra').'" />';
  2136. }
  2137. else
  2138. {
  2139. $protect_page= '<img src="../img/wiki/lock.gif" title="'.get_lang('PageLockedExtra').'" alt="'.get_lang('PageLockedExtra').'" />';
  2140. }
  2141. }
  2142. else
  2143. {
  2144. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2145. {
  2146. $protect_page= '<img src="../img/wiki/unlock.gif" title="'.get_lang('PageUnlockedExtra').'" alt="'.get_lang('PageUnlockedExtra').'" />';
  2147. }
  2148. }
  2149. echo '<span style="float:right">';
  2150. echo '<a href="index.php?action=showpage&amp;actionpage=lock&amp;title='.$page.'">'.$protect_page.'</a>';
  2151. echo '</span>';
  2152. //page action: visibility
  2153. if (check_visibility_page())
  2154. {
  2155. //This hides the icon eye closed to users of work they can see yours
  2156. if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false)
  2157. {
  2158. $visibility_page= '<img src="../img/wiki/invisible.gif" title="'.get_lang('HidePageExtra').'" alt="'.get_lang('HidePageExtra').'" />';
  2159. }
  2160. }
  2161. else
  2162. {
  2163. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2164. {
  2165. $visibility_page= '<img src="../img/wiki/visible.gif" title="'.get_lang('ShowPageExtra').'" alt="'.get_lang('ShowPageExtra').'" />';
  2166. }
  2167. }
  2168. echo '<span style="float:right">';
  2169. echo '<a href="index.php?action=showpage&amp;actionpage=visibility&amp;title='.$page.'">'.$visibility_page.'</a>';
  2170. echo '</span>';
  2171. //page action: notification
  2172. if (check_notify_page($page))
  2173. {
  2174. $notify_page= '<img src="../img/wiki/send_mail_checked.gif" title="'.get_lang('NotifyByEmail').'" alt="'.get_lang('NotifyByEmail').'" />';
  2175. }
  2176. else
  2177. {
  2178. $notify_page= '<img src="../img/wiki/send_mail.gif" title="'.get_lang('CancelNotifyByEmail').'" alt="'.get_lang('CancelNotifyByEmail').'" />';
  2179. }
  2180. echo '<span style="float:right">';
  2181. echo '<a href="index.php?action=showpage&amp;actionpage=notify&amp;title='.$page.'">'.$notify_page.'</a>';
  2182. echo '</span>';
  2183. //page action: export to pdf
  2184. echo '<span style="float:right">';
  2185. echo '<form name="form_export2PDF" method="post" action="export_html2pdf.php" target="_blank, fullscreen">'; // also with export_tcpdf.php
  2186. echo '<input type=hidden name="titlePDF" value="'.htmlentities($title).'">';
  2187. echo '<input type=hidden name="contentPDF" value="'.htmlentities($content).'">';
  2188. echo '<input type="image" src="../img/wiki/wexport2pdf.gif" border ="0" title="'.get_lang('ExportToPDF').'" alt="'.get_lang('ExportToPDF').'" style=" border:none;">';
  2189. echo '</form>';
  2190. echo '</span>';
  2191. //page action: copy last version to doc area
  2192. if(api_is_allowed_to_edit() || api_is_platform_admin())
  2193. {
  2194. echo '<span style="float:right;">';
  2195. echo '<form name="form_export2DOC" method="post" action="index.php">';
  2196. echo '<input type=hidden name="export2DOC" value="export2doc">';
  2197. echo '<input type=hidden name="titleDOC" value="'.htmlentities($title).'">';
  2198. echo '<input type=hidden name="contentDOC" value="'.htmlentities($content).'">';
  2199. echo '<input type="image" src="../img/wiki/wexport2doc.png" border ="0" title="'.get_lang('ExportToDocArea').'" alt="'.get_lang('ExportToDocArea').'" style=" border:none;">';
  2200. echo '</form>';
  2201. echo '</span>';
  2202. }
  2203. //export to print
  2204. ?>
  2205. <script>
  2206. function goprint()
  2207. {
  2208. var a = window.open('','','width=800,height=600');
  2209. a.document.open("text/html");
  2210. a.document.write(document.getElementById('wikicontent').innerHTML);
  2211. a.document.close();
  2212. a.print();
  2213. }
  2214. </script>
  2215. <?php
  2216. echo '<span style="float:right; cursor: pointer;">';
  2217. echo '<img src="../img/wiki/wprint.gif" title="'.get_lang('Print').'" alt="'.get_lang('Print').'" onclick="goprint()">';
  2218. echo '</span>';
  2219. if (empty($title))
  2220. {
  2221. $title=get_lang('DefaultTitle');
  2222. }
  2223. if (wiki_exist($title))
  2224. {
  2225. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.stripslashes($title);
  2226. }
  2227. else
  2228. {
  2229. echo stripslashes($title);
  2230. }
  2231. echo '</div>';
  2232. echo '<div id="wikicontent">'. make_wiki_link_clickable(detect_external_link(detect_anchor_link(detect_mail_link(detect_ftp_link(detect_irc_link(detect_news_link(stripslashes($content)))))))).'</div>';
  2233. echo '<div id="wikifooter">'.get_lang('Progress').': '.stripslashes($row['progress']).'%&nbsp;&nbsp;&nbsp;'.get_lang('Rating').': '.stripslashes($row['score']).'&nbsp;&nbsp;&nbsp;'.get_lang('Words').': '.word_count($content).'</div>';
  2234. }//end filter visibility
  2235. } // end function display_wiki_entry
  2236. //more for export to course document area. See display_wiki_entry
  2237. if ($_POST['export2DOC'])
  2238. {
  2239. $titleDOC=$_POST['titleDOC'];
  2240. $contentDOC=$_POST['contentDOC'];
  2241. $groupIdDOC=$_clean['group_id'];
  2242. export2doc($titleDOC,$contentDOC,$groupIdDOC);
  2243. }
  2244. /**
  2245. * This function counted the words in a document. Thanks Adeel Khan
  2246. */
  2247. function word_count($document) {
  2248. $search = array(
  2249. '@<script[^>]*?>.*?</script>@si',
  2250. '@<style[^>]*?>.*?</style>@siU',
  2251. '@<![\s\S]*?--[ \t\n\r]*>@'
  2252. );
  2253. $document = preg_replace($search, '', $document);
  2254. # strip all html tags
  2255. $wc = strip_tags($document);
  2256. # remove 'words' that don't consist of alphanumerical characters or punctuation
  2257. $pattern = "#[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]+#";
  2258. $wc = trim(preg_replace($pattern, " ", $wc));
  2259. # remove one-letter 'words' that consist only of punctuation
  2260. $wc = trim(preg_replace("#\s*[(\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]\s*#", " ", $wc));
  2261. # remove superfluous whitespace
  2262. $wc = preg_replace("/\s\s+/", " ", $wc);
  2263. # split string into an array of words
  2264. $wc = explode(" ", $wc);
  2265. # remove empty elements
  2266. $wc = array_filter($wc);
  2267. # return the number of words
  2268. return count($wc);
  2269. }
  2270. /**
  2271. * This function checks if wiki title exist
  2272. */
  2273. function wiki_exist($title)
  2274. {
  2275. global $tbl_wiki;
  2276. global $groupfilter;
  2277. $sql='SELECT id FROM '.$tbl_wiki.'WHERE title="'.Database::escape_string($title).'" AND '.$groupfilter.' ORDER BY id ASC';
  2278. $result=api_sql_query($sql,__LINE__,__FILE__);
  2279. $cant=Database::num_rows($result);
  2280. if ($cant>0)
  2281. return true;
  2282. else
  2283. return false;
  2284. }
  2285. /**
  2286. * This function a wiki warning
  2287. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  2288. * @return html code
  2289. **/
  2290. function display_wiki_warning($variable)
  2291. {
  2292. echo '<div class="wiki_warning">'.$variable.'</div>';
  2293. }
  2294. /**
  2295. * Checks if this navigation tab has to be set to active
  2296. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  2297. * @return html code
  2298. */
  2299. function is_active_navigation_tab($paramwk)
  2300. {
  2301. if ($_GET['action']==$paramwk)
  2302. {
  2303. return ' class="active"';
  2304. }
  2305. }
  2306. /**
  2307. * Lock add pages
  2308. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2309. */
  2310. function check_addnewpagelock()
  2311. {
  2312. global $tbl_wiki;
  2313. global $groupfilter;
  2314. $_clean['group_id']=(int)$_SESSION['_gid'];
  2315. $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.' ORDER BY id ASC';
  2316. $result=api_sql_query($sql,__LINE__,__FILE__);
  2317. $row=Database::fetch_array($result);
  2318. $status_addlock=$row['addlock'];
  2319. //change status
  2320. if ($_GET['actionpage']=='addlock' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2321. {
  2322. if ($row['addlock']==1)
  2323. {
  2324. $status_addlock=0;
  2325. }
  2326. else
  2327. {
  2328. $status_addlock=1;
  2329. }
  2330. api_sql_query('UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string($status_addlock).'" WHERE '.$groupfilter.'',__LINE__,__FILE__);
  2331. $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.' ORDER BY id ASC';
  2332. $result=api_sql_query($sql,__LINE__,__FILE__);
  2333. $row=Database::fetch_array($result);
  2334. }
  2335. //show status
  2336. if ($row['addlock']==1 || ($row['content']=='' AND $row['title']=='' AND $page='index'))
  2337. {
  2338. return false;
  2339. }
  2340. else
  2341. {
  2342. return true;
  2343. }
  2344. }
  2345. /**
  2346. * Protect page
  2347. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2348. */
  2349. function check_protect_page()
  2350. {
  2351. global $tbl_wiki;
  2352. global $page;
  2353. global $groupfilter;
  2354. $_clean['group_id']=(int)$_SESSION['_gid'];
  2355. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2356. $result=api_sql_query($sql,__LINE__,__FILE__);
  2357. $row=Database::fetch_array($result);
  2358. $status_editlock=$row['editlock'];
  2359. $id=$row['id'];
  2360. ///change status
  2361. if ($_GET['actionpage']=='lock' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2362. {
  2363. if ($row['editlock']==0)
  2364. {
  2365. $status_editlock=1;
  2366. }
  2367. else
  2368. {
  2369. $status_editlock=0;
  2370. }
  2371. $sql='UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string($status_editlock).'" WHERE id="'.$id.'"';
  2372. api_sql_query($sql,__FILE__,__LINE__);
  2373. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2374. $result=api_sql_query($sql,__LINE__,__FILE__);
  2375. $row=Database::fetch_array($result);
  2376. }
  2377. //show status
  2378. if ($row['editlock']==0 || ($row['content']=='' AND $row['title']=='' AND $page=='index'))
  2379. {
  2380. return false;
  2381. }
  2382. else
  2383. {
  2384. return true;
  2385. }
  2386. }
  2387. /**
  2388. * Visibility page
  2389. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2390. */
  2391. function check_visibility_page()
  2392. {
  2393. global $tbl_wiki;
  2394. global $page;
  2395. global $groupfilter;
  2396. $_clean['group_id']=(int)$_SESSION['_gid'];
  2397. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2398. $result=api_sql_query($sql,__LINE__,__FILE__);
  2399. $row=Database::fetch_array($result);
  2400. $status_visibility=$row['visibility'];
  2401. $id=$row['id']; //need ? check. TODO
  2402. //change status
  2403. if ($_GET['actionpage']=='visibility' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2404. {
  2405. if ($row['visibility']==1)
  2406. {
  2407. $status_visibility=0;
  2408. }
  2409. else
  2410. {
  2411. $status_visibility=1;
  2412. }
  2413. $sql='UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string($status_visibility).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter;
  2414. api_sql_query($sql,__FILE__,__LINE__);
  2415. //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
  2416. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2417. $result=api_sql_query($sql,__LINE__,__FILE__);
  2418. $row=Database::fetch_array($result);
  2419. }
  2420. //show status
  2421. if ($row['visibility']=="1" || ($row['content']=='' AND $row['title']=='' AND $page=='index'))
  2422. {
  2423. return false;
  2424. }
  2425. else
  2426. {
  2427. return true;
  2428. }
  2429. }
  2430. /**
  2431. * Visibility discussion
  2432. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2433. */
  2434. function check_visibility_discuss()
  2435. {
  2436. global $tbl_wiki;
  2437. global $page;
  2438. global $groupfilter;
  2439. $_clean['group_id']=(int)$_SESSION['_gid'];
  2440. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2441. $result=api_sql_query($sql,__LINE__,__FILE__);
  2442. $row=Database::fetch_array($result);
  2443. $status_visibility_disc=$row['visibility_disc'];
  2444. $id=$row['id']; //need ? check. TODO
  2445. //change status
  2446. if ($_GET['actionpage']=='visibility_disc' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2447. {
  2448. if ($row['visibility_disc']==1)
  2449. {
  2450. $status_visibility_disc=0;
  2451. }
  2452. else
  2453. {
  2454. $status_visibility_disc=1;
  2455. }
  2456. $sql='UPDATE '.$tbl_wiki.' SET visibility_disc="'.Database::escape_string($status_visibility_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter;
  2457. api_sql_query($sql,__FILE__,__LINE__);
  2458. //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
  2459. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2460. $result=api_sql_query($sql,__LINE__,__FILE__);
  2461. $row=Database::fetch_array($result);
  2462. }
  2463. //show status
  2464. if ($row['visibility_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index'))
  2465. {
  2466. return false;
  2467. }
  2468. else
  2469. {
  2470. return true;
  2471. }
  2472. }
  2473. /**
  2474. * Lock add discussion
  2475. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2476. */
  2477. function check_addlock_discuss()
  2478. {
  2479. global $tbl_wiki;
  2480. global $page;
  2481. global $groupfilter;
  2482. $_clean['group_id']=(int)$_SESSION['_gid'];
  2483. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2484. $result=api_sql_query($sql,__LINE__,__FILE__);
  2485. $row=Database::fetch_array($result);
  2486. $status_addlock_disc=$row['addlock_disc'];
  2487. $id=$row['id']; //need ? check. TODO
  2488. //change status
  2489. if ($_GET['actionpage']=='addlock_disc' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2490. {
  2491. if ($row['addlock_disc']==1)
  2492. {
  2493. $status_addlock_disc=0;
  2494. }
  2495. else
  2496. {
  2497. $status_addlock_disc=1;
  2498. }
  2499. $sql='UPDATE '.$tbl_wiki.' SET addlock_disc="'.Database::escape_string($status_addlock_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter;
  2500. api_sql_query($sql,__FILE__,__LINE__);
  2501. //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
  2502. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2503. $result=api_sql_query($sql,__LINE__,__FILE__);
  2504. $row=Database::fetch_array($result);
  2505. }
  2506. //show status
  2507. if ($row['addlock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index'))
  2508. {
  2509. return false;
  2510. }
  2511. else
  2512. {
  2513. return true;
  2514. }
  2515. }
  2516. /**
  2517. * Lock rating discussion
  2518. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2519. */
  2520. function check_ratinglock_discuss()
  2521. {
  2522. global $tbl_wiki;
  2523. global $page;
  2524. global $groupfilter;
  2525. $_clean['group_id']=(int)$_SESSION['_gid'];
  2526. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2527. $result=api_sql_query($sql,__LINE__,__FILE__);
  2528. $row=Database::fetch_array($result);
  2529. $status_ratinglock_disc=$row['ratinglock_disc'];
  2530. $id=$row['id']; //need ? check. TODO
  2531. //change status
  2532. if ($_GET['actionpage']=='ratinglock_disc' && (api_is_allowed_to_edit() || api_is_platform_admin()))
  2533. {
  2534. if ($row['ratinglock_disc']==1)
  2535. {
  2536. $status_ratinglock_disc=0;
  2537. }
  2538. else
  2539. {
  2540. $status_ratinglock_disc=1;
  2541. }
  2542. $sql='UPDATE '.$tbl_wiki.' SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; //Visibility. Value to all,not only for the first
  2543. api_sql_query($sql,__FILE__,__LINE__);
  2544. //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
  2545. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
  2546. $result=api_sql_query($sql,__LINE__,__FILE__);
  2547. $row=Database::fetch_array($result);
  2548. }
  2549. //show status
  2550. if ($row['ratinglock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index'))
  2551. {
  2552. return false;
  2553. }
  2554. else
  2555. {
  2556. return true;
  2557. }
  2558. }
  2559. /**
  2560. * Notify page changes
  2561. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2562. */
  2563. function check_notify_page($reflink)
  2564. {
  2565. global $tbl_wiki;
  2566. global $groupfilter;
  2567. global $tbl_wiki_mailcue;
  2568. $_clean['group_id']=(int)$_SESSION['_gid'];
  2569. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.' ORDER BY id ASC';
  2570. $result=api_sql_query($sql,__LINE__,__FILE__);
  2571. $row=Database::fetch_array($result);
  2572. $id=$row['id'];
  2573. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"';
  2574. $result=api_sql_query($sql,__LINE__,__FILE__);
  2575. $row=Database::fetch_array($result);
  2576. $idm=$row['id'];
  2577. if (empty($idm))
  2578. {
  2579. $status_notify=0;
  2580. }
  2581. else
  2582. {
  2583. $status_notify=1;
  2584. }
  2585. //change status
  2586. if ($_GET['actionpage']=='notify')
  2587. {
  2588. if ($status_notify==0)
  2589. {
  2590. $sql="INSERT INTO ".$tbl_wiki_mailcue." (id, user_id, type, group_id) VALUES ('".$id."','".api_get_user_id()."','P','".$_clean['group_id']."')";
  2591. api_sql_query($sql,__FILE__,__LINE__);
  2592. $status_notify=1;
  2593. }
  2594. else
  2595. {
  2596. $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"'; //$_clean['group_id'] not necessary
  2597. api_sql_query($sql,__FILE__,__LINE__);
  2598. $status_notify=0;
  2599. }
  2600. }
  2601. //show status
  2602. if ($status_notify==0)
  2603. {
  2604. return false;
  2605. }
  2606. else
  2607. {
  2608. return true;
  2609. }
  2610. }
  2611. /**
  2612. * Notify discussion changes
  2613. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2614. */
  2615. function check_notify_discuss($reflink)
  2616. {
  2617. global $tbl_wiki;
  2618. global $groupfilter;
  2619. global $tbl_wiki_mailcue;
  2620. $_clean['group_id']=(int)$_SESSION['_gid'];
  2621. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.' ORDER BY id ASC';
  2622. $result=api_sql_query($sql,__LINE__,__FILE__);
  2623. $row=Database::fetch_array($result);
  2624. $id=$row['id'];
  2625. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"';
  2626. $result=api_sql_query($sql,__LINE__,__FILE__);
  2627. $row=Database::fetch_array($result);
  2628. $idm=$row['id'];
  2629. if (empty($idm))
  2630. {
  2631. $status_notify_disc=0;
  2632. }
  2633. else
  2634. {
  2635. $status_notify_disc=1;
  2636. }
  2637. //change status
  2638. if ($_GET['actionpage']=='notify_disc')
  2639. {
  2640. if ($status_notify_disc==0)
  2641. {
  2642. if (!$_POST['Submit'])
  2643. {
  2644. $sql="INSERT INTO ".$tbl_wiki_mailcue." (id, user_id, type, group_id) VALUES ('".$id."','".api_get_user_id()."','D','".$_clean['group_id']."')";
  2645. api_sql_query($sql,__FILE__,__LINE__);
  2646. $status_notify_disc=1;
  2647. }
  2648. else
  2649. {
  2650. $status_notify_disc=0;
  2651. }
  2652. }
  2653. else
  2654. {
  2655. if (!$_POST['Submit'])
  2656. {
  2657. $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"'; //$_clean['group_id'] not necessary
  2658. api_sql_query($sql,__FILE__,__LINE__);
  2659. $status_notify_disc=0;
  2660. }
  2661. else
  2662. {
  2663. $status_notify_disc=1;
  2664. }
  2665. }
  2666. }
  2667. //show status
  2668. if ($status_notify_disc==0)
  2669. {
  2670. return false;
  2671. }
  2672. else
  2673. {
  2674. return true;
  2675. }
  2676. }
  2677. /**
  2678. * Notify all changes
  2679. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2680. */
  2681. function check_notify_all()
  2682. {
  2683. global $tbl_wiki_mailcue;
  2684. $_clean['group_id']=(int)$_SESSION['_gid'];
  2685. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'"';
  2686. $result=api_sql_query($sql,__LINE__,__FILE__);
  2687. $row=Database::fetch_array($result);
  2688. $idm=$row['user_id'];
  2689. if (empty($idm))
  2690. {
  2691. $status_notify_all=0;
  2692. }
  2693. else
  2694. {
  2695. $status_notify_all=1;
  2696. }
  2697. //change status
  2698. if ($_GET['actionpage']=='notify_all')
  2699. {
  2700. if ($status_notify_all==0)
  2701. {
  2702. $sql="INSERT INTO ".$tbl_wiki_mailcue." (user_id, type, group_id) VALUES ('".api_get_user_id()."','F','".$_clean['group_id']."')";
  2703. api_sql_query($sql,__FILE__,__LINE__);
  2704. $status_notify_all=1;
  2705. }
  2706. else
  2707. {
  2708. $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'"';
  2709. api_sql_query($sql,__FILE__,__LINE__);
  2710. $status_notify_all=0;
  2711. }
  2712. }
  2713. //show status
  2714. if ($status_notify_all==0)
  2715. {
  2716. return false;
  2717. }
  2718. else
  2719. {
  2720. return true;
  2721. }
  2722. }
  2723. /**
  2724. * Function check emailcue and send email when a page change
  2725. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2726. */
  2727. function check_emailcue($id_or_ref, $type, $lastime='', $lastuser='')
  2728. {
  2729. global $tbl_wiki;
  2730. global $groupfilter;
  2731. global $tbl_wiki_mailcue;
  2732. global $_course;
  2733. $_clean['group_id']=(int)$_SESSION['_gid'];
  2734. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  2735. $group_name= $group_properties['name'];
  2736. $allow_send_mail=false; //define the variable to below
  2737. if ($type=='P')
  2738. {
  2739. //if modifying a wiki page
  2740. //first, current author and time
  2741. //Who is the author?
  2742. $userinfo= Database::get_user_info_from_id($lastuser);
  2743. $email_user_author= get_lang('EditedBy').': '.$userinfo['firstname'].' '.$userinfo['lastname'];
  2744. //When ?
  2745. $year = substr($lastime, 0, 4);
  2746. $month = substr($lastime, 5, 2);
  2747. $day = substr($lastime, 8, 2);
  2748. $hours=substr($lastime, 11,2);
  2749. $minutes=substr($lastime, 14,2);
  2750. $seconds=substr($lastime, 17,2);
  2751. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  2752. //second, extract data from first reg
  2753. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$id_or_ref.'" AND '.$groupfilter.' ORDER BY id ASC'; //id_or_ref is reflink from tblwiki
  2754. $result=api_sql_query($sql,__LINE__,__FILE__);
  2755. $row=Database::fetch_array($result);
  2756. $id=$row['id'];
  2757. $email_page_name=$row['title'];
  2758. if ($row['visibility']==1)
  2759. {
  2760. $allow_send_mail=true; //if visibility off - notify off
  2761. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full.
  2762. $result=api_sql_query($sql,__LINE__,__FILE__);
  2763. $emailtext=get_lang('EmailWikipageModified').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
  2764. }
  2765. }
  2766. elseif ($type=='D')
  2767. {
  2768. //if added a post to discuss
  2769. //first, current author and time
  2770. //Who is the author of last message?
  2771. $userinfo= Database::get_user_info_from_id($lastuser);
  2772. $email_user_author= get_lang('AddedBy').': '.$userinfo['firstname'].' '.$userinfo['lastname'];
  2773. //When ?
  2774. $year = substr($lastime, 0, 4);
  2775. $month = substr($lastime, 5, 2);
  2776. $day = substr($lastime, 8, 2);
  2777. $hours=substr($lastime, 11,2);
  2778. $minutes=substr($lastime, 14,2);
  2779. $seconds=substr($lastime, 17,2);
  2780. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  2781. //second, extract data from first reg
  2782. $id=$id_or_ref; //$id_or_ref is id from tblwiki
  2783. $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.$id.'" ORDER BY id ASC';
  2784. $result=api_sql_query($sql,__LINE__,__FILE__);
  2785. $row=Database::fetch_array($result);
  2786. $email_page_name=$row['title'];
  2787. if ($row['visibility_disc']==1)
  2788. {
  2789. $allow_send_mail=true; //if visibility off - notify off
  2790. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full
  2791. $result=api_sql_query($sql,__LINE__,__FILE__);
  2792. $emailtext=get_lang('EmailWikiPageDiscAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
  2793. }
  2794. }
  2795. elseif($type=='A')
  2796. {
  2797. //for added pages
  2798. $id=0; //for tbl_wiki_mailcue
  2799. $sql='SELECT * FROM '.$tbl_wiki.' ORDER BY id DESC'; //the added is always the last
  2800. $result=api_sql_query($sql,__LINE__,__FILE__);
  2801. $row=Database::fetch_array($result);
  2802. $email_page_name=$row['title'];
  2803. //Who is the author?
  2804. $userinfo= Database::get_user_info_from_id($row['user_id']);
  2805. $email_user_author= get_lang('AddedBy').': '.$userinfo['firstname'].' '.$userinfo['lastname'];
  2806. //When ?
  2807. $year = substr($row['dtime'], 0, 4);
  2808. $month = substr($row['dtime'], 5, 2);
  2809. $day = substr($row['dtime'], 8, 2);
  2810. $hours=substr($row['dtime'], 11,2);
  2811. $minutes=substr($row['dtime'], 14,2);
  2812. $seconds=substr($row['dtime'], 17,2);
  2813. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  2814. if($row['assignment']==0)
  2815. {
  2816. $allow_send_mail=true;
  2817. }
  2818. elseif($row['assignment']==1)
  2819. {
  2820. $email_assignment=get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')';
  2821. $allow_send_mail=true;
  2822. }
  2823. elseif($row['assignment']==2)
  2824. {
  2825. $allow_send_mail=false; //Mode tasks: avoids notifications to all users about all users
  2826. }
  2827. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full
  2828. $result=api_sql_query($sql,__LINE__,__FILE__);
  2829. $emailtext=get_lang('EmailWikiPageAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('In').' '. get_lang('Wiki');
  2830. }
  2831. elseif($type=='E')
  2832. {
  2833. $id=0;
  2834. $allow_send_mail=true;
  2835. //Who is the author?
  2836. $userinfo= Database::get_user_info_from_id(api_get_user_id()); //current user
  2837. $email_user_author= get_lang('DeletedBy').': '.$userinfo['firstname'].' '.$userinfo['lastname'];
  2838. //When ?
  2839. $today = date('r'); //current time
  2840. $email_date_changes=$today;
  2841. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=wiki
  2842. $result=api_sql_query($sql,__LINE__,__FILE__);
  2843. $emailtext=get_lang('EmailWikipageDedeleted');
  2844. }
  2845. ///make and send email
  2846. if ($allow_send_mail)
  2847. {
  2848. while ($row=Database::fetch_array($result))
  2849. {
  2850. if(empty($charset)){$charset='ISO-8859-1';}
  2851. $headers = 'Content-Type: text/html; charset='. $charset;
  2852. $userinfo=Database::get_user_info_from_id($row['user_id']); //$row['user_id'] obtained from tbl_wiki_mailcue
  2853. $name_to=$userinfo['firstname'].' '.$userinfo['lastname'];
  2854. $email_to=$userinfo['email'];
  2855. $sender_name=get_setting('emailAdministrator');
  2856. $sender_email=get_setting('emailAdministrator');
  2857. $email_subject = get_lang('EmailWikiChanges').' - '.$_course['official_code'];
  2858. $email_body= get_lang('DearUser').' '.$userinfo['firstname'].' '.$userinfo['lastname'].',<br /><br />';
  2859. $email_body .= $emailtext.' <strong>'.$_course['name'].' - '.$group_name.'</strong><br /><br /><br />';
  2860. $email_body .= $email_user_author.' ('.$email_date_changes.')<br /><br /><br />';
  2861. $email_body .= $email_assignment.'<br /><br /><br />';
  2862. $email_body .= '<font size="-2">'.get_lang('EmailWikiChangesExt_1').': <strong>'.get_lang('NotifyChanges').'</strong><br />';
  2863. $email_body .= get_lang('EmailWikiChangesExt_2').': <strong>'.get_lang('NotNotifyChanges').'</strong></font><br />';
  2864. api_mail_html($name_to, $email_to, $email_subject, $email_body, $sender_name, $sender_email, $headers);
  2865. }
  2866. }
  2867. }
  2868. /**
  2869. * Function export last wiki page version to document area
  2870. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2871. */
  2872. function export2doc($wikiTitle, $wikiContents, $groupId)
  2873. {
  2874. if ( 0 != $groupId)
  2875. {
  2876. $groupPart = '_group' . $groupId; // and add groupId to put the same title document in different groups
  2877. $group_properties = GroupManager :: get_group_properties($groupId);
  2878. $groupPath = $group_properties['directory'];
  2879. }
  2880. else
  2881. {
  2882. $groupPart = '';
  2883. $groupPath ='';
  2884. }
  2885. $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath;
  2886. $exportFile = replace_dangerous_char(replace_accents($wikiTitle), 'strict' ) . $groupPart;
  2887. $i = 1;
  2888. while ( file_exists($exportDir . '/' .$exportFile.'_'.$i.'.html') ) $i++; //only export last version, but in new export new version in document area
  2889. $wikiFileName = $exportFile . '_' . $i . '.html';
  2890. $exportPath = $exportDir . '/' . $wikiFileName;
  2891. $wikiContents = stripslashes($wikiContents);
  2892. file_put_contents( $exportPath, $wikiContents );
  2893. $doc_id = add_document($_course, $groupPath.'/'.$wikiFileName,'file',filesize($exportPath),$wikiFileName);
  2894. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId);
  2895. // TODO: link to go document area
  2896. }
  2897. /**
  2898. * Function wizard individual assignment
  2899. * @author Juan Carlos Raña <herodoto@telefonica.net>
  2900. */
  2901. function auto_add_page_users($assignment_type)
  2902. {
  2903. global $assig_user_id; //need to identify end reflinks
  2904. $_clean['group_id']=(int)$_SESSION['_gid'];
  2905. if($_clean['group_id']==0)
  2906. {
  2907. //extract course members
  2908. if(!empty($_SESSION["id_session"])){
  2909. $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true, $_SESSION['id_session']);
  2910. }
  2911. else
  2912. {
  2913. $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true);
  2914. }
  2915. }
  2916. else
  2917. {
  2918. //extract group members
  2919. $subscribed_users = GroupManager :: get_subscribed_users($_clean['group_id']);
  2920. $subscribed_tutors = GroupManager :: get_subscribed_tutors($_clean['group_id']);
  2921. $a_users_to_add_with_duplicates=array_merge($subscribed_users, $subscribed_tutors);
  2922. //remove duplicates
  2923. $a_users_to_add = $a_users_to_add_with_duplicates;
  2924. array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_encode($value);'));
  2925. $a_users_to_add = array_unique($a_users_to_add);
  2926. array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_decode($value, true);'));
  2927. }
  2928. $all_students_pages = array();
  2929. //data about teacher
  2930. $userinfo=Database::get_user_info_from_id(api_get_user_id());
  2931. require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php');
  2932. if (api_get_user_id()<>0)
  2933. {
  2934. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',false, true);
  2935. $image_repository = $image_path['dir'];
  2936. $existing_image = $image_path['file'];
  2937. $photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  2938. }
  2939. else
  2940. {
  2941. $photo= '<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  2942. }
  2943. //teacher assignment title
  2944. $title_orig=$_POST['title'];
  2945. //teacher assignment reflink
  2946. $link2teacher=$_POST['title']= $title_orig."_uass".api_get_user_id();
  2947. //first: teacher name, photo, and assignment description (original content)
  2948. $content_orig_A='<div align="center" style="font-size:24px; background-color: #F5F8FB; border:double">'.$photo.get_lang('Teacher').': '.$userinfo['firstname'].$userinfo['lastname'].'</div><br/><div>';
  2949. $content_orig_B='<h1>'.get_lang('AssignmentDescription').'</h1></div><br/>'.$_POST['content'];
  2950. //Second: student list (names, photo and links to their works).
  2951. //Third: Create Students work pages.
  2952. foreach($a_users_to_add as $user_id=>$o_user_to_add)
  2953. {
  2954. if($o_user_to_add['user_id'] != api_get_user_id()) //except that puts the task
  2955. {
  2956. $assig_user_id= $o_user_to_add['user_id']; //identifies each page as created by the student, not by teacher
  2957. $image_path = UserManager::get_user_picture_path_by_id($assig_user_id,'web',false, true);
  2958. $image_repository = $image_path['dir'];
  2959. $existing_image = $image_path['file'];
  2960. $name= $o_user_to_add['lastname'].', '.$o_user_to_add['firstname'];
  2961. $photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />';
  2962. $is_tutor_of_group = GroupManager :: is_tutor_of_group($assig_user_id,$_clean['group_id']); //student is tutor
  2963. $is_tutor_and_member = (GroupManager :: is_tutor_of_group($assig_user_id,$_clean['group_id']) && GroupManager :: is_subscribed($assig_user_id, $_clean['group_id'])); //student is tutor and member
  2964. if($is_tutor_and_member)
  2965. {
  2966. $status_in_group=get_lang('GroupTutorAndMember');
  2967. }
  2968. else
  2969. {
  2970. if($is_tutor_of_group)
  2971. {
  2972. $status_in_group=get_lang('GroupTutor');
  2973. }
  2974. else
  2975. {
  2976. $status_in_group=" "; //get_lang('GroupStandardMember')
  2977. }
  2978. }
  2979. if($assignment_type==1)
  2980. {
  2981. $_POST['title']= $title_orig;
  2982. $_POST['comment']=get_lang('AssignmentFirstComToStudent');
  2983. $_POST['content']='<div align="center" style="font-size:24px; background-color: #F5F8FB; border:double">'.$photo.get_lang('Student').': '.$name.'</div>[['.$link2teacher.' | '.get_lang('AssignmentLinktoTeacherPage').']] '; //If $content_orig_B is added here, the task written by the professor was copied to the page of each student. TODO: config options
  2984. //AssignmentLinktoTeacherPage
  2985. $all_students_pages[] = '<li>'.$o_user_to_add['lastname'].', '.$o_user_to_add['firstname'].' [['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>';
  2986. $_POST['assignment']=2;
  2987. }
  2988. save_new_wiki();
  2989. }
  2990. }//end foreach for each user
  2991. foreach($a_users_to_add as $user_id=>$o_user_to_add)
  2992. {
  2993. if($o_user_to_add['user_id'] == api_get_user_id())
  2994. {
  2995. $assig_user_id=$o_user_to_add['user_id'];
  2996. if($assignment_type==1)
  2997. {
  2998. $_POST['title']= $title_orig;
  2999. $_POST['comment']=get_lang('AssignmentDesc');
  3000. sort($all_students_pages);
  3001. $_POST['content']=$content_orig_A.$content_orig_B.'<br/><div align="center" style="font-size:24px; background-color: #F5F8FB; border:double">'.get_lang('AssignmentLinkstoStudentsPage').'<br/><strong>'.$title_orig.'</strong></div><div style="background-color: #F5F8FB; border:double"><ol>'.implode($all_students_pages).'</ol></div><br/>';
  3002. $_POST['assignment']=1;
  3003. }
  3004. save_new_wiki();
  3005. }
  3006. } //end foreach to teacher
  3007. }
  3008. function display_wiki_search_results($search_term, $search_content=0)
  3009. {
  3010. global $tbl_wiki, $groupfilter, $MonthsLong;
  3011. echo '<div class="row"><div class="form_header">'.get_lang('WikiSearchResults').'</div></div>';
  3012. $_clean['group_id']=(int)$_SESSION['_gid'];
  3013. if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
  3014. {
  3015. if($search_content=='1')
  3016. {
  3017. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
  3018. }
  3019. else
  3020. {
  3021. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND title LIKE '%".Database::escape_string($search_term)."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
  3022. }
  3023. }
  3024. else
  3025. {
  3026. if($search_content=='1')
  3027. {
  3028. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
  3029. }
  3030. else
  3031. {
  3032. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
  3033. }
  3034. }
  3035. $result=api_sql_query($sql,__LINE__,__FILE__);
  3036. //show table
  3037. if (mysql_num_rows($result) > 0)
  3038. {
  3039. $row = array ();
  3040. while ($obj = mysql_fetch_object($result))
  3041. {
  3042. //get author
  3043. $userinfo=Database::get_user_info_from_id($obj->user_id);
  3044. //get time
  3045. $year = substr($obj->dtime, 0, 4);
  3046. $month = substr($obj->dtime, 5, 2);
  3047. $day = substr($obj->dtime, 8, 2);
  3048. $hours = substr($obj->dtime, 11,2);
  3049. $minutes = substr($obj->dtime, 14,2);
  3050. $seconds = substr($obj->dtime, 17,2);
  3051. //get type assignment icon
  3052. if($obj->assignment==1)
  3053. {
  3054. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  3055. }
  3056. elseif ($obj->assignment==2)
  3057. {
  3058. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  3059. }
  3060. elseif ($obj->assignment==0)
  3061. {
  3062. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  3063. }
  3064. $row = array ();
  3065. $row[] =$ShowAssignment;
  3066. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
  3067. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  3068. $row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
  3069. $rows[] = $row;
  3070. }
  3071. $table = new SortableTableFromArrayConfig($rows,1,10,'SearchPages_table','','','ASC');
  3072. $table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id'])));
  3073. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  3074. $table->set_header(1,get_lang('Title'), true);
  3075. $table->set_header(2,get_lang('Author'), true);
  3076. $table->set_header(3,get_lang('Date'), true);
  3077. $table->display();
  3078. }
  3079. else
  3080. {
  3081. echo get_lang('NoSearchResults');
  3082. }
  3083. }
  3084. ?>