index.php 127 KB

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