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