index.php 82 KB

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