index.php 95 KB

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