index.php 131 KB

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