index.php 95 KB

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