index.php 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  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. $_SESSION['id_session'] = intval($_GET['id_session']);
  33. }
  34. // including the global dokeos file
  35. require_once '../inc/global.inc.php';
  36. // section (for the tabs)
  37. $this_section=SECTION_COURSES;
  38. // including additional library scripts
  39. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  40. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  41. require_once api_get_path(LIBRARY_PATH).'text.lib.php';
  42. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  43. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  44. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  45. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  46. require_once 'wiki.inc.php';
  47. // additional style information
  48. $htmlHeadXtra[] ='<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'wiki/css/default.css"/>';
  49. // javascript for advanced parameters menu
  50. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  51. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  52. function advanced_parameters() {
  53. if(document.getElementById(\'options\').style.display == \'none\') {
  54. document.getElementById(\'options\').style.display = \'block\';
  55. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  56. } else {
  57. document.getElementById(\'options\').style.display = \'none\';
  58. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  59. }
  60. }
  61. function setFocus(){
  62. $("#search_title").focus();
  63. }
  64. $(document).ready(function () {
  65. setFocus();
  66. });
  67. </script>';
  68. // Database table definition
  69. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  70. $tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS);
  71. $tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE);
  72. $tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
  73. /*
  74. -----------------------------------------------------------
  75. Constants and variables
  76. -----------------------------------------------------------
  77. */
  78. $tool_name = get_lang('ToolWiki');
  79. $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"));
  80. //condition for the session
  81. $session_id = api_get_session_id();
  82. $condition_session = api_get_session_condition($session_id);
  83. /*
  84. ----------------------------------------------------------
  85. ACCESS
  86. -----------------------------------------------------------
  87. */
  88. api_protect_course_script();
  89. api_block_anonymous_users();
  90. /*
  91. -----------------------------------------------------------
  92. TRACKING
  93. -----------------------------------------------------------
  94. */
  95. event_access_tool(TOOL_WIKI);
  96. /*
  97. -----------------------------------------------------------
  98. HEADER & TITLE
  99. -----------------------------------------------------------
  100. */
  101. // If it is a group wiki then the breadcrumbs will be different.
  102. if ($_SESSION['_gid'] OR $_GET['group_id']) {
  103. if (isset($_SESSION['_gid'])) {
  104. $_clean['group_id']=(int)$_SESSION['_gid'];
  105. }
  106. if (isset($_GET['group_id'])) {
  107. $_clean['group_id']=(int)Database::escape_string($_GET['group_id']);
  108. }
  109. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  110. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  111. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  112. $add_group_to_title = ' ('.$group_properties['name'].')';
  113. $groupfilter='group_id="'.$_clean['group_id'].'"';
  114. //ensure this tool in groups whe it's private or deactivated
  115. if ($group_properties['wiki_state']==0)
  116. {
  117. echo api_not_allowed();
  118. }
  119. elseif ($group_properties['wiki_state']==2)
  120. {
  121. if (!api_is_allowed_to_edit(false,true) and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid']))
  122. {
  123. echo api_not_allowed();
  124. }
  125. }
  126. }
  127. else
  128. {
  129. $groupfilter='group_id=0';
  130. }
  131. Display::display_header($tool_name, 'Wiki');
  132. $is_allowed_to_edit = api_is_allowed_to_edit(false,true);
  133. //api_display_tool_title($tool_name.$add_group_to_title);
  134. /*
  135. -----------------------------------------------------------
  136. INITIALISATION
  137. -----------------------------------------------------------
  138. */
  139. //the page we are dealing with
  140. if (!isset($_GET['title'])){
  141. $page='index';
  142. }
  143. else
  144. {
  145. $page=Security::remove_XSS($_GET['title']);
  146. }
  147. // some titles are not allowed
  148. // $not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now
  149. /*
  150. ==============================================================================
  151. MAIN CODE
  152. ==============================================================================
  153. */
  154. // Tool introduction
  155. Display::display_introduction_section(TOOL_WIKI);
  156. /*
  157. -----------------------------------------------------------
  158. ACTIONS
  159. -----------------------------------------------------------
  160. */
  161. //release of blocked pages to prevent concurrent editions
  162. $sql='SELECT * FROM '.$tbl_wiki.'WHERE is_editing!="0" '.$condition_session;
  163. $result=Database::query($sql);
  164. while ($is_editing_block=Database::fetch_array($result))
  165. {
  166. $max_edit_time=1200; // 20 minutes
  167. $timestamp_edit=strtotime($is_editing_block['time_edit']);
  168. $time_editing=time()-$timestamp_edit;
  169. //first prevent concurrent users and double version
  170. if($is_editing_block['is_editing']==$_user['user_id'])
  171. {
  172. $_SESSION['_version']=$is_editing_block['version'];
  173. }
  174. else
  175. {
  176. unset ( $_SESSION['_version'] );
  177. }
  178. //second checks if has exceeded the time that a page may be available or if a page was edited and saved by its author
  179. if ($time_editing>$max_edit_time || ($is_editing_block['is_editing']==$_user['user_id'] && $_GET['action']!='edit'))
  180. {
  181. $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" WHERE is_editing="'.$is_editing_block['is_editing'].'" '.$condition_session;
  182. Database::query($sql);
  183. }
  184. }
  185. // saving a change
  186. if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'')
  187. {
  188. if(empty($_POST['title']))
  189. {
  190. Display::display_error_message(get_lang("NoWikiPageTitle"));
  191. }
  192. elseif(!double_post($_POST['wpost_id']))
  193. {
  194. //double post
  195. }
  196. elseif ($_POST['version']!='' && $_SESSION['_version']!=0 && $_POST['version']!=$_SESSION['_version'])
  197. {
  198. //prevent concurrent users and double version
  199. Display::display_error_message(get_lang("EditedByAnotherUser"));
  200. }
  201. else
  202. {
  203. $return_message=save_wiki();
  204. Display::display_confirmation_message($return_message, false);
  205. }
  206. }
  207. //saving a new wiki entry
  208. if (isset($_POST['SaveWikiNew']))
  209. {
  210. if(empty($_POST['title']))
  211. {
  212. Display::display_error_message(get_lang("NoWikiPageTitle"));
  213. }
  214. elseif (strtotime(get_date_from_select('startdate_assig')) > strtotime(get_date_from_select('enddate_assig')))
  215. {
  216. Display::display_error_message(get_lang("EndDateCannotBeBeforeTheStartDate"));
  217. }
  218. elseif(!double_post($_POST['wpost_id']))
  219. {
  220. //double post
  221. }
  222. else
  223. {
  224. $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment
  225. if ($_clean['assignment']==1)
  226. {
  227. auto_add_page_users($_clean['assignment']);
  228. }
  229. else
  230. {
  231. $return_message=save_new_wiki();
  232. Display::display_confirmation_message($return_message, false);
  233. $page=urlencode(Security::remove_XSS($_POST['reflink']));
  234. }
  235. }
  236. }
  237. // check last version
  238. if ($_GET['view'])
  239. {
  240. $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.Database::escape_string($_GET['view']).'"'; //current view
  241. $result=Database::query($sql);
  242. $current_row=Database::fetch_array($result);
  243. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; //last version
  244. $result=Database::query($sql);
  245. $last_row=Database::fetch_array($result);
  246. if ($_GET['view']<$last_row['id'])
  247. {
  248. $message= '<center>'.get_lang('NoAreSeeingTheLastVersion').'<br /> '.get_lang("Version").' (<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>) <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></center>';
  249. Display::display_warning_message($message,false);
  250. }
  251. ///restore page
  252. if ($_GET['action']=='restorepage')
  253. {
  254. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher
  255. if(($current_row['reflink']=='index' || $current_row['reflink']=='' || $current_row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && $_clean['group_id']==0))
  256. {
  257. Display::display_normal_message(get_lang('OnlyEditPagesCourseManager'));
  258. }
  259. else
  260. {
  261. $PassEdit=false;
  262. //check if is a wiki group
  263. if($current_row['group_id']!=0)
  264. {
  265. //Only teacher, platform admin and group members can edit a wiki group
  266. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
  267. {
  268. $PassEdit=true;
  269. }
  270. else
  271. {
  272. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  273. }
  274. }
  275. else
  276. {
  277. $PassEdit=true;
  278. }
  279. // check if is an assignment
  280. if(stripslashes($current_row['assignment'])==1)
  281. {
  282. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  283. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  284. }
  285. elseif(stripslashes($current_row['assignment'])==2)
  286. {
  287. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  288. if((api_get_user_id()==$current_row['user_id'])==false)
  289. {
  290. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  291. {
  292. $PassEdit=true;
  293. }
  294. else
  295. {
  296. Display::display_warning_message(get_lang('LockByTeacher'));
  297. $PassEdit=false;
  298. }
  299. }
  300. else
  301. {
  302. $PassEdit=true;
  303. }
  304. }
  305. if($PassEdit) //show editor if edit is allowed
  306. {
  307. if ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false))
  308. {
  309. Display::display_normal_message(get_lang('PageLockedExtra'));
  310. }
  311. else
  312. {
  313. if($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id'])
  314. {
  315. //checking for concurrent users
  316. $timestamp_edit=strtotime($last_row['time_edit']);
  317. $time_editing=time()-$timestamp_edit;
  318. $max_edit_time=1200; // 20 minutes
  319. $rest_time=$max_edit_time-$time_editing;
  320. $userinfo=Database::get_user_info_from_id($last_row['is_editing']);
  321. $is_being_edited= get_lang('ThisPageisBeginEditedBy').' <a href=../user/userInfo.php?uInfo='.$userinfo['user_id'].'>'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
  322. Display::display_normal_message($is_being_edited, false);
  323. }
  324. else
  325. {
  326. Display::display_confirmation_message(restore_wikipage($current_row['page_id'], $current_row['reflink'], $current_row['title'], $current_row['content'], $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': <a href="index.php?cidReq='.$_course[id].'&action=showpage&amp;title='.$last_row['reflink'].'&group_id='.$last_row['group_id'].'">'.$last_row['title'].'</a>',false);
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. if ($_GET['action']=='deletewiki'){
  334. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  335. {
  336. if ($_GET['delete'] == 'yes')
  337. {
  338. $return_message=delete_wiki();
  339. Display::display_confirmation_message($return_message);
  340. }
  341. }
  342. }
  343. if ($_GET['action']=='discuss' && $_POST['Submit'])
  344. {
  345. Display::display_confirmation_message(get_lang('CommentAdded'));
  346. }
  347. /*
  348. -----------------------------------------------------------
  349. WIKI WRAPPER
  350. -----------------------------------------------------------
  351. */
  352. echo "<div id='wikiwrapper'>";
  353. /** Actions bar (= action of the wiki tool, not of the page)**/
  354. echo '<div id="menuwiki">';
  355. echo '<table width="210">';
  356. echo '<tr>';
  357. echo '<td>';
  358. echo get_lang('Menu');
  359. echo '</td>';
  360. echo '</tr>';
  361. echo '<tr>';
  362. echo '<td>';
  363. ///menu home
  364. 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>';
  365. if ( api_is_allowed_to_session_edit(false,true) ) {
  366. //menu add page
  367. 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> ';
  368. }
  369. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  370. {
  371. // page action: enable or disable the adding of new pages
  372. if (check_addnewpagelock()==0)
  373. {
  374. $protect_addnewpage= '<img src="../img/wiki/lockadd.gif" title="'.get_lang('AddOptionProtected').'" alt="'.get_lang('AddOptionProtected').'" width="8" height="8" />';
  375. $lock_unlock_addnew='unlockaddnew';
  376. }
  377. else
  378. {
  379. $protect_addnewpage= '<img src="../img/wiki/unlockadd.gif" title="'.get_lang('AddOptionUnprotected').'" alt="'.get_lang('AddOptionUnprotected').'" width="8" height="8" />';
  380. $lock_unlock_addnew='lockaddnew';
  381. }
  382. }
  383. echo '<a href="index.php?action=show&amp;actionpage='.$lock_unlock_addnew.'&amp;title='.$page.'">'.$protect_addnewpage.'</a></li>';
  384. ///menu find
  385. 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>';
  386. ///menu all pages
  387. 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>';
  388. ///menu recent changes
  389. 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>';
  390. ///menu delete all wiki
  391. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  392. {
  393. echo '<li><a href="index.php?action=deletewiki&amp;title='.$page.'"'.is_active_navigation_tab('deletewiki').'>'.get_lang('DeleteWiki').'</a></li>';
  394. }
  395. ///menu more
  396. echo '<li><a href="index.php?action=more&amp;title='.$page.'"'.is_active_navigation_tab('more').'>'.get_lang('More').'</a></li>';
  397. echo '</ul>';
  398. echo '</td>';
  399. echo '</tr>';
  400. echo '</table>';
  401. echo '</div>';
  402. /*
  403. -----------------------------------------------------------
  404. MAIN WIKI AREA
  405. -----------------------------------------------------------
  406. */
  407. echo "<div id='mainwiki'>";
  408. /** menuwiki (= actions of the page, not of the wiki tool) **/
  409. if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted')))
  410. {
  411. echo "<div class='actions'>";
  412. //menu show page
  413. 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>';
  414. if (api_is_allowed_to_session_edit(false,true) ) {
  415. //menu edit page
  416. 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>';
  417. //menu discuss page
  418. 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>';
  419. }
  420. //menu history
  421. 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>';
  422. //menu linkspages
  423. 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>';
  424. //menu delete wikipage
  425. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  426. {
  427. 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>';
  428. }
  429. echo '</div>';
  430. }
  431. /////////////////////// more options /////////////////////// Juan Carlos Raña Trabado
  432. //more for export to course document area. See display_wiki_entry
  433. if ($_POST['export2DOC'])
  434. {
  435. $titleDOC=$_POST['titleDOC'];
  436. $contentDOC=$_POST['contentDOC'];
  437. $groupIdDOC=(int)$_SESSION['_gid'];
  438. $export2doc = export2doc($titleDOC,$contentDOC,$groupIdDOC);
  439. if ($export2doc) {
  440. Display::display_normal_message(get_lang('ThePageHasBeenExportedToDocArea'));
  441. }
  442. }
  443. if ($_GET['action']=='more')
  444. {
  445. echo '<div class="actions">'.get_lang('More').'</div>';
  446. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  447. {
  448. //TODO: config area and private stats
  449. }
  450. echo '<table border="0">';
  451. echo '<tr>';
  452. echo '<td>';
  453. echo '<ul>';
  454. //Submenu Most active users
  455. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mactiveusers&group_id='.$_clean['group_id'].'">'.get_lang('MostActiveUsers').'</a></li>';
  456. //Submenu Most visited pages
  457. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mvisited&group_id='.$_clean['group_id'].'">'.get_lang('MostVisitedPages').'</a></li>';
  458. //Submenu Most changed pages
  459. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mostchanged&group_id='.$_clean['group_id'].'">'.get_lang('MostChangedPages').'</a></li>';
  460. echo '</ul>';
  461. echo '</td>';
  462. echo '<td>';
  463. echo '<ul>';
  464. //Submenu Orphaned pages
  465. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=orphaned&group_id='.$_clean['group_id'].'">'.get_lang('OrphanedPages').'</a></li>';
  466. //Submenu Wanted pages
  467. echo '<li><a href="index.php?cidReq='.$_course[id].'&action=wanted&group_id='.$_clean['group_id'].'">'.get_lang('WantedPages').'</a></li>';
  468. echo '</ul>';
  469. echo'</td>';
  470. echo '</tr>';
  471. echo '</table>';
  472. //Submenu Most linked pages
  473. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mostlinked&group_id='.$_clean['group_id'].'">'.get_lang('MostLinkedPages').'</a></li>';//TODO:
  474. //Submenu Dead end pages
  475. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=deadend&group_id='.$_clean['group_id'].'">'.get_lang('DeadEndPages').'</a></li>';//TODO:
  476. //Submenu Most new pages (not versions)
  477. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mnew&group_id='.$_clean['group_id'].'">'.get_lang('MostNewPages').'</a></li>';//TODO:
  478. //Submenu Most long pages
  479. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mnew&group_id='.$_clean['group_id'].'">'.get_lang('MostLongPages').'</a></li>';//TODO:
  480. //Submenu Protected pages
  481. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=protected&group_id='.$_clean['group_id'].'">'.get_lang('ProtectedPages').'</a></li>';//TODO:
  482. //Submenu Hidden pages
  483. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=hidden&group_id='.$_clean['group_id'].'">'.get_lang('HiddenPages').'</a></li>';//TODO:
  484. //Submenu Most discuss pages
  485. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mdiscuss&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussPages').'</a></li>';//TODO:
  486. //Submenu Best scored pages
  487. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mscored&group_id='.$_clean['group_id'].'">'.get_lang('BestScoredPages').'</a></li>';//TODO:
  488. //Submenu Pages with more progress
  489. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mprogress&group_id='.$_clean['group_id'].'">'.get_lang('MProgressPages').'</a></li>';//TODO:
  490. //Submenu Most active users in discuss
  491. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mactiveusers&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussUsers').'</a></li>';//TODO:
  492. //Submenu Random page
  493. //echo '<li><a href="index.php?cidReq='.$_course[id].'&action=mrandom&group_id='.$_clean['group_id'].'">'.get_lang('RandomPage').'</a></li>';//TODO:
  494. }
  495. /////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado
  496. if ($_GET['action']=='mactiveusers')
  497. {
  498. echo '<div class="actions">'.get_lang('MostActiveUsers').'</div>';
  499. $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' GROUP BY user_id';
  500. $allpages=Database::query($sql);
  501. //show table
  502. if (Database::num_rows($allpages) > 0)
  503. {
  504. $row = array ();
  505. while ($obj = Database::fetch_object($allpages))
  506. {
  507. $userinfo=Database::get_user_info_from_id($obj->user_id);
  508. $row = array ();
  509. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</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.')';
  510. $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>';
  511. $rows[] = $row;
  512. }
  513. $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC');
  514. $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'])));
  515. $table->set_header(0,get_lang('Author'), true, array ('style' => 'width:30px;'));
  516. $table->set_header(1,get_lang('Contributions'), true);
  517. $table->display();
  518. }
  519. }
  520. /////////////////////// User contributions /////////////////////// Juan Carlos Raña Trabado
  521. if ($_GET['action']=='usercontrib')
  522. {
  523. $userinfo=Database::get_user_info_from_id(Security::remove_XSS($_GET['user_id']));
  524. echo '<div class="actions">'.get_lang('UserContributions').': <a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</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>';
  525. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  526. {
  527. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'"';
  528. }
  529. else
  530. {
  531. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'" AND visibility=1';
  532. }
  533. $allpages=Database::query($sql);
  534. //show table
  535. if (Database::num_rows($allpages) > 0)
  536. {
  537. $row = array ();
  538. while ($obj = Database::fetch_object($allpages))
  539. {
  540. //get author
  541. $userinfo=Database::get_user_info_from_id($obj->user_id);
  542. //get time
  543. $year = substr($obj->dtime, 0, 4);
  544. $month = substr($obj->dtime, 5, 2);
  545. $day = substr($obj->dtime, 8, 2);
  546. $hours = substr($obj->dtime, 11,2);
  547. $minutes = substr($obj->dtime, 14,2);
  548. $seconds = substr($obj->dtime, 17,2);
  549. //get type assignment icon
  550. if($obj->assignment==1)
  551. {
  552. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  553. }
  554. elseif ($obj->assignment==2)
  555. {
  556. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  557. }
  558. elseif ($obj->assignment==0)
  559. {
  560. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  561. }
  562. $row = array ();
  563. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  564. $row[] =$ShowAssignment;
  565. $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>';
  566. $row[] =$obj->version;
  567. $row[] =$obj->comment;
  568. //$row[] = api_strlen($obj->comment)>30 ? api_substr($obj->comment,0,30).'...' : $obj->comment;
  569. $row[] =$obj->progress.' %';
  570. $row[] =$obj->score;
  571. //if(api_is_allowed_to_edit() || api_is_platform_admin())
  572. //{
  573. //$row[] =$obj->user_ip;
  574. //}
  575. $rows[] = $row;
  576. }
  577. $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC');
  578. $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'])));
  579. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  580. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  581. $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;'));
  582. $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;'));
  583. $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;'));
  584. $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;'));
  585. $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;'));
  586. //if(api_is_allowed_to_edit() || api_is_platform_admin())
  587. //{
  588. //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;'));
  589. //}
  590. $table->display();
  591. }
  592. }
  593. /////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado
  594. if ($_GET['action']=='mostchanged')
  595. {
  596. echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
  597. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  598. {
  599. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' GROUP BY reflink';
  600. }
  601. else
  602. {
  603. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND visibility=1 GROUP BY reflink';
  604. }
  605. $allpages=Database::query($sql);
  606. //show table
  607. if (Database::num_rows($allpages) > 0)
  608. {
  609. $row = array ();
  610. while ($obj = Database::fetch_object($allpages))
  611. {
  612. //get type assignment icon
  613. if($obj->assignment==1)
  614. {
  615. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  616. }
  617. elseif ($obj->assignment==2)
  618. {
  619. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentWork').'" />';
  620. }
  621. elseif ($obj->assignment==0)
  622. {
  623. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  624. }
  625. $row = array ();
  626. $row[] =$ShowAssignment;
  627. $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>';
  628. $row[] = $obj->MAX;
  629. $rows[] = $row;
  630. }
  631. $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC');
  632. $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'])));
  633. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  634. $table->set_header(1,get_lang('Title'), true);
  635. $table->set_header(2,get_lang('Changes'), true);
  636. $table->display();
  637. }
  638. }
  639. /////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado
  640. if ($_GET['action']=='mvisited')
  641. {
  642. echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
  643. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  644. {
  645. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' GROUP BY reflink';
  646. }
  647. else
  648. {
  649. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND visibility=1 GROUP BY reflink';
  650. }
  651. $allpages=Database::query($sql);
  652. //show table
  653. if (Database::num_rows($allpages) > 0)
  654. {
  655. $row = array ();
  656. while ($obj = Database::fetch_object($allpages))
  657. {
  658. //get type assignment icon
  659. if($obj->assignment==1)
  660. {
  661. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  662. }
  663. elseif ($obj->assignment==2)
  664. {
  665. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  666. }
  667. elseif ($obj->assignment==0)
  668. {
  669. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  670. }
  671. $row = array ();
  672. $row[] =$ShowAssignment;
  673. $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>';
  674. $row[] = $obj->tsum;
  675. $rows[] = $row;
  676. }
  677. $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC');
  678. $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'])));
  679. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  680. $table->set_header(1,get_lang('Title'), true);
  681. $table->set_header(2,get_lang('Visits'), true);
  682. $table->display();
  683. }
  684. }
  685. /////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado
  686. if ($_GET['action']=='wanted')
  687. {
  688. echo '<div class="actions">'.get_lang('WantedPages').'</div>';
  689. $pages = array();
  690. $refs = array();
  691. $sort_wanted=array();
  692. //get name pages
  693. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' GROUP BY reflink ORDER BY reflink ASC';
  694. $allpages=Database::query($sql);
  695. while ($row=Database::fetch_array($allpages))
  696. {
  697. $pages[] = $row['reflink'];
  698. }
  699. //get name refs in last pages and make a unique list
  700. //$sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; //old version TODO: Replace by the bottom line
  701. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE visibility=1 AND '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session; // new version
  702. $allpages=Database::query($sql);
  703. while ($row=Database::fetch_array($allpages))
  704. {
  705. //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO: check
  706. $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " "
  707. $refs = array_merge($refs, $rf);
  708. if ($n++ > 299)
  709. {
  710. $refs = array_unique($refs);
  711. $n=0;
  712. } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
  713. }
  714. //sort linksto. Find linksto into reflink. If not found ->page is wanted
  715. natcasesort($refs);
  716. echo '<ul>';
  717. foreach($refs as $v)
  718. {
  719. if(!in_array($v, $pages))
  720. {
  721. if (trim($v)!="")
  722. {
  723. 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>';
  724. }
  725. }
  726. }
  727. echo '</ul>';
  728. }
  729. /////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado
  730. if ($_GET['action']=='orphaned')
  731. {
  732. echo '<div class="actions">'.get_lang('OrphanedPages').'</div>';
  733. $pages = array();
  734. $refs = array();
  735. $orphaned = array();
  736. //get name pages
  737. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' GROUP BY reflink ORDER BY reflink ASC';
  738. $allpages=Database::query($sql);
  739. while ($row=Database::fetch_array($allpages))
  740. {
  741. $pages[] = $row['reflink'];
  742. }
  743. //get name refs in last pages and make a unique list
  744. //$sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; //old version TODO: Replace by the bottom line
  745. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' '; // new version
  746. $allpages=Database::query($sql);
  747. while ($row=Database::fetch_array($allpages))
  748. {
  749. //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO: check
  750. $rf = explode(" ", trim($row["linksto"])); //fix replace explode("\n", trim($row["linksto"])) with explode(" ", trim($row["linksto"]))
  751. $refs = array_merge($refs, $rf);
  752. if ($n++ > 299)
  753. {
  754. $refs = array_unique($refs);
  755. $n=0;
  756. } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
  757. }
  758. //search each name of list linksto into list reflink
  759. foreach($pages as $v)
  760. {
  761. if(!in_array($v, $refs))
  762. {
  763. $orphaned[] = $v;
  764. }
  765. }
  766. //change reflink by title
  767. foreach($orphaned as $vshow)
  768. {
  769. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  770. {
  771. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND reflink="'.$vshow.'" GROUP BY reflink';
  772. }
  773. else
  774. {
  775. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND reflink="'.$vshow.'" AND visibility=1 GROUP BY reflink';
  776. }
  777. $allpages=Database::query($sql);
  778. echo '<ul>';
  779. while ($row=Database::fetch_array($allpages))
  780. {
  781. //fix assignment icon
  782. if($row['assignment']==1)
  783. {
  784. $ShowAssignment='<img src="../img/wiki/assignment.gif" />';
  785. }
  786. elseif ($row['assignment']==2)
  787. {
  788. $ShowAssignment='<img src="../img/wiki/works.gif" />';
  789. }
  790. elseif ($row['assignment']==0)
  791. {
  792. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  793. }
  794. 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>';
  795. }
  796. echo '</ul>';
  797. }
  798. }
  799. /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado
  800. if ($_GET['action']=='delete')
  801. {
  802. if(!$_GET['title'])
  803. {
  804. Display::display_error_message(get_lang('MustSelectPage'));
  805. exit;
  806. }
  807. echo '<div style="overflow:hidden">';
  808. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  809. {
  810. echo '<div id="wikititle">'.get_lang('DeletePageHistory').'</div>';
  811. if($page=="index")
  812. {
  813. Display::display_warning_message(get_lang('WarningDeleteMainPage'),false);
  814. }
  815. $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>";
  816. if (!isset ($_GET['delete']))
  817. {
  818. Display::display_warning_message($message,false);
  819. }
  820. if ($_GET['delete'] == 'yes')
  821. {
  822. $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';
  823. Database::query($sql);
  824. $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';
  825. Database::query($sql);
  826. $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.'';
  827. Database::query($sql);
  828. check_emailcue(0, 'E');
  829. Display::display_confirmation_message(get_lang('WikiPageDeleted'));
  830. }
  831. }
  832. else
  833. {
  834. Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki"));
  835. }
  836. echo '</div>';
  837. }
  838. /////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado
  839. if ($_GET['action']=='deletewiki')
  840. {
  841. echo '<div class="actions">'.get_lang('DeleteWiki').'</div>';
  842. echo '<div style="overflow:hidden">';
  843. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  844. {
  845. $message = get_lang('ConfirmDeleteWiki');
  846. $message .= '<p>
  847. <a href="index.php">'.get_lang('No').'</a>
  848. &nbsp;&nbsp;|&nbsp;&nbsp;
  849. <a href="'.api_get_self().'?action=deletewiki&amp;delete=yes">'.get_lang('Yes').'</a>
  850. </p>';
  851. if (!isset($_GET['delete']))
  852. {
  853. Display::display_warning_message($message,false);
  854. }
  855. }
  856. else
  857. {
  858. Display::display_normal_message(get_lang("OnlyAdminDeleteWiki"));
  859. }
  860. echo '</div>';
  861. }
  862. /////////////////////// search wiki pages ///////////////////////
  863. if ($_GET['action']=='searchpages')
  864. {
  865. echo '<div class="actions">'.get_lang('SearchPages').'</div>';
  866. echo '<div style="overflow:hidden">';
  867. // initiate the object
  868. $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']));
  869. // settting the form elements
  870. $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles" id="search_title"');
  871. $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent'));
  872. $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"');
  873. // setting the rules
  874. $form->addRule('search_term', '<span class="required">'.get_lang('ThisFieldIsRequired').'</span>', 'required');
  875. $form->addRule('search_term', get_lang('TooShort'),'minlength',3);
  876. if ($form->validate())
  877. {
  878. $form->display();
  879. $values = $form->exportValues();
  880. display_wiki_search_results($values['search_term'], $values['search_content']);
  881. }
  882. else
  883. {
  884. $form->display();
  885. }
  886. echo '</div>';
  887. }
  888. /////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado
  889. if ($_GET['action']=='links')
  890. {
  891. if (!$_GET['title'])
  892. {
  893. Display::display_error_message(get_lang("MustSelectPage"));
  894. }
  895. else
  896. {
  897. $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.'';
  898. $result=Database::query($sql);
  899. $row=Database::fetch_array($result);
  900. //get type assignment icon
  901. if($row['assignment']==1)
  902. {
  903. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  904. }
  905. elseif ($row['assignment']==2)
  906. {
  907. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  908. }
  909. elseif ($row['assignment']==0)
  910. {
  911. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  912. }
  913. //fix Title to reflink (link Main Page)
  914. if ($page==get_lang('DefaultTitle'))
  915. {
  916. $page='index';
  917. }
  918. echo '<div id="wikititle">';
  919. echo get_lang('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>';
  920. echo '</div>';
  921. //fix index to title Main page into linksto
  922. if ($page=='index')
  923. {
  924. $page=str_replace(' ','_',get_lang('DefaultTitle'));
  925. }
  926. //table
  927. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  928. {
  929. //$sql="SELECT * FROM ".$tbl_wiki." s1 WHERE 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 AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word. //Old version TODO: Replace by the bottom line
  930. $sql="SELECT * FROM ".$tbl_wiki.", ".$tbl_wiki_conf." WHERE linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND ".$tbl_wiki_conf.".page_id=".$tbl_wiki.".page_id AND ".$tbl_wiki.".".$groupfilter.$condition_session.""; //add blank space after like '%" " %' to identify each word. // new version
  931. }
  932. else
  933. {
  934. //$sql="SELECT * FROM ".$tbl_wiki." s1 WHERE 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 AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word //old version TODO: Replace by the bottom line
  935. $sql="SELECT * FROM ".$tbl_wiki.", ".$tbl_wiki_conf." WHERE visibility=1 AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND ".$tbl_wiki_conf.".page_id=".$tbl_wiki.".page_id AND ".$tbl_wiki.".".$groupfilter.$condition_session.""; //add blank space after like '%" " %' to identify each word // new version
  936. }
  937. $allpages=Database::query($sql);
  938. //show table
  939. if (Database::num_rows($allpages) > 0)
  940. {
  941. $row = array ();
  942. while ($obj = Database::fetch_object($allpages))
  943. {
  944. //get author
  945. $userinfo=Database::get_user_info_from_id($obj->user_id);
  946. //get time
  947. $year = substr($obj->dtime, 0, 4);
  948. $month = substr($obj->dtime, 5, 2);
  949. $day = substr($obj->dtime, 8, 2);
  950. $hours = substr($obj->dtime, 11,2);
  951. $minutes = substr($obj->dtime, 14,2);
  952. $seconds = substr($obj->dtime, 17,2);
  953. //get type assignment icon
  954. if($obj->assignment==1)
  955. {
  956. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  957. }
  958. elseif ($obj->assignment==2)
  959. {
  960. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  961. }
  962. elseif ($obj->assignment==0)
  963. {
  964. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  965. }
  966. $row = array ();
  967. $row[] =$ShowAssignment;
  968. $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>';
  969. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  970. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  971. $rows[] = $row;
  972. }
  973. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  974. $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'])));
  975. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  976. $table->set_header(1,get_lang('Title'), true);
  977. $table->set_header(2,get_lang('Author'), true);
  978. $table->set_header(3,get_lang('Date'), true);
  979. $table->display();
  980. }
  981. }
  982. }
  983. /////////////////////// adding a new page ///////////////////////
  984. // Display the form for adding a new wiki page
  985. if ($_GET['action']=='addnew')
  986. {
  987. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  988. api_not_allowed();
  989. }
  990. echo '<div class="actions">'.get_lang('AddNew').'</div>';
  991. //first, check if page index was created. chektitle=false
  992. if (checktitle('index'))
  993. {
  994. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
  995. {
  996. Display::display_normal_message(get_lang('GoAndEditMainPage'));
  997. }
  998. else
  999. {
  1000. return Display::display_normal_message(get_lang('WikiStandBy'));
  1001. }
  1002. }
  1003. elseif (check_addnewpagelock()==0 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false))
  1004. {
  1005. Display::display_error_message(get_lang('AddPagesLocked'));
  1006. }
  1007. else
  1008. {
  1009. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0)
  1010. {
  1011. display_new_wiki_form();
  1012. }
  1013. else
  1014. {
  1015. Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers'));
  1016. }
  1017. }
  1018. }
  1019. /////////////////////// show home page ///////////////////////
  1020. if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew']))
  1021. {
  1022. display_wiki_entry($newtitle);
  1023. }
  1024. /////////////////////// show current page ///////////////////////
  1025. if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew']))
  1026. {
  1027. if($_GET['title'])
  1028. {
  1029. display_wiki_entry($newtitle);
  1030. }
  1031. else
  1032. {
  1033. Display::display_error_message(get_lang('MustSelectPage'));
  1034. }
  1035. }
  1036. /////////////////////// edit current page ///////////////////////
  1037. if ($_GET['action']=='edit')
  1038. {
  1039. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  1040. api_not_allowed();
  1041. }
  1042. $_clean['group_id']=(int)$_SESSION['_gid'];
  1043. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' ORDER BY id DESC';
  1044. $result=Database::query($sql);
  1045. $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
  1046. if ($row['content']=='' AND $row['title']=='' AND $page=='')
  1047. {
  1048. Display::display_error_message(get_lang('MustSelectPage'));
  1049. exit;
  1050. }
  1051. elseif ($row['content']=='' AND $row['title']=='' AND $page=='index')
  1052. {
  1053. //Table structure for better export to pdf
  1054. $default_table_for_content_Start='<table align="center" border="0"><tr><td align="center">';
  1055. $default_table_for_content_End='</td></tr></table>';
  1056. $content=$default_table_for_content_Start.sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)).$default_table_for_content_End;
  1057. $title=get_lang('DefaultTitle');
  1058. $page_id=0;
  1059. }
  1060. else
  1061. {
  1062. $content=$row['content'];
  1063. $title=$row['title'];
  1064. $page_id=$row['page_id'];
  1065. }
  1066. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher. And users in groups
  1067. if(($row['reflink']=='index' || $row['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && $_clean['group_id']==0))
  1068. {
  1069. Display::display_error_message(get_lang('OnlyEditPagesCourseManager'));
  1070. }
  1071. else
  1072. {
  1073. $PassEdit=false;
  1074. //check if is a wiki group
  1075. if($_clean['group_id']!=0)
  1076. {
  1077. //Only teacher, platform admin and group members can edit a wiki group
  1078. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
  1079. {
  1080. $PassEdit=true;
  1081. }
  1082. else
  1083. {
  1084. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  1085. }
  1086. }
  1087. else
  1088. {
  1089. $PassEdit=true;
  1090. }
  1091. // check if is a assignment
  1092. if(stripslashes($row['assignment'])==1)
  1093. {
  1094. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  1095. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1096. }
  1097. elseif(stripslashes($row['assignment'])==2)
  1098. {
  1099. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1100. if((api_get_user_id()==$row['user_id'])==false)
  1101. {
  1102. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1103. {
  1104. $PassEdit=true;
  1105. }
  1106. else
  1107. {
  1108. Display::display_warning_message(get_lang('LockByTeacher'));
  1109. $PassEdit=false;
  1110. }
  1111. }
  1112. else
  1113. {
  1114. $PassEdit=true;
  1115. }
  1116. }
  1117. if($PassEdit) //show editor if edit is allowed
  1118. {
  1119. if ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false))
  1120. {
  1121. Display::display_normal_message(get_lang('PageLockedExtra'));
  1122. }
  1123. else
  1124. {
  1125. //check tasks
  1126. if (!empty($row['startdate_assig']) && $row['startdate_assig']!='0000-00-00 00:00:00' && time()<strtotime($row['startdate_assig']))
  1127. {
  1128. $message=get_lang('TheTaskDoesNotBeginUntil').': '.api_convert_and_format_date($row['startdate_assig'], null, date_default_timezone_get());
  1129. Display::display_warning_message($message);
  1130. if(!api_is_allowed_to_edit(false,true))
  1131. {
  1132. exit;
  1133. }
  1134. }
  1135. //
  1136. if (!empty($row['enddate_assig']) && $row['enddate_assig']!='0000-00-00 00:00:00' && time()>strtotime($row['enddate_assig']) && $row['enddate_assig']!='0000-00-00 00:00:00' && $row['delayedsubmit']==0)
  1137. {
  1138. $message=get_lang('TheDeadlineHasBeenCompleted').': '.api_convert_and_format_date($row['enddate_assig'], null, date_default_timezone_get());
  1139. Display::display_warning_message($message);
  1140. if(!api_is_allowed_to_edit(false,true))
  1141. {
  1142. exit;
  1143. }
  1144. }
  1145. //
  1146. if(!empty($row['max_version']) && $row['version']>=$row['max_version'])
  1147. {
  1148. $message=get_lang('HasReachedMaxiNumVersions');
  1149. Display::display_warning_message($message);
  1150. if(!api_is_allowed_to_edit(false,true))
  1151. {
  1152. exit;
  1153. }
  1154. }
  1155. //
  1156. if (!empty($row['max_text']) && $row['max_text']<=word_count($row['content']))
  1157. {
  1158. $message=get_lang('HasReachedMaxNumWords');
  1159. Display::display_warning_message($message);
  1160. if(!api_is_allowed_to_edit(false,true))
  1161. {
  1162. exit;
  1163. }
  1164. }
  1165. ////
  1166. if (!empty($row['task']))
  1167. {
  1168. //previous change 0 by text
  1169. if ($row['startdate_assig']=='0000-00-00 00:00:00')
  1170. {
  1171. $message_task_startdate=get_lang('No');
  1172. }
  1173. else
  1174. {
  1175. $message_task_startdate=api_convert_and_format_date($row['startdate_assig'], null, date_default_timezone_get());
  1176. }
  1177. if ($row['enddate_assig']=='0000-00-00 00:00:00')
  1178. {
  1179. $message_task_enddate=get_lang('No');
  1180. }
  1181. else
  1182. {
  1183. $message_task_endate=api_convert_and_format_date($row['enddate_assig'], null, date_default_timezone_get());
  1184. }
  1185. if ($row['delayedsubmit']==0)
  1186. {
  1187. $message_task_delayedsubmit=get_lang('No');
  1188. }
  1189. else
  1190. {
  1191. $message_task_delayedsubmit=get_lang('Yes');
  1192. }
  1193. if ($row['max_version']==0)
  1194. {
  1195. $message_task_max_version=get_lang('No');
  1196. }
  1197. else
  1198. {
  1199. $message_task_max_version=$row['max_version'];
  1200. }
  1201. if ($row['max_text']==0)
  1202. {
  1203. $message_task_max_text=get_lang('No');
  1204. }
  1205. else
  1206. {
  1207. $message_task_max_text=$row['max_text'];
  1208. }
  1209. //comp message
  1210. $message_task='<b>'.get_lang('DescriptionOfTheTask').'</b><p>'.$row['task'].'</p><hr>';
  1211. $message_task.='<p>'.get_lang('StartDate').': '.$message_task_startdate.'</p>';
  1212. $message_task.='<p>'.get_lang('EndDate').': '.$message_task_enddate;
  1213. $message_task.=' ('.get_lang('AllowLaterSends').') '.$message_task_delayedsubmit.'</p>';
  1214. $message_task.='<p>'.get_lang('OtherSettings').': '.get_lang('NMaxVersion').': '.$message_task_max_version;
  1215. $message_task.=' '.get_lang('NMaxWords').': '.$message_task_max_text;
  1216. //display message
  1217. Display::display_normal_message($message_task,false);
  1218. }
  1219. if($row['progress']==$row['fprogress1'] && !empty($row['fprogress1']))
  1220. {
  1221. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.$row['feedback1'].'</p>';
  1222. Display::display_normal_message($feedback_message, false);
  1223. }
  1224. elseif($row['progress']==$row['fprogress2'] && !empty($row['fprogress2']))
  1225. {
  1226. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.$row['feedback2'].'</p>';
  1227. Display::display_normal_message($feedback_message, false);
  1228. }
  1229. elseif($row['progress']==$row['fprogress3'] && !empty($row['fprogress3']))
  1230. {
  1231. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.$row['feedback3'].'</p>';
  1232. Display::display_normal_message($feedback_message, false);
  1233. }
  1234. //previous checking for concurrent editions
  1235. if($row['is_editing']==0)
  1236. {
  1237. Display::display_normal_message(get_lang('WarningMaxEditingTime'));
  1238. $time_edit = date("Y-m-d H:i:s");
  1239. $sql='UPDATE '.$tbl_wiki.' SET is_editing="'.$_user['user_id'].'", time_edit="'.$time_edit.'" WHERE id="'.$row['id'].'"';
  1240. Database::query($sql);
  1241. }
  1242. elseif($row['is_editing']!=$_user['user_id'])
  1243. {
  1244. $timestamp_edit=strtotime($row['time_edit']);
  1245. $time_editing=time()-$timestamp_edit;
  1246. $max_edit_time=1200; // 20 minutes
  1247. $rest_time=$max_edit_time-$time_editing;
  1248. $userinfo=Database::get_user_info_from_id($row['is_editing']);
  1249. $is_being_edited= get_lang('ThisPageisBeginEditedBy').' <a href=../user/userInfo.php?uInfo='.$userinfo['user_id'].'>'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
  1250. Display::display_normal_message($is_being_edited, false);
  1251. exit;
  1252. }
  1253. //form
  1254. echo '<form name="form1" method="post" action="'.api_get_self().'?action=showpage&amp;title='.$page.'&group_id='.Security::remove_XSS($_GET['group_id']).'">';
  1255. echo '<div id="wikititle" >';
  1256. echo '<div style="width:70%;float:left;">'.$icon_assignment.str_repeat('&nbsp;',3).$title.'</div>';
  1257. if((api_is_allowed_to_edit(false,true) || api_is_platform_admin()) && $row['reflink']!='index')
  1258. {
  1259. echo'<a href="javascript://" onclick="advanced_parameters()" ><span id="plus_minus" style="float:right">&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>';
  1260. echo '<div id="options" style="display:none; margin: 20px;" >';
  1261. //task
  1262. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktask" onclick="if(this.checked==true){document.getElementById(\'option4\').style.display=\'block\';}else{document.getElementById(\'option4\').style.display=\'none\';}"/>&nbsp;<img src="../img/wiki/task.gif" title="'.get_lang('DefineTask').'" alt="'.get_lang('DefineTask').'"/>'.get_lang('DescriptionOfTheTask').'';
  1263. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error4" style="display:none;color:red"></span>';
  1264. echo '<div id="option4" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1265. echo '<table border="0" style="font-weight:normal">';
  1266. echo '<tr>';
  1267. echo '<td>'.get_lang('DescriptionOfTheTask').'</td>';
  1268. echo '</tr>';
  1269. echo '<tr>';
  1270. echo '<td>'.api_disp_html_area('task', stripslashes($row['task']), '', '', null, array('ToolbarSet' => 'wiki_task', 'Width' => '600', 'Height' => '200')).'</td>';
  1271. echo '</tr>';
  1272. echo '</table>';
  1273. echo '</div>';
  1274. //feedback
  1275. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkfeedback" onclick="if(this.checked==true){document.getElementById(\'option2\').style.display=\'block\';}else{document.getElementById(\'option2\').style.display=\'none\';}"/>&nbsp;'.get_lang('AddFeedback').'';
  1276. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error2" style="display:none;color:red"></span>';
  1277. echo '<div id="option2" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1278. echo '<table border="0" style="font-weight:normal" align="center">';
  1279. echo '<tr>';
  1280. echo '<td colspan="2">'.get_lang('Feedback1').'</td>';
  1281. echo '<td colspan="2">'.get_lang('Feedback2').'</td>';
  1282. echo '<td colspan="2">'.get_lang('Feedback3').'</td>';
  1283. echo '</tr>';
  1284. echo '<tr>';
  1285. echo '<td colspan="2"><textarea name="feedback1" cols="23" rows="4" >'.stripslashes($row['feedback1']).'</textarea></td>';
  1286. echo '<td colspan="2"><textarea name="feedback2" cols="23" rows="4" >'.stripslashes($row['feedback2']).'</textarea></td>';
  1287. echo '<td colspan="2"><textarea name="feedback3" cols="23" rows="4" >'.stripslashes($row['feedback3']).'</textarea></td>';
  1288. echo '</tr>';
  1289. echo '<tr>';
  1290. echo '<td>'.get_lang('FProgress').':</td>';
  1291. echo '<td><select name="fprogress1">';
  1292. echo '<option value="'.stripslashes($row['fprogress1']).'" selected>'.stripslashes($row['fprogress1']).'</option>';
  1293. echo '<option value="10">10</option>
  1294. <option value="20">20</option>
  1295. <option value="30">30</option>
  1296. <option value="40">40</option>
  1297. <option value="50">50</option>
  1298. <option value="60">60</option>
  1299. <option value="70">70</option>
  1300. <option value="80">80</option>
  1301. <option value="90">90</option>
  1302. <option value="100">100</option>
  1303. </select> %</td>';
  1304. echo '<td>'.get_lang('FProgress').':</td>';
  1305. echo '<td><select name="fprogress2">';
  1306. echo '<option value="'.stripslashes($row['fprogress2']).'" selected>'.stripslashes($row['fprogress2']).'</option>';
  1307. echo '<option value="10">10</option>
  1308. <option value="20">20</option>
  1309. <option value="30">30</option>
  1310. <option value="40">40</option>
  1311. <option value="50">50</option>
  1312. <option value="60">60</option>
  1313. <option value="70">70</option>
  1314. <option value="80">80</option>
  1315. <option value="90">90</option>
  1316. <option value="100">100</option>
  1317. </select> %</td>';
  1318. echo '<td>'.get_lang('FProgress').':</td>';
  1319. echo '<td><select name="fprogress3">';
  1320. echo '<option value="'.stripslashes($row['fprogress3']).'" selected>'.stripslashes($row['fprogress3']).'</option>';
  1321. echo '<option value="10">10</option>
  1322. <option value="20">20</option>
  1323. <option value="30">30</option>
  1324. <option value="40">40</option>
  1325. <option value="50">50</option>
  1326. <option value="60">60</option>
  1327. <option value="70">70</option>
  1328. <option value="80">80</option>
  1329. <option value="90">90</option>
  1330. <option value="100">100</option>
  1331. </select> %</td>';
  1332. echo '</tr>';
  1333. echo '</table>';
  1334. echo '</div>';
  1335. //time limit
  1336. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktimelimit" onclick="if(this.checked==true){document.getElementById(\'option1\').style.display=\'block\'; $pepe=\'a\';}else{document.getElementById(\'option1\').style.display=\'none\';}"/>&nbsp;'.get_lang('PutATimeLimit').'';
  1337. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error1" style="display:none;color:red"></span>';
  1338. echo '<div id="option1" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1339. echo '<table width="100%" border="0" style="font-weight:normal">';
  1340. echo '<tr>';
  1341. echo '<td align="right">'.get_lang("StartDate").':</td>';
  1342. echo '<td>';
  1343. if ($row['startdate_assig']=='0000-00-00 00:00:00')
  1344. {
  1345. echo draw_date_picker('startdate_assig').' <input type="checkbox" name="initstartdate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1346. }
  1347. else
  1348. {
  1349. echo draw_date_picker('startdate_assig', $row['startdate_assig']).' <input type="checkbox" name="initstartdate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1350. }
  1351. echo '</td>';
  1352. echo '</tr>';
  1353. echo '<tr>';
  1354. echo '<td align="right">'.get_lang("EndDate").':</td>';
  1355. echo '<td>';
  1356. if ($row['enddate_assig']=='0000-00-00 00:00:00')
  1357. {
  1358. echo draw_date_picker('enddate_assig').' <input type="checkbox" name="initenddate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1359. }
  1360. else
  1361. {
  1362. echo draw_date_picker('enddate_assig', $row['enddate_assig']).' <input type="checkbox" name="initenddate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1363. }
  1364. echo '</td>';
  1365. echo '</tr>';
  1366. echo '<tr>';
  1367. echo '<td align="right">'.get_lang('AllowLaterSends').':</td>';
  1368. if (stripslashes($row['delayedsubmit'])==1)
  1369. {
  1370. $check_uncheck='checked';
  1371. }
  1372. echo '<td><input type="checkbox" name="delayedsubmit" value="1" '.$check_uncheck.'></td>';
  1373. echo '</tr>';
  1374. echo'</table>';
  1375. echo '</div>';
  1376. //other limit
  1377. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkotherlimit" onclick="if(this.checked==true){document.getElementById(\'option3\').style.display=\'block\';}else{document.getElementById(\'option3\').style.display=\'none\';}"/>&nbsp;'.get_lang('OtherSettings').'';
  1378. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error3" style="display:none;color:red"></span>';
  1379. echo '<div id="option3" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1380. echo '<div style="font-weight:normal"; align="center">'.get_lang('NMaxWords').':&nbsp;<input type="text" name="max_text" size="3" value="'.stripslashes($row['max_text']).'">&nbsp;&nbsp;'.get_lang('NMaxVersion').':&nbsp;<input type="text" name="max_version" size="3" value="'.stripslashes($row['max_version']).'"></div>';
  1381. echo '</div>';
  1382. //
  1383. echo '</div>';
  1384. }
  1385. echo '</div>';
  1386. echo '<div id="wikicontent">';
  1387. echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
  1388. echo '<input type="hidden" name="reflink" value="'.$page.'">';
  1389. echo '<input type="hidden" name="title" value="'.stripslashes($title).'">';
  1390. api_disp_html_area('content', stripslashes($content), '', '', null, api_is_allowed_to_edit(null,true)
  1391. ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400')
  1392. : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student')
  1393. );
  1394. echo '<br/>';
  1395. echo '<br/>';
  1396. //if(api_is_allowed_to_edit() || api_is_platform_admin()) //off for now
  1397. //{
  1398. echo get_lang('Comments').':&nbsp;&nbsp;<input type="text" name="comment" size="40">&nbsp;&nbsp;&nbsp;';
  1399. //}
  1400. echo '<INPUT TYPE="hidden" NAME="assignment" VALUE="'.stripslashes($row['assignment']).'"/>';
  1401. echo '<INPUT TYPE="hidden" NAME="version" VALUE="'.stripslashes($row['version']).'"/>';
  1402. //hack date for edit
  1403. echo '<INPUT TYPE="hidden" NAME="startdate_assig" VALUE="'.stripslashes($row['startdate_assig']).'"/>';
  1404. echo '<INPUT TYPE="hidden" NAME="enddate_assig" VALUE="'.stripslashes($row['enddate_assig']).'"/>';
  1405. //
  1406. echo get_lang('Progress').':&nbsp;&nbsp;<select name="progress" id="progress">';
  1407. echo '<option value="'.stripslashes($row['progress']).'" selected>'.stripslashes($row['progress']).'</option>';
  1408. echo '<option value="10">10</option>
  1409. <option value="20">20</option>
  1410. <option value="30">30</option>
  1411. <option value="40">40</option>
  1412. <option value="50">50</option>
  1413. <option value="60">60</option>
  1414. <option value="70">70</option>
  1415. <option value="80">80</option>
  1416. <option value="90">90</option>
  1417. <option value="100">100</option>
  1418. </select> %';
  1419. echo '<br/><br/>';
  1420. echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post
  1421. echo '<button class="save" type="submit" name="SaveWikiChange">'.get_lang('langSave').'</button>';//for save button Don't change name (see fckeditor/editor/plugins/customizations/fckplugin_compressed.js and fckplugin.js
  1422. echo '</div>';
  1423. echo '</form>';
  1424. }
  1425. }
  1426. }
  1427. }
  1428. /////////////////////// page history ///////////////////////
  1429. if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences']))
  1430. {
  1431. if (!$_GET['title'])
  1432. {
  1433. Display::display_error_message(get_lang("MustSelectPage"));
  1434. exit;
  1435. }
  1436. echo '<div style="overflow:hidden">';
  1437. $_clean['group_id']=(int)$_SESSION['_gid'];
  1438. //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
  1439. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1440. $result=Database::query($sql);
  1441. while ($row=Database::fetch_array($result))
  1442. {
  1443. $KeyVisibility=$row['visibility'];
  1444. $KeyAssignment=$row['assignment'];
  1445. $KeyTitle=$row['title'];
  1446. $KeyUserId=$row['user_id'];
  1447. }
  1448. if($KeyAssignment==1)
  1449. {
  1450. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1451. }
  1452. elseif($KeyAssignment==2)
  1453. {
  1454. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1455. }
  1456. //Second, show
  1457. //if the page is hidden and is a job only sees its author and professor
  1458. if($KeyVisibility==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin() || ($KeyAssignment==2 && $KeyVisibility==0 && (api_get_user_id()==$KeyUserId)))
  1459. {
  1460. // We show the complete history
  1461. if (!$_POST['HistoryDifferences'] && !$_POST['HistoryDifferences2'] )
  1462. {
  1463. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1464. $result=Database::query($sql);
  1465. $title = Security::remove_XSS($_GET['title']);
  1466. $group_id = Security::remove_XSS($_GET['group_id']);
  1467. echo '<div id="wikititle">';
  1468. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.$KeyTitle;
  1469. echo '</div>';
  1470. echo '<div id="wikicontent">';
  1471. echo '<form id="differences" method="POST" action="index.php?cidReq='.$_course[id].'&action=history&title='.$title.'&group_id='.$group_id.'">';
  1472. echo '<ul style="list-style-type: none;">';
  1473. echo '<br/>';
  1474. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1475. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1476. echo '<br/><br/>';
  1477. $counter=0;
  1478. $total_versions=Database::num_rows($result);
  1479. while ($row=Database::fetch_array($result))
  1480. {
  1481. $userinfo=Database::get_user_info_from_id($row['user_id']);
  1482. echo '<li style="margin-bottom: 5px;">';
  1483. ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle='';
  1484. ($counter==0) ? $newchecked=' checked':$newchecked='';
  1485. ($counter==$total_versions-1) ? $newstyle='style="visibility: hidden;"':$newstyle='';
  1486. ($counter==1) ? $oldchecked=' checked':$oldchecked='';
  1487. echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
  1488. echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
  1489. echo '<a href="'.api_get_self().'?action=showpage&amp;title='.$page.'&amp;view='.$row['id'].'">';
  1490. echo '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&amp;title='.$page.'&amp;view='.$row['id'].'&group_id='.$group_id.'">';
  1491. echo api_convert_and_format_date($row['dtime'], null, date_default_timezone_get());
  1492. echo '</a>';
  1493. echo ' ('.get_lang('Version').' '.$row['version'].')';
  1494. echo ' '.get_lang('By').' ';
  1495. if ($row['user_id']<>0)
  1496. {
  1497. echo '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>';
  1498. }
  1499. else
  1500. {
  1501. echo get_lang('Anonymous').' ('.$row[user_ip].')';
  1502. }
  1503. echo ' ( '.get_lang('Progress').': '.$row['progress'].'%, ';
  1504. $comment=$row['comment'];
  1505. if (!empty($comment))
  1506. {
  1507. echo get_lang('Comments').': '.api_substr(api_htmlentities($row['comment'], ENT_QUOTES, $charset),0,100);
  1508. if (api_strlen($row['comment'])>100)
  1509. {
  1510. echo '... ';
  1511. }
  1512. }
  1513. else
  1514. {
  1515. echo get_lang('Comments').': ---';
  1516. }
  1517. echo ' ) </li>';
  1518. $counter++;
  1519. } //end while
  1520. echo '<br/>';
  1521. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1522. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1523. echo '</ul></form></div>';
  1524. }
  1525. // We show the differences between two versions
  1526. else
  1527. {
  1528. $sql_old="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['old'])."'";
  1529. $result_old=Database::query($sql_old);
  1530. $version_old=Database::fetch_array($result_old);
  1531. $sql_new="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['new'])."'";
  1532. $result_new=Database::query($sql_new);
  1533. $version_new=Database::fetch_array($result_new);
  1534. if(isset($_POST['HistoryDifferences']))
  1535. {
  1536. include('diff.inc.php');
  1537. //title
  1538. 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>';
  1539. }
  1540. if(isset($_POST['HistoryDifferences2']))
  1541. {
  1542. require_once 'Text/Diff.php';
  1543. require_once 'Text/Diff/Renderer/inline.php';
  1544. //title
  1545. 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>';
  1546. }
  1547. echo '<div class="diff"><br /><br />';
  1548. if(isset($_POST['HistoryDifferences']))
  1549. {
  1550. echo '<table>'.diff( stripslashes($version_old['content']), stripslashes($version_new['content']), true, 'format_table_line' ).'</table>'; // format_line mode is better for words
  1551. echo '</div>';
  1552. echo '<br />';
  1553. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1554. echo '<table><tr>';
  1555. echo '<td>';
  1556. echo '</td><td>';
  1557. echo '<span class="diffEqual" >'.get_lang('WikiDiffUnchangedLine').'</span><br />';
  1558. echo '<span class="diffAdded" >'.get_lang('WikiDiffAddedLine').'</span><br />';
  1559. echo '<span class="diffDeleted" >'.get_lang('WikiDiffDeletedLine').'</span><br />';
  1560. echo '<span class="diffMoved" >'.get_lang('WikiDiffMovedLine').'</span><br />';
  1561. echo '</td>';
  1562. echo '</tr></table>';
  1563. echo '</div>';
  1564. }
  1565. if(isset($_POST['HistoryDifferences2']))
  1566. {
  1567. $lines1 = array(strip_tags($version_old['content'])); //without <> tags
  1568. $lines2 = array(strip_tags($version_new['content'])); //without <> tags
  1569. $diff = &new Text_Diff($lines1, $lines2);
  1570. $renderer = &new Text_Diff_Renderer_inline();
  1571. echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render($diff); // Code inline
  1572. //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
  1573. echo '</div>';
  1574. echo '<br />';
  1575. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1576. echo '<table><tr>';
  1577. echo '<td>';
  1578. echo '</td><td>';
  1579. echo '<span class="diffAddedTex" >'.get_lang('WikiDiffAddedTex').'</span><br />';
  1580. echo '<span class="diffDeletedTex" >'.get_lang('WikiDiffDeletedTex').'</span><br />';
  1581. echo '</td>';
  1582. echo '</tr></table>';
  1583. echo '</div>';
  1584. }
  1585. }
  1586. }
  1587. echo '</div>';
  1588. }
  1589. /////////////////////// recent changes ///////////////////////
  1590. //
  1591. //rss feed. TODO:
  1592. //
  1593. if ($_GET['action']=='recentchanges')
  1594. {
  1595. $_clean['group_id']=(int)$_SESSION['_gid'];
  1596. if ( api_is_allowed_to_session_edit(false,true) ) {
  1597. if (check_notify_all()==1)
  1598. {
  1599. $notify_all= '<img src="../img/wiki/send_mail_checked.gif" title="'.get_lang('FullNotifyByEmail').'" alt="'.get_lang('FullNotifyByEmail').'" style="vertical-align:middle;" />'.get_lang('NotNotifyChanges');
  1600. $lock_unlock_notify_all='unlocknotifyall';
  1601. }
  1602. else
  1603. {
  1604. $notify_all= '<img src="../img/wiki/send_mail.gif" title="'.get_lang('FullCancelNotifyByEmail').'" alt="'.get_lang('FullCancelNotifyByEmail').'" style="vertical-align:middle;"/>'.get_lang('NotifyChanges');
  1605. $lock_unlock_notify_all='locknotifyall';
  1606. }
  1607. }
  1608. echo '<div class="actions"><span style="float: right;">';
  1609. echo '<a href="index.php?action=recentchanges&amp;actionpage='.$lock_unlock_notify_all.'&amp;title='.$page.'">'.$notify_all.'</a>';
  1610. echo '</span>'.get_lang('RecentChanges').'</div>';
  1611. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  1612. {
  1613. //$sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY dtime DESC'; // old version TODO: Replace by the bottom line
  1614. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' ORDER BY dtime DESC'; // new version
  1615. }
  1616. else
  1617. {
  1618. $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' AND visibility=1 ORDER BY dtime DESC'; // old version TODO: Replace by the bottom line
  1619. //$sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND visibility=1 AND '.$tbl_wiki.'.'.$groupfilter.' ORDER BY dtime DESC'; // new version
  1620. }
  1621. $allpages=Database::query($sql);
  1622. //show table
  1623. if (Database::num_rows($allpages) > 0)
  1624. {
  1625. $row = array ();
  1626. while ($obj = Database::fetch_object($allpages))
  1627. {
  1628. //get author
  1629. $userinfo=Database::get_user_info_from_id($obj->user_id);
  1630. //get type assignment icon
  1631. if($obj->assignment==1)
  1632. {
  1633. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  1634. }
  1635. elseif ($obj->assignment==2)
  1636. {
  1637. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  1638. }
  1639. elseif ($obj->assignment==0)
  1640. {
  1641. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  1642. }
  1643. //get icon task
  1644. if (!empty($obj->task))
  1645. {
  1646. $icon_task='<img src="../img/wiki/task.gif" title="'.get_lang('StandardTask').'" alt="'.get_lang('StandardTask').'" />';
  1647. }
  1648. else
  1649. {
  1650. $icon_task='<img src="../img/wiki/trans.gif" />';
  1651. }
  1652. $row = array ();
  1653. $row[] = api_convert_and_format_date($obj->dtime, null, date_default_timezone_get());
  1654. $row[] = $ShowAssignment.$icon_task;
  1655. $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>';
  1656. $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
  1657. $row[] = $obj->user_id <> 0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  1658. $rows[] = $row;
  1659. }
  1660. $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC');
  1661. $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'])));
  1662. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  1663. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1664. $table->set_header(2,get_lang('Title'), true);
  1665. $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;'));
  1666. $table->set_header(4,get_lang('Author'), true);
  1667. $table->display();
  1668. }
  1669. }
  1670. /////////////////////// all pages ///////////////////////
  1671. if ($_GET['action']=='allpages')
  1672. {
  1673. echo '<div class="actions">'.get_lang('AllPages').'</div>';
  1674. $_clean['group_id']=(int)$_SESSION['_gid'];
  1675. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //only by professors if page is hidden
  1676. {
  1677. //$sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version// old version TODO: Replace by the bottom line
  1678. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' GROUP BY '.$tbl_wiki.'.page_id'; // new version
  1679. }
  1680. else
  1681. {
  1682. //$sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version // old version TODO: Replace by the bottom line
  1683. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE visibility=1 AND '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' GROUP BY '.$tbl_wiki.'.page_id'; // new version
  1684. }
  1685. $allpages=Database::query($sql);
  1686. //show table
  1687. if (Database::num_rows($allpages) > 0)
  1688. {
  1689. $row = array ();
  1690. while ($obj = Database::fetch_object($allpages))
  1691. {
  1692. //get author
  1693. $userinfo=Database::get_user_info_from_id($obj->user_id);
  1694. //get type assignment icon
  1695. if($obj->assignment==1)
  1696. {
  1697. $ShowAssignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDesc').'" alt="'.get_lang('AssignmentDesc').'" />';
  1698. }
  1699. elseif ($obj->assignment==2)
  1700. {
  1701. $ShowAssignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWork').'" alt="'.get_lang('AssignmentWork').'" />';
  1702. }
  1703. elseif ($obj->assignment==0)
  1704. {
  1705. $ShowAssignment='<img src="../img/wiki/trans.gif" />';
  1706. }
  1707. //get icon task
  1708. if (!empty($obj->task))
  1709. {
  1710. $icon_task='<img src="../img/wiki/task.gif" title="'.get_lang('StandardTask').'" alt="'.get_lang('StandardTask').'" />';
  1711. }
  1712. else
  1713. {
  1714. $icon_task='<img src="../img/wiki/trans.gif" />';
  1715. }
  1716. $row = array ();
  1717. $row[] =$ShowAssignment.$icon_task;
  1718. $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>';
  1719. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  1720. $row[] = api_convert_and_format_date($obj->dtime, null, date_default_timezone_get());
  1721. if(api_is_allowed_to_edit(false,true)|| api_is_platform_admin())
  1722. {
  1723. $showdelete=' <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=delete&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'"><img src="../img/delete.gif" title="'.get_lang('Delete').'" alt="'.get_lang('Delete').'" />';
  1724. }
  1725. if (api_is_allowed_to_session_edit(false,true) )
  1726. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=edit&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'"><img src="../img/lp_quiz.png" title="'.get_lang('EditPage').'" alt="'.get_lang('EditPage').'" /></a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=discuss&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'"><img src="../img/comment_bubble.gif" title="'.get_lang('Discuss').'" alt="'.get_lang('Discuss').'" /></a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=history&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'"><img src="../img/history.gif" title="'.get_lang('History').'" alt="'.get_lang('History').'" /></a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=links&title='.urlencode(Security::remove_XSS($obj->reflink)).'&group_id='.Security::remove_XSS($_GET['group_id']).'"><img src="../img/lp_link.png" title="'.get_lang('LinksPages').'" alt="'.get_lang('LinksPages').'" /></a>'.$showdelete;
  1727. $rows[] = $row;
  1728. }
  1729. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  1730. $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'])));
  1731. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1732. $table->set_header(1,get_lang('Title'), true);
  1733. $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true);
  1734. $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
  1735. if (api_is_allowed_to_session_edit(false,true) )
  1736. $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:100px;'));
  1737. $table->display();
  1738. }
  1739. }
  1740. /////////////////////// discuss pages ///////////////////////
  1741. if ($_GET['action']=='discuss')
  1742. {
  1743. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  1744. api_not_allowed();
  1745. }
  1746. if (!$_GET['title'])
  1747. {
  1748. Display::display_error_message(get_lang("MustSelectPage"));
  1749. exit;
  1750. }
  1751. //first extract the date of last version
  1752. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1753. $result=Database::query($sql);
  1754. $row=Database::fetch_array($result);
  1755. $lastversiondate=api_convert_and_format_date($row['dtime'], null, date_default_timezone_get());
  1756. $lastuserinfo=Database::get_user_info_from_id($row['user_id']);
  1757. //select page to discuss
  1758. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1759. $result=Database::query($sql);
  1760. $row=Database::fetch_array($result);
  1761. $id=$row['id'];
  1762. $firstuserid=$row['user_id'];
  1763. //mode assignment: previous to show page type
  1764. if(stripslashes($row['assignment'])==1)
  1765. {
  1766. $icon_assignment='<img src="../img/wiki/assignment.gif" title="'.get_lang('AssignmentDescExtra').'" alt="'.get_lang('AssignmentDescExtra').'" />';
  1767. }
  1768. elseif(stripslashes($row['assignment'])==2)
  1769. {
  1770. $icon_assignment='<img src="../img/wiki/works.gif" title="'.get_lang('AssignmentWorkExtra').'" alt="'.get_lang('AssignmentWorkExtra').'" />';
  1771. }
  1772. //Show title and form to discuss if page exist
  1773. if ($id!='')
  1774. {
  1775. //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
  1776. if($row['visibility_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id'])))
  1777. {
  1778. echo '<div id="wikititle">';
  1779. // discussion action: protecting (locking) the discussion
  1780. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1781. {
  1782. if (check_addlock_discuss()==1)
  1783. {
  1784. $addlock_disc= '<img src="../img/wiki/unlock.gif" title="'.get_lang('UnlockDiscussExtra').'" alt="'.get_lang('UnlockDiscussExtra').'" />';
  1785. $lock_unlock_disc='unlockdisc';
  1786. }
  1787. else
  1788. {
  1789. $addlock_disc= '<img src="../img/wiki/lock.gif" title="'.get_lang('LockDiscussExtra').'" alt="'.get_lang('LockDiscussExtra').'" />';
  1790. $lock_unlock_disc='lockdisc';
  1791. }
  1792. }
  1793. echo '<span style="float:right">';
  1794. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_disc.'&amp;title='.$page.'">'.$addlock_disc.'</a>';
  1795. echo '</span>';
  1796. // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
  1797. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1798. {
  1799. if (check_visibility_discuss()==1)
  1800. {
  1801. /// TODO: Fix Mode assignments: If is hidden, show discussion to student only if student is the author
  1802. //if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
  1803. //{
  1804. //$visibility_disc= '<img src="../img/wiki/invisible.gif" title="'.get_lang('HideDiscussExtra').'" alt="'.get_lang('HideDiscussExtra').'" />';
  1805. //}
  1806. $visibility_disc= '<img src="../img/wiki/visible.gif" title="'.get_lang('ShowDiscussExtra').'" alt="'.get_lang('ShowDiscussExtra').'" />';
  1807. $hide_show_disc='hidedisc';
  1808. }
  1809. else
  1810. {
  1811. $visibility_disc= '<img src="../img/wiki/invisible.gif" title="'.get_lang('HideDiscussExtra').'" alt="'.get_lang('HideDiscussExtra').'" />';
  1812. $hide_show_disc='showdisc';
  1813. }
  1814. }
  1815. echo '<span style="float:right">';
  1816. echo '<a href="index.php?action=discuss&amp;actionpage='.$hide_show_disc.'&amp;title='.$page.'">'.$visibility_disc.'</a>';
  1817. echo '</span>';
  1818. //discussion action: check add rating lock. Show/Hide list to rating for all student
  1819. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1820. {
  1821. if (check_ratinglock_discuss()==1)
  1822. {
  1823. $ratinglock_disc= '<img src="../img/wiki/rating.gif" title="'.get_lang('UnlockRatingDiscussExtra').'" alt="'.get_lang('UnlockRatingDiscussExtra').'" />';
  1824. $lock_unlock_rating_disc='unlockrating';
  1825. }
  1826. else
  1827. {
  1828. $ratinglock_disc= '<img src="../img/wiki/rating_na.gif" title="'.get_lang('LockRatingDiscussExtra').'" alt="'.get_lang('LockRatingDiscussExtra').'" />';
  1829. $lock_unlock_rating_disc='lockrating';
  1830. }
  1831. }
  1832. echo '<span style="float:right">';
  1833. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_rating_disc.'&amp;title='.$page.'">'.$ratinglock_disc.'</a>';
  1834. echo '</span>';
  1835. //discussion action: email notification
  1836. if (check_notify_discuss($page)==1)
  1837. {
  1838. $notify_disc= '<img src="../img/wiki/send_mail_checked.gif" title="'.get_lang('NotifyDiscussByEmail').'" alt="'.get_lang('NotifyDiscussByEmail').'" />';
  1839. $lock_unlock_notify_disc='unlocknotifydisc';
  1840. }
  1841. else
  1842. {
  1843. $notify_disc= '<img src="../img/wiki/send_mail.gif" title="'.get_lang('CancelNotifyDiscussByEmail').'" alt="'.get_lang('CancelNotifyDiscussByEmail').'" />';
  1844. $lock_unlock_notify_disc='locknotifydisc';
  1845. }
  1846. echo '<span style="float:right">';
  1847. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_notify_disc.'&amp;title='.$page.'">'.$notify_disc.'</a>';
  1848. echo '</span>';
  1849. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.$row['title'];
  1850. echo ' ('.get_lang('MostRecentVersionBy').' <a href="../user/userInfo.php?uInfo='.$lastuserinfo['user_id'].'">'.api_get_person_name($lastuserinfo['firstname'], $lastuserinfo['lastname']).'</a> '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read avg score
  1851. echo '</div>';
  1852. if($row['addlock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) //show comments but students can't add theirs
  1853. {
  1854. ?>
  1855. <form name="form1" method="post" action="">
  1856. <table>
  1857. <tr>
  1858. <td valign="top" ><?php echo get_lang('Comments');?>:</td>
  1859. <?php echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post ?>
  1860. <td><textarea name="comment" cols="80" rows="5" id="comment"></textarea></td>
  1861. </tr>
  1862. <tr>
  1863. <?php
  1864. //check if rating is allowed
  1865. if($row['ratinglock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1866. {
  1867. ?>
  1868. <td><?php echo get_lang('Rating');?>: </td>
  1869. <td valign="top"><select name="rating" id="rating">
  1870. <option value="-" selected>-</option>
  1871. <option value="0">0</option>
  1872. <option value="1">1</option>
  1873. <option value="2">2</option>
  1874. <option value="3">3</option>
  1875. <option value="4">4</option>
  1876. <option value="5">5</option>
  1877. <option value="6">6</option>
  1878. <option value="7">7</option>
  1879. <option value="8">8</option>
  1880. <option value="9">9</option>
  1881. <option value="10">10</option>
  1882. </select></td>
  1883. <?php
  1884. }
  1885. else
  1886. {
  1887. echo '<input type=hidden name="rating" value="-">';// must pass a default value to avoid rate automatically
  1888. }
  1889. ?>
  1890. </tr>
  1891. <tr>
  1892. <td>&nbsp;</td>
  1893. <td> <?php echo '<button class="save" type="submit" name="Submit"> '.get_lang('Send').'</button>'; ?></td>
  1894. </tr>
  1895. </table>
  1896. </form>
  1897. <?php
  1898. if (isset($_POST['Submit']) && double_post($_POST['wpost_id']))
  1899. {
  1900. $dtime = date( "Y-m-d H:i:s" );
  1901. $message_author=api_get_user_id();
  1902. $sql="INSERT INTO $tbl_wiki_discuss (publication_id, userc_id, comment, p_score, dtime) VALUES ('".$id."','".$message_author."','".$_POST['comment']."','".$_POST['rating']."','".$dtime."')";
  1903. $result=Database::query($sql) or die(Database::error());
  1904. check_emailcue($id, 'D', $dtime, $message_author);
  1905. }
  1906. }//end discuss lock
  1907. echo '<hr noshade size="1">';
  1908. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  1909. $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' ORDER BY id DESC";
  1910. $result=Database::query($sql) or die(Database::error());
  1911. $countWPost = Database::num_rows($result);
  1912. echo get_lang('NumComments').": ".$countWPost; //comment's numbers
  1913. $sql="SELECT SUM(p_score) as sumWPost FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-' ORDER BY id DESC";
  1914. $result2=Database::query($sql) or die(Database::error());
  1915. $row2=Database::fetch_array($result2);
  1916. $sql="SELECT * FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-'";
  1917. $result3=Database::query($sql) or die(Database::error());
  1918. $countWPost_score= Database::num_rows($result3);
  1919. echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;//
  1920. if ($countWPost_score!=0)
  1921. {
  1922. $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10';
  1923. }
  1924. else
  1925. {
  1926. $avg_WPost_score = $countWPost_score;
  1927. }
  1928. echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
  1929. $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.$condition_session; // check if work ok. TODO:
  1930. Database::query($sql);
  1931. echo '<hr noshade size="1">';
  1932. //echo '<div style="overflow:auto; height:170px;">';
  1933. while ($row=Database::fetch_array($result))
  1934. {
  1935. $userinfo=Database::get_user_info_from_id($row['userc_id']);
  1936. if (($userinfo['status'])=="5")
  1937. {
  1938. $author_status=get_lang('Student');
  1939. }
  1940. else
  1941. {
  1942. $author_status=get_lang('Teacher');
  1943. }
  1944. require_once api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php';
  1945. $user_id=$row['userc_id'];
  1946. $name = api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1947. $attrb=array();
  1948. if ($user_id<>0)
  1949. {
  1950. $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
  1951. $image_repository = $image_path['dir'];
  1952. $existing_image = $image_path['file'];
  1953. $author_photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1954. }
  1955. else
  1956. {
  1957. $author_photo= '<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1958. }
  1959. //stars
  1960. $p_score=$row['p_score'];
  1961. switch($p_score){
  1962. case 0:
  1963. $imagerating='<img src="../img/wiki/rating/stars_0.gif"/>';
  1964. break;
  1965. case 1:
  1966. $imagerating='<img src="../img/wiki/rating/stars_5.gif"/>';
  1967. break;
  1968. case 2:
  1969. $imagerating='<img src="../img/wiki/rating/stars_10.gif"/>';
  1970. break;
  1971. case 3:
  1972. $imagerating='<img src="../img/wiki/rating/stars_15.gif"/>';
  1973. break;
  1974. case 4:
  1975. $imagerating='<img src="../img/wiki/rating/stars_20.gif"/>';
  1976. break;
  1977. case 5:
  1978. $imagerating='<img src="../img/wiki/rating/stars_25.gif"/>';
  1979. break;
  1980. case 6:
  1981. $imagerating='<img src="../img/wiki/rating/stars_30.gif"/>';
  1982. break;
  1983. case 7:
  1984. $imagerating='<img src="../img/wiki/rating/stars_35.gif"/>';
  1985. break;
  1986. case 8:
  1987. $imagerating='<img src="../img/wiki/rating/stars_40.gif"/>';
  1988. break;
  1989. case 9:
  1990. $imagerating='<img src="../img/wiki/rating/stars_45.gif"/>';
  1991. break;
  1992. case 10:
  1993. $imagerating='<img src="../img/wiki/rating/stars_50.gif"/>';
  1994. break;
  1995. }
  1996. echo '<p><table>';
  1997. echo '<tr>';
  1998. echo '<td rowspan="2">'.$author_photo.'</td>';
  1999. echo '<td style=" color:#999999"><a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</a> ('.$author_status.') '.api_convert_and_format_date($row['dtime'], null, date_default_timezone_get()).' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' </td>';
  2000. echo '</tr>';
  2001. echo '<tr>';
  2002. echo '<td>'.$row['comment'].'</td>';
  2003. echo '</tr>';
  2004. echo "</table>";
  2005. echo '<hr noshade size="1">';
  2006. }
  2007. // echo"</div>";
  2008. }
  2009. else
  2010. {
  2011. Display::display_warning_message(get_lang('LockByTeacher'),false);
  2012. }
  2013. }
  2014. else
  2015. {
  2016. Display::display_normal_message(get_lang('DiscussNotAvailable'));
  2017. }
  2018. }
  2019. ///in new pages go to new page
  2020. if ($_POST['SaveWikiNew'])
  2021. {
  2022. display_wiki_entry(Security::remove_XSS($_POST['reflink']));
  2023. }
  2024. echo "</div>"; // echo "<div id='mainwiki'>";
  2025. echo "</div>"; // echo "<div id='wikiwrapper'>";
  2026. /*
  2027. ==============================================================================
  2028. FOOTER
  2029. ==============================================================================
  2030. */
  2031. //$_SESSION['_gid'];
  2032. Display::display_footer();
  2033. ?>