index.php 132 KB

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